34if (!defined(
'NOREQUIREMENU')) {
35 define(
'NOREQUIREMENU',
'1');
37if (!defined(
'NOBROWSERNOTIF')) {
38 define(
'NOBROWSERNOTIF',
'1');
42require
'../../main.inc.php';
51require_once DOL_DOCUMENT_ROOT.
'/compta/cashcontrol/class/cashcontrol.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/compta/cashcontrol/class/cashcontrol.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
56require_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/blockedlog.lib.php';
58$langs->loadLangs(array(
"bills",
"banks",
"cashdesk",
"blockedlog"));
68$sortfields = array(
'f.ref',
'p.datep',
'ba.ref',
'cp.code',
'amount');
69$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
70$sortorder = (strtolower(
GETPOST(
'sortorder',
'aZ09comma')) ==
'desc' ?
'DESC' :
'ASC');
71if (!in_array($sortfield, $sortfields)) {
72 $sortfield =
'p.datep';
76 'b.rowid' => array(
'label' => $langs->trans(
"Ref"),
'checked' => 1),
77 'b.dateo' => array(
'label' => $langs->trans(
"DateOperationShort"),
'checked' => 1),
78 'b.num_chq' => array(
'label' => $langs->trans(
"Number"),
'checked' => 1),
79 'ba.ref' => array(
'label' => $langs->trans(
"BankAccount"),
'checked' => 1),
80 'cp.code' => array(
'label' => $langs->trans(
"PaymentMode"),
'checked' => 1),
81 'b.debit' => array(
'label' => $langs->trans(
"Debit"),
'checked' => 1,
'position' => 600),
82 'b.credit' => array(
'label' => $langs->trans(
"Credit"),
'checked' => 1,
'position' => 605),
90$terminalid =
$object->posnumber;
93if ($user->socid > 0) {
97if (!$user->hasRight(
'cashdesk',
'run') && !$user->hasRight(
'takepos',
'run')) {
106$title = $langs->trans(
"CashControl");
109$conf->dol_hide_topmenu = 1;
110$conf->dol_hide_leftmenu = 1;
112llxHeader(
'', $title,
'',
'', 0, 0, array(), array(), $param);
114print
'<!-- Begin div id-container --><div id="id-container" class="id-container center">';
118if ($syear && !$smonth) {
120} elseif ($syear && $smonth && !$sday) {
122} elseif ($syear && $smonth && $sday) {
123 $dates =
dol_mktime(0, 0, 0, $smonth, $sday, $syear); $datee =
dol_mktime(23, 59, 59, $smonth, $sday, $syear);
127$datefilter =
'p.datep';
128$modulesourcefilter =
'f.module_source';
129$amountfield =
'pf.amount';
132 $datefilter =
'bl.date_creation';
133 $modulesourcefilter =
'bl.module_source';
134 $amountfield =
'bl.amounts';
139$sql =
"SELECT p.rowid, p.datep as datep, cp.code,";
140$sql .=
" f.rowid as facid, f.ref, f.datef as datef, ".$db->sanitize($amountfield).
" as amount,";
141$sql .=
" b.fk_account as bankid,";
142$sql .=
" bl.signature";
143$sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"facture as f,";
144$sql .=
" ".MAIN_DB_PREFIX.
"paiement as p";
146$sql .=
" ".$db->sanitize($joinleft).
" JOIN ".MAIN_DB_PREFIX.
"blockedlog as bl ON bl.action = 'PAYMENT_CUSTOMER_CREATE'";
147$sql .=
" AND bl.element = 'payment' AND bl.fk_object = p.rowid AND bl.entity = ".((int) $conf->entity);
148$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON p.fk_bank = b.rowid,";
149$sql .=
" ".MAIN_DB_PREFIX.
"c_paiement as cp";
150$sql .=
" WHERE pf.fk_facture = f.rowid AND p.rowid = pf.fk_paiement AND cp.id = p.fk_paiement";
151$sql .=
" AND ".$db->sanitize($modulesourcefilter).
" = '".$db->escape($posmodule).
"'";
152$sql .=
" AND f.pos_source = '".$db->escape($terminalid).
"'";
153$sql .=
" AND p.entity = ".((int) $conf->entity);
154$sql .=
" AND ".$db->sanitize($datefilter).
" BETWEEN '".$db->idate($dates).
"' AND '".$db->idate($datee).
"'";
155$sql .=
" ORDER BY ".$db->sanitize($datefilter).
" ASC, rowid ASC";
157$resql = $db->query($sql);
159 $num = $db->num_rows($resql);
162 print
"<!-- title of cash control -->\n";
163 print
'<!-- We will use this request to find payments: '.dolPrintHTML($sql).
' -->';
168 print $langs->trans(
"CashControl").
" #".
$object->id.(($nameterminal !=
"TAKEPOS_TERMINAL_NAME_".$object->posnumber) ?
'<br>'.$nameterminal :
'');
169 if (
$object->status == $object::STATUS_DRAFT) {
170 print
'<br><span class="opacitymedium small">('.$langs->trans(
"Draft").
" - ".$langs->trans(
"TheoricalView").
")</span>";
174 print
'<br>'.$langs->trans(
"DateCreationShort").
": ".
dol_print_date(
$object->date_creation,
'dayhour');
175 $userauthor =
$object->fk_user_valid;
176 if (empty($userauthor)) {
177 $userauthor =
$object->fk_user_creat;
180 $uservalid =
new User($db);
181 if ($userauthor > 0) {
182 $uservalid->fetch($userauthor);
183 print
'<br>'.$langs->trans(
"Author").
': '.$uservalid->getFullName($langs);
185 print
'<br>'.$langs->trans(
"Period").
': '.
$object->year_close.($object->month_close ?
'-'.sprintf(
"%02d",
$object->month_close) :
'').(
$object->day_close ?
'-'.sprintf(
"%02d",
$object->day_close) :
'');
188 $invoicetmp =
new Facture($db);
191 print
"<div style='text-align: right'><h2>";
192 print $langs->trans(
"InitialBankBalance").
' - '.$langs->trans(
"Cash").
' : <div class="inline-block amount width100">'.
price(
$object->opening).
'</div>';
198 $param =
'&id='.((int) $id);
199 if (
GETPOST(
'contextpage',
'aZ09')) {
200 $param .=
'&contextpage='.urlencode(
GETPOST(
'contextpage',
'aZ09'));
204 print
'<div class="div-table-responsive">';
205 print
'<table class="tagtable liste">'.
"\n";
208 print
'<tr class="liste_titre">';
209 print_liste_field_titre($arrayfields[
'b.rowid'][
'label'], $_SERVER[
'PHP_SELF'],
'f.ref',
'', $param,
'', $sortfield, $sortorder);
210 print_liste_field_titre($arrayfields[
'b.dateo'][
'label'], $_SERVER[
'PHP_SELF'],
'p.datep',
'', $param,
'"', $sortfield, $sortorder,
'center ');
211 print_liste_field_titre($arrayfields[
'ba.ref'][
'label'], $_SERVER[
'PHP_SELF'],
'ba.ref',
'', $param,
'', $sortfield, $sortorder,
'');
212 print_liste_field_titre($arrayfields[
'cp.code'][
'label'], $_SERVER[
'PHP_SELF'],
'cp.code',
'', $param,
'', $sortfield, $sortorder,
'right ');
213 print_liste_field_titre($arrayfields[
'b.debit'][
'label'], $_SERVER[
'PHP_SELF'],
'amount',
'', $param,
'', $sortfield, $sortorder,
'right ');
214 print_liste_field_titre($arrayfields[
'b.credit'][
'label'], $_SERVER[
'PHP_SELF'],
'amount',
'', $param,
'', $sortfield, $sortorder,
'right ');
219 $cash = $bank = $cheque = $other = 0;
223 $totalvatperrate = array();
224 $totalhtperrate = array();
227 $cachebankaccount = array();
228 $cacheinvoiceid = array();
229 $transactionspertype = array();
230 $amountpertype = array();
232 $totalarray = array(
'nbfield' => 0,
'pos' => array(),
'val' => array(
'totaldebfield' => 0,
'totalcredfield' => 0));
233 $rowstoprint = array();
235 $objp = $db->fetch_object($resql);
238 if (empty($cachebankaccount[$objp->bankid])) {
239 $bankaccounttmp =
new Account($db);
240 $bankaccounttmp->fetch($objp->bankid);
241 $cachebankaccount[$objp->bankid] = $bankaccounttmp;
242 $bankaccount = $bankaccounttmp;
244 $bankaccount = $cachebankaccount[$objp->bankid];
247 $invoicetmp->fetch($objp->facid);
249 if (empty($cacheinvoiceid[$objp->facid])) {
250 $cacheinvoiceid[$objp->facid] = $objp->facid;
251 foreach ($invoicetmp->lines as $line) {
252 $totalqty += $line->qty;
253 $totalvat += $line->total_tva;
255 if (empty($totalvatperrate[$line->tva_tx])) {
256 $totalvatperrate[$line->tva_tx] = 0;
257 $totalhtperrate[$line->tva_tx] = 0;
259 $totalvatperrate[$line->tva_tx] += $line->total_tva;
260 $totalhtperrate[$line->tva_tx] += $line->total_ht;
262 $totallocaltax1 += $line->total_localtax1;
263 $totallocaltax2 += $line->total_localtax2;
267 if (
$object->posmodule ==
"takepos") {
268 $var1 =
'CASHDESK_ID_BANKACCOUNT_CASH'.$object->posnumber;
270 $var1 =
'CASHDESK_ID_BANKACCOUNT_CASH';
273 if ($objp->code ==
'CHQ') {
274 $cheque += $objp->amount;
275 if (empty($transactionspertype[$objp->code])) {
276 $transactionspertype[$objp->code] = 0;
278 $transactionspertype[$objp->code] += 1;
279 } elseif ($objp->code ==
'CB') {
280 $bank += $objp->amount;
281 if (empty($transactionspertype[$objp->code])) {
282 $transactionspertype[$objp->code] = 0;
284 $transactionspertype[$objp->code] += 1;
287 $cash += $objp->amount;
290 if (empty($transactionspertype[
'CASH'])) {
291 $transactionspertype[
'CASH'] = 0;
293 $transactionspertype[
'CASH'] += 1;
295 $other += $objp->amount;
296 if (empty($transactionspertype[
'OTHER'])) {
297 $transactionspertype[
'OTHER'] = 0;
299 $transactionspertype[
'OTHER'] += 1;
303 if (empty($amountpertype[$objp->code])) {
304 $amountpertype[$objp->code] = 0;
307 if ($objp->amount < 0) {
308 $amountpertype[$objp->code] += $objp->amount;
310 if ($objp->amount > 0) {
311 $amountpertype[$objp->code] -= $objp->amount;
316 print
'<tr class="oddeven">';
319 print
'<td class="nowrap left smallheight">';
320 print $invoicetmp->getNomUrl(1);
321 print
'<br><span class="small opacitymedium" title="'.$langs->trans(
"FingerprintInBlockedLog").
': '.$objp->signature.
'">'.
dol_trunc($objp->signature, 16).
'</span>';
328 print
'<td class="nowrap center">';
329 print
'<span id="dateoperation_'.$objp->facid.
'">'.
dol_print_date($db->jdate($objp->datep),
"day").
"</span>";
336 print
'<td class="nowrap left">';
337 print $bankaccount->getNomUrl(1);
344 print
'<td class="right">';
352 print
'<td class="right">';
353 if ($objp->amount < 0) {
354 print
'<span class="amount">'.price($objp->amount * -1).
'</span>';
355 $totalarray[
'val'][
'totaldebfield'] += $objp->amount;
366 print
'<td class="right">';
367 if ($objp->amount > 0) {
368 print
'<span class="amount">'.price($objp->amount).
'</span>';
369 $totalarray[
'val'][
'totalcredfield'] += $objp->amount;
380 $rowstoprint[] = array(
'html' => ob_get_clean(),
'pos' => $i,
'f.ref' => (
string) $invoicetmp->ref,
'p.datep' => (
int) $db->jdate($objp->datep),
381 'ba.ref' => (
string) $bankaccount->ref,
'cp.code' => (
string) $objp->code,
'amount' => (
float) $objp->amount);
398 function (array $a, array $b) use ($sortfield, $sortorder): int {
399 $cmp = is_string($a[$sortfield]) ? strnatcasecmp($a[$sortfield], $b[$sortfield]) : ($a[$sortfield] <=> $b[$sortfield]);
400 if ($sortorder ==
'DESC') {
403 return $cmp ? $cmp : ($a[
'pos'] <=> $b[
'pos']);
406 foreach ($rowstoprint as $rowtoprint) {
407 print $rowtoprint[
'html'];
411 include DOL_DOCUMENT_ROOT.
'/core/tpl/list_print_total.tpl.php';
420 print
'<div style="text-align: right">';
423 print $langs->trans(
"Cash").(!empty($transactionspertype[
'CASH']) ?
' ('.$transactionspertype[
'CASH'].
' '.$langs->trans(
"Articles").
')' :
'').
' : ';
427 print
'<div class="inline-block amount width100 marginrightonly">'.($cash >= 0 ?
'+' :
'').
price($cash).
'</div>';
428 print
'<div class="inline-block amount width100">'.price($newcash).
'</div>';
430 print
'<div class="inline-block amount width100"></div>';
431 print
'<div class="inline-block amount width100">'.price($cash).
'</div>';
434 print
' <div class="inline-block amountremaintopay fontsizeunset small"><> '.$langs->trans(
"Declared").
': '.
price(
$object->cash_declared).
'</div>';
439 print $langs->trans(
"PaymentTypeCHQ").(!empty($transactionspertype[
'CHQ']) ?
' ('.$transactionspertype[
'CHQ'].
' '.$langs->trans(
"Articles").
')' :
'').
' : ';
440 print
'<div class="inline-block amount width100"></div>';
441 print
'<div class="inline-block amount width100">'.price($cheque).
'</div>';
443 print
' <div class="inline-block amountremaintopay fontsizeunset small"><> '.$langs->trans(
"Declared").
' : '.
price(
$object->cheque_declared).
'</div>';
448 print $langs->trans(
"PaymentTypeCB").(!empty($transactionspertype[
'CB']) ?
' ('.$transactionspertype[
'CB'].
' '.$langs->trans(
"Articles").
')' :
'').
' : ';
449 print
'<div class="inline-block amount width100"></div>';
450 print
'<div class="inline-block amount width100">'.price($bank).
'</div>';
452 print
' <div class="inline-block amountremaintopay fontsizeunset small"><> '.$langs->trans(
"Declared").
': '.
price(
$object->card_declared).
'</div>';
458 print
''.$langs->trans(
"Other").(!empty($transactionspertype[
'OTHER']) ?
' ('.$transactionspertype[
'OTHER'].
' '.$langs->trans(
"Articles").
')' :
'').
' : ';
459 print
'<div class="inline-block amount width100"></div>';
460 print
'<div class="inline-block amount width100">'.price($other).
"</div>";
466 print $langs->trans(
"Total").
' ('.$totalqty.
' '.$langs->trans(
"Articles").
') : <div class="inline-block amount width100"></div><div class="inline-block amount width100">'.
price((
float) $cash + (
float) $cheque + (
float) $bank + (
float) $other).
'</div>';
468 print
'<br>'.$langs->trans(
"TotalVAT").
' : <div class="inline-block amount width100"></div><div class="inline-block amount width100">'.
price($totalvat).
'</div>';
470 if (
$mysoc->useLocalTax(1)) {
471 print
'<br>'.$langs->trans(
"TotalLT1").
' : <div class="inline-block amount width100"></div><div class="inline-block amount width100">'.
price($totallocaltax1).
'</div>';
473 if (
$mysoc->useLocalTax(1)) {
474 print
'<br>'.$langs->trans(
"TotalLT2").
' : <div class="inline-block amount width100"></div><div class="inline-block amount width100">'.
price($totallocaltax2).
'</div>';
477 if (!empty($totalvatperrate) && is_array($totalvatperrate)) {
478 print
'<br><br><div class="small inline-block width100">'.$langs->trans(
"TotalHT").
'</div><div class="small inline-block width100">'.$langs->trans(
"TotalVAT").
'</div>';
479 if (
getDolGlobalInt(
'TAKEPOS_CASHCONTROL_REPORT_SHOW_TOTAL_INCLUDING_TAXES_COLUMN', 0) != 0) {
480 print
'<div class="small inline-block width100">'.$langs->trans(
"TotalTTC").
'</div>';
482 foreach ($totalvatperrate as $keyrate => $valuerate) {
483 print
'<br><div class="small">'.$langs->trans(
"VATRate").
' '.
vatrate($keyrate,
true).
' : <div class="inline-block amount width100">'.
price($totalhtperrate[$keyrate] ?? 0).
'</div><div class="inline-block amount width100">'.
price($valuerate).
'</div>';
484 if (
getDolGlobalInt(
'TAKEPOS_CASHCONTROL_REPORT_SHOW_TOTAL_INCLUDING_TAXES_COLUMN', 0) != 0) {
485 print
'<div class="inline-block amount width100">'.price(($totalhtperrate[$keyrate] ?? 0) + $valuerate).
'</div>';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
isALNERunningVersion($blockedlogtestalreadydone=0)
Return if the application is executed with the LNE requirements on.
Class to manage bank accounts.
Class to manage cash fence.
Class to manage invoices.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.