dolibarr 20.0.0
report.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
5 * Copyright (C) 2012 Vinícius Nogueira <viniciusvgn@gmail.com>
6 * Copyright (C) 2014 Florian Henry <florian.henry@open-cooncept.pro>
7 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
8 * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
10 * Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
11 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33if (!defined('NOREQUIREMENU')) {
34 define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
35}
36if (!defined('NOBROWSERNOTIF')) {
37 define('NOBROWSERNOTIF', '1'); // Disable browser notification
38}
39
40$optioncss = "print";
41
42// Load Dolibarr environment
43require '../../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
45require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
46require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
47require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
49
50
51$langs->loadLangs(array("bills", "banks"));
52
53$id = GETPOSTINT('id');
54$summaryonly = GETPOSTINT('summaryonly'); // May be used for ticket Z
55
56$object = new CashControl($db);
57$object->fetch($id);
58
59//$limit = GETPOST('limit')?GETPOST('limit', 'int'):$conf->liste_limit;
60$sortorder = 'ASC';
61$sortfield = 'b.datev,b.dateo,b.rowid';
62
63$arrayfields = array(
64 'b.rowid' => array('label' => $langs->trans("Ref"), 'checked' => 1),
65 'b.dateo' => array('label' => $langs->trans("DateOperationShort"), 'checked' => 1),
66 'b.num_chq' => array('label' => $langs->trans("Number"), 'checked' => 1),
67 'ba.ref' => array('label' => $langs->trans("BankAccount"), 'checked' => 1),
68 'cp.code' => array('label' => $langs->trans("PaymentMode"), 'checked' => 1),
69 'b.debit' => array('label' => $langs->trans("Debit"), 'checked' => 1, 'position' => 600),
70 'b.credit' => array('label' => $langs->trans("Credit"), 'checked' => 1, 'position' => 605),
71);
72
73$syear = $object->year_close;
74$smonth = $object->month_close;
75$sday = $object->day_close;
76
77$posmodule = $object->posmodule;
78$terminalid = $object->posnumber;
79
80// Security check
81if ($user->socid > 0) { // Protection if external user
82 //$socid = $user->socid;
84}
85if (!$user->hasRight('cashdesk', 'run') && !$user->hasRight('takepos', 'run')) {
87}
88
89
90/*
91 * View
92 */
93
94$title = $langs->trans("CashControl");
95$param = '';
96
97$conf->dol_hide_topmenu = 1;
98$conf->dol_hide_leftmenu = 1;
99
100llxHeader('', $title, '', '', 0, 0, array(), array(), $param);
101
102print '<!-- Begin div id-container --><div id="id-container" class="id-container center">';
103
104/*$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,";
105$sql.= " b.fk_account, b.fk_type,";
106$sql.= " ba.rowid as bankid, ba.ref as bankref,";
107$sql.= " bu.url_id,";
108$sql.= " f.module_source, f.ref as ref";
109$sql.= " FROM ";
110//if ($bid) $sql.= MAIN_DB_PREFIX."bank_class as l,";
111$sql.= " ".MAIN_DB_PREFIX."bank_account as ba,";
112$sql.= " ".MAIN_DB_PREFIX."bank as b";
113$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND type = 'payment'";
114$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON bu.url_id = f.rowid";
115$sql.= " WHERE b.fk_account = ba.rowid";
116// Define filter on invoice
117$sql.= " AND f.module_source = '".$db->escape($object->posmodule)."'";
118$sql.= " AND f.pos_source = '".$db->escape($object->posnumber)."'";
119$sql.= " AND f.entity IN (".getEntity('facture').")";
120// Define filter on data
121if ($syear && ! $smonth) $sql.= " AND dateo BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
122elseif ($syear && $smonth && ! $sday) $sql.= " AND dateo BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
123elseif ($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))."'";
124else dol_print_error(null, 'Year not defined');
125// Define filter on bank account
126$sql.=" AND (b.fk_account = ".((int) $conf->global->CASHDESK_ID_BANKACCOUNT_CASH);
127$sql.=" OR b.fk_account = ".((int) $conf->global->CASHDESK_ID_BANKACCOUNT_CB);
128$sql.=" OR b.fk_account = ".((int) $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE);
129$sql.=")";
130*/
131$sql = "SELECT f.rowid as facid, f.ref, f.datef as do, pf.amount as amount, b.fk_account as bankid, cp.code";
132$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";
133$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";
134$sql .= " AND f.module_source = '".$db->escape($posmodule)."'";
135$sql .= " AND f.pos_source = '".$db->escape($terminalid)."'";
136$sql .= " AND f.paye = 1";
137$sql .= " AND p.entity = ".$conf->entity; // Never share entities for features related to accountancy
138/*if ($key == 'cash') $sql.=" AND cp.code = 'LIQ'";
139elseif ($key == 'cheque') $sql.=" AND cp.code = 'CHQ'";
140elseif ($key == 'card') $sql.=" AND cp.code = 'CB'";
141else
142{
143 dol_print_error(null, 'Value for key = '.$key.' not supported');
144 exit;
145}*/
146if ($syear && !$smonth) {
147 $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
148} elseif ($syear && $smonth && !$sday) {
149 $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
150} elseif ($syear && $smonth && $sday) {
151 $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))."'";
152} else {
153 dol_print_error(null, 'Year not defined');
154}
155
156$resql = $db->query($sql);
157if ($resql) {
158 $num = $db->num_rows($resql);
159 $i = 0;
160
161 print "<!-- title of cash fence -->\n";
162 print '<center>';
163 print '<h2>';
164
165 $nameterminal = getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$object->posnumber);
166 print $langs->trans("CashControl")." #".$object->id.(($nameterminal != "TAKEPOS_TERMINAL_NAME_".$object->posnumber) ? '<br>'.$nameterminal : '');
167 if ($object->status == $object::STATUS_DRAFT) {
168 print '<br><span class="opacitymedium small">('.$langs->trans("Draft").")</span>";
169 }
170 print "</h2>";
171 print $mysoc->name;
172 print '<br>'.$langs->trans("DateCreationShort").": ".dol_print_date($object->date_creation, 'dayhour');
173 $userauthor = $object->fk_user_valid;
174 if (empty($userauthor)) {
175 $userauthor = $object->fk_user_creat;
176 }
177
178 $uservalid = new User($db);
179 if ($userauthor > 0) {
180 $uservalid->fetch($userauthor);
181 print '<br>'.$langs->trans("Author").': '.$uservalid->getFullName($langs);
182 }
183 print '<br>'.$langs->trans("Period").': '.$object->year_close.($object->month_close ? '-'.$object->month_close : '').($object->day_close ? '-'.$object->day_close : '');
184 print '</center>';
185
186 $invoicetmp = new Facture($db);
187
188 if (!$summaryonly) {
189 print "<div style='text-align: right'><h2>";
190 print $langs->trans("InitialBankBalance").' - '.$langs->trans("Cash").' : <div class="inline-block amount width100">'.price($object->opening).'</div>';
191 print "</h2></div>";
192 } else {
193 print '<br>';
194 }
195
196 $param = '';
197
198 if (!$summaryonly) {
199 print '<div class="div-table-responsive">';
200 print '<table class="tagtable liste">'."\n";
201
202 // Fields title
203 print '<tr class="liste_titre">';
204 print_liste_field_titre($arrayfields['b.rowid']['label'], $_SERVER['PHP_SELF'], 'b.rowid', '', $param, '', $sortfield, $sortorder);
205 print_liste_field_titre($arrayfields['b.dateo']['label'], $_SERVER['PHP_SELF'], 'b.dateo', '', $param, '"', $sortfield, $sortorder, 'center ');
206 print_liste_field_titre($arrayfields['ba.ref']['label'], $_SERVER['PHP_SELF'], 'ba.ref', '', $param, '', $sortfield, $sortorder, 'right ');
207 print_liste_field_titre($arrayfields['cp.code']['label'], $_SERVER['PHP_SELF'], 'cp.code', '', $param, '', $sortfield, $sortorder, 'right ');
208 print_liste_field_titre($arrayfields['b.debit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, 'right ');
209 print_liste_field_titre($arrayfields['b.credit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, 'right ');
210 print "</tr>\n";
211 }
212
213 // Loop on each record
214 $cash = $bank = $cheque = $other = 0;
215
216 $totalqty = 0;
217 $totalvat = 0;
218 $totalvatperrate = array();
219 $totallocaltax1 = 0;
220 $totallocaltax2 = 0;
221 $cachebankaccount = array();
222 $cacheinvoiceid = array();
223 $transactionspertype = array();
224 $amountpertype = array();
225
226 $totalarray = array('nbfield' => 0, 'pos' => array());
227 while ($i < $num) {
228 $objp = $db->fetch_object($resql);
229
230 // Load bankaccount
231 if (empty($cachebankaccount[$objp->bankid])) {
232 $bankaccounttmp = new Account($db);
233 $bankaccounttmp->fetch($objp->bankid);
234 $cachebankaccount[$objp->bankid] = $bankaccounttmp;
235 $bankaccount = $bankaccounttmp;
236 } else {
237 $bankaccount = $cachebankaccount[$objp->bankid];
238 }
239
240 $invoicetmp->fetch($objp->facid);
241
242 if (empty($cacheinvoiceid[$objp->facid])) {
243 $cacheinvoiceid[$objp->facid] = $objp->facid; // First time this invoice is found into list of invoice x payments
244 foreach ($invoicetmp->lines as $line) {
245 $totalqty += $line->qty;
246 $totalvat += $line->total_tva;
247 if ($line->tva_tx) {
248 if (empty($totalvatperrate[$line->tva_tx])) {
249 $totalvatperrate[$line->tva_tx] = 0;
250 }
251 $totalvatperrate[$line->tva_tx] += $line->total_tva;
252 }
253 $totallocaltax1 += $line->total_localtax1;
254 $totallocaltax2 += $line->total_localtax2;
255 }
256 }
257
258 if ($object->posmodule == "takepos") {
259 $var1 = 'CASHDESK_ID_BANKACCOUNT_CASH'.$object->posnumber;
260 } else {
261 $var1 = 'CASHDESK_ID_BANKACCOUNT_CASH';
262 }
263
264 if ($objp->code == 'CHQ') {
265 $cheque += $objp->amount;
266 if (empty($transactionspertype[$objp->code])) {
267 $transactionspertype[$objp->code] = 0;
268 }
269 $transactionspertype[$objp->code] += 1;
270 } elseif ($objp->code == 'CB') {
271 $bank += $objp->amount;
272 if (empty($transactionspertype[$objp->code])) {
273 $transactionspertype[$objp->code] = 0;
274 }
275 $transactionspertype[$objp->code] += 1;
276 } else {
277 if (getDolGlobalString($var1) == $bankaccount->id) {
278 $cash += $objp->amount;
279 // } elseif (getDolGlobalString($var2) == $bankaccount->id) $bank+=$objp->amount;
280 //elseif (getDolGlobalString($var3) == $bankaccount->id) $cheque+=$objp->amount;
281 if (empty($transactionspertype['CASH'])) {
282 $transactionspertype['CASH'] = 0;
283 }
284 $transactionspertype['CASH'] += 1;
285 } else {
286 $other += $objp->amount;
287 if (empty($transactionspertype['OTHER'])) {
288 $transactionspertype['OTHER'] = 0;
289 }
290 $transactionspertype['OTHER'] += 1;
291 }
292 }
293
294 if (empty($amountpertype[$objp->code])) {
295 $amountpertype[$objp->code] = 0;
296 }
297
298 if ($objp->amount < 0) {
299 $amountpertype[$objp->code] += $objp->amount;
300 }
301 if ($objp->amount > 0) {
302 $amountpertype[$objp->code] -= $objp->amount;
303 }
304
305 if (!$summaryonly) {
306 print '<tr class="oddeven">';
307
308 // Ref
309 print '<td class="nowrap left">';
310 print $invoicetmp->getNomUrl(1);
311 print '</td>';
312 if (!$i) {
313 $totalarray['nbfield']++;
314 }
315
316 // Date ope
317 print '<td class="nowrap left">';
318 print '<span id="dateoperation_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->do), "day")."</span>";
319 print "</td>\n";
320 if (!$i) {
321 $totalarray['nbfield']++;
322 }
323
324 // Bank account
325 print '<td class="nowrap right">';
326 print $bankaccount->getNomUrl(1);
327 print "</td>\n";
328 if (!$i) {
329 $totalarray['nbfield']++;
330 }
331
332 // Type
333 print '<td class="right">';
334 print $objp->code;
335 print "</td>\n";
336 if (!$i) {
337 $totalarray['nbfield']++;
338 }
339
340 // Debit
341 print '<td class="right">';
342 if ($objp->amount < 0) {
343 print '<span class="amount">'.price($objp->amount * -1).'</span>';
344 $totalarray['val']['totaldebfield'] += $objp->amount;
345 }
346 print "</td>\n";
347 if (!$i) {
348 $totalarray['nbfield']++;
349 }
350 if (!$i) {
351 $totalarray['pos'][$totalarray['nbfield']] = 'totaldebfield';
352 }
353
354 // Credit
355 print '<td class="right">';
356 if ($objp->amount > 0) {
357 print '<span class="amount">'.price($objp->amount).'</span>';
358 $totalarray['val']['totalcredfield'] += $objp->amount;
359 }
360 print "</td>\n";
361 if (!$i) {
362 $totalarray['nbfield']++;
363 }
364 if (!$i) {
365 $totalarray['pos'][$totalarray['nbfield']] = 'totalcredfield';
366 }
367
368 print "</tr>";
369 }
370
371 $i++;
372 }
373
374 if (!$summaryonly) {
375 // Show total line
376 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
377
378 print "</table>";
379 print "</div>";
380 }
381
382 //$cash = $amountpertype['LIQ'] + $object->opening;
383 $newcash = price2num($cash + (float) $object->opening, 'MT');
384
385 print '<div style="text-align: right">';
386 print '<h2>';
387
388 print $langs->trans("Cash").(!empty($transactionspertype['CASH']) ? ' ('.$transactionspertype['CASH'].' '.$langs->trans("Articles").')' : '').' : ';
389 if (!$summaryonly) {
390 print '<div class="inline-block amount width100">'.($cash >= 0 ? '+' : '').price($cash).'</div>';
391 print '<div class="inline-block amount width100">'.price($newcash).'</div>';
392 } else {
393 print '<div class="inline-block amount width100"></div>';
394 print '<div class="inline-block amount width100">'.price($cash).'</div>';
395 }
396 if (!$summaryonly && $object->status == $object::STATUS_VALIDATED && $newcash != $object->cash) {
397 print ' <div class="inline-block amountremaintopay fontsizeunset small"><> '.$langs->trans("Declared").': '.price($object->cash).'</div>';
398 }
399 print "<br>";
400
401 //print '<br>';
402 print $langs->trans("PaymentTypeCHQ").(!empty($transactionspertype['CHQ']) ? ' ('.$transactionspertype['CHQ'].' '.$langs->trans("Articles").')' : '').' : ';
403 print '<div class="inline-block amount width100"></div>';
404 print '<div class="inline-block amount width100">'.price($cheque).'</div>';
405 if (!$summaryonly && $object->status == $object::STATUS_VALIDATED && $cheque != $object->cheque) {
406 print ' <div class="inline-block amountremaintopay fontsizeunset small"><> '.$langs->trans("Declared").' : '.price($object->cheque).'</div>';
407 }
408 print "<br>";
409
410 //print '<br>';
411 print $langs->trans("PaymentTypeCB").(!empty($transactionspertype['CB']) ? ' ('.$transactionspertype['CB'].' '.$langs->trans("Articles").')' : '').' : ';
412 print '<div class="inline-block amount width100"></div>';
413 print '<div class="inline-block amount width100">'.price($bank).'</div>';
414 if (!$summaryonly && $object->status == $object::STATUS_VALIDATED && $bank != $object->card) {
415 print ' <div class="inline-block amountremaintopay fontsizeunset small"><> '.$langs->trans("Declared").': '.price($object->card).'</div>';
416 }
417 print "<br>";
418
419 // print '<br>';
420 if ($other) {
421 print ''.$langs->trans("Other").(!empty($transactionspertype['OTHER']) ? ' ('.$transactionspertype['OTHER'].' '.$langs->trans("Articles").')' : '').' : ';
422 print '<div class="inline-block amount width100"></div>';
423 print '<div class="inline-block amount width100">'.price($other)."</div>";
424 print '<br>';
425 }
426
427 print "<br>";
428
429 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>';
430
431 print '<br>'.$langs->trans("TotalVAT").' : <div class="inline-block amount width100"></div><div class="inline-block amount width100">'.price($totalvat).'</div>';
432
433 if ($mysoc->useLocalTax(1)) {
434 print '<br>'.$langs->trans("TotalLT1").' : <div class="inline-block amount width100"></div><div class="inline-block amount width100">'.price($totallocaltax1).'</div>';
435 }
436 if ($mysoc->useLocalTax(1)) {
437 print '<br>'.$langs->trans("TotalLT2").' : <div class="inline-block amount width100"></div><div class="inline-block amount width100">'.price($totallocaltax2).'</div>';
438 }
439
440 if (!empty($totalvatperrate) && is_array($totalvatperrate)) {
441 print '<br><br><div class="small inline-block">'.$langs->trans("VATRate").'</div>';
442 foreach ($totalvatperrate as $keyrate => $valuerate) {
443 print '<br><div class="small">'.$langs->trans("VATRate").' '.vatrate($keyrate, 1).' : <div class="inline-block amount width100"></div><div class="inline-block amount width100">'.price($valuerate).'</div></div>';
444 }
445 }
446
447 print '</h2>';
448 print '</div>';
449
450 print '</form>';
451
452 $db->free($resql);
453} else {
454 dol_print_error($db);
455}
456
457print '</div>';
458
459llxFooter();
460
461$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
Definition date.lib.php:595
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:614
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.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return 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.