dolibarr 19.0.4
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 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32if (!defined('NOREQUIREMENU')) {
33 define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
34}
35if (!defined('NOBROWSERNOTIF')) {
36 define('NOBROWSERNOTIF', '1'); // Disable browser notification
37}
38
39$_GET['optioncss'] = "print";
40
41// Load Dolibarr environment
42require '../../main.inc.php';
43require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
44require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
45require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
46require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
48
49
50$langs->loadLangs(array("bills", "banks"));
51
52$id = GETPOST('id', 'int');
53
54$object = new CashControl($db);
55$object->fetch($id);
56
57//$limit = GETPOST('limit')?GETPOST('limit', 'int'):$conf->liste_limit;
58$sortorder = 'ASC';
59$sortfield = 'b.datev,b.dateo,b.rowid';
60
61$arrayfields = array(
62 'b.rowid'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
63 'b.dateo'=>array('label'=>$langs->trans("DateOperationShort"), 'checked'=>1),
64 'b.num_chq'=>array('label'=>$langs->trans("Number"), 'checked'=>1),
65 'ba.ref'=>array('label'=>$langs->trans("BankAccount"), 'checked'=>1),
66 'cp.code'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>1),
67 'b.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1, 'position'=>600),
68 'b.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1, 'position'=>605),
69);
70
71$syear = $object->year_close;
72$smonth = $object->month_close;
73$sday = $object->day_close;
74
75$posmodule = $object->posmodule;
76$terminalid = $object->posnumber;
77
78// Security check
79if ($user->socid > 0) { // Protection if external user
80 //$socid = $user->socid;
82}
83if (!$user->hasRight('cashdesk', 'run') && !$user->hasRight('takepos', 'run')) {
85}
86
87
88/*
89 * View
90 */
91
92$title = $langs->trans("CashControl");
93$param = '';
94
95llxHeader('', $title, '', '', 0, 0, array(), array(), $param);
96
97/*$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,";
98$sql.= " b.fk_account, b.fk_type,";
99$sql.= " ba.rowid as bankid, ba.ref as bankref,";
100$sql.= " bu.url_id,";
101$sql.= " f.module_source, f.ref as ref";
102$sql.= " FROM ";
103//if ($bid) $sql.= MAIN_DB_PREFIX."bank_class as l,";
104$sql.= " ".MAIN_DB_PREFIX."bank_account as ba,";
105$sql.= " ".MAIN_DB_PREFIX."bank as b";
106$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND type = 'payment'";
107$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON bu.url_id = f.rowid";
108$sql.= " WHERE b.fk_account = ba.rowid";
109// Define filter on invoice
110$sql.= " AND f.module_source = '".$db->escape($object->posmodule)."'";
111$sql.= " AND f.pos_source = '".$db->escape($object->posnumber)."'";
112$sql.= " AND f.entity IN (".getEntity('facture').")";
113// Define filter on data
114if ($syear && ! $smonth) $sql.= " AND dateo BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
115elseif ($syear && $smonth && ! $sday) $sql.= " AND dateo BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
116elseif ($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))."'";
117else dol_print_error('', 'Year not defined');
118// Define filter on bank account
119$sql.=" AND (b.fk_account = ".((int) $conf->global->CASHDESK_ID_BANKACCOUNT_CASH);
120$sql.=" OR b.fk_account = ".((int) $conf->global->CASHDESK_ID_BANKACCOUNT_CB);
121$sql.=" OR b.fk_account = ".((int) $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE);
122$sql.=")";
123*/
124$sql = "SELECT f.rowid as facid, f.ref, f.datef as do, pf.amount as amount, b.fk_account as bankid, cp.code";
125$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";
126$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";
127$sql .= " AND f.module_source = '".$db->escape($posmodule)."'";
128$sql .= " AND f.pos_source = '".$db->escape($terminalid)."'";
129$sql .= " AND f.paye = 1";
130$sql .= " AND p.entity = ".$conf->entity; // Never share entities for features related to accountancy
131/*if ($key == 'cash') $sql.=" AND cp.code = 'LIQ'";
132elseif ($key == 'cheque') $sql.=" AND cp.code = 'CHQ'";
133elseif ($key == 'card') $sql.=" AND cp.code = 'CB'";
134else
135{
136 dol_print_error('Value for key = '.$key.' not supported');
137 exit;
138}*/
139if ($syear && !$smonth) {
140 $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
141} elseif ($syear && $smonth && !$sday) {
142 $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
143} elseif ($syear && $smonth && $sday) {
144 $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))."'";
145} else {
146 dol_print_error('', 'Year not defined');
147}
148
149$resql = $db->query($sql);
150if ($resql) {
151 $num = $db->num_rows($resql);
152 $i = 0;
153
154 print "<!-- title of cash fence -->\n";
155 print '<center>';
156 print '<h2>';
157 if ($object->status != $object::STATUS_DRAFT) {
158 print $langs->trans("CashControl")." ".$object->id;
159 } else {
160 print $langs->trans("CashControl")." - ".$langs->trans("Draft");
161 }
162 print "</h2>";
163 print $mysoc->name;
164 print '<br>'.$langs->trans("DateCreationShort").": ".dol_print_date($object->date_creation, 'dayhour');
165 $userauthor = $object->fk_user_valid;
166 if (empty($userauthor)) {
167 $userauthor = $object->fk_user_creat;
168 }
169
170 $uservalid = new User($db);
171 if ($userauthor > 0) {
172 $uservalid->fetch($userauthor);
173 print '<br>'.$langs->trans("Author").': '.$uservalid->getFullName($langs);
174 }
175 print '<br>'.$langs->trans("Period").': '.$object->year_close.($object->month_close ? '-'.$object->month_close : '').($object->day_close ? '-'.$object->day_close : '');
176 print '</center>';
177
178 $invoicetmp = new Facture($db);
179
180 print "<div style='text-align: right'><h2>";
181 print $langs->trans("InitialBankBalance").' - '.$langs->trans("Cash").' : <div class="inline-block amount width100">'.price($object->opening).'</div>';
182 print "</h2></div>";
183
184 print '<div class="div-table-responsive">';
185 print '<table class="tagtable liste">'."\n";
186
187 $param = '';
188
189 // Fields title
190 print '<tr class="liste_titre">';
191 print_liste_field_titre($arrayfields['b.rowid']['label'], $_SERVER['PHP_SELF'], 'b.rowid', '', $param, '', $sortfield, $sortorder);
192 print_liste_field_titre($arrayfields['b.dateo']['label'], $_SERVER['PHP_SELF'], 'b.dateo', '', $param, '"', $sortfield, $sortorder, 'center ');
193 print_liste_field_titre($arrayfields['ba.ref']['label'], $_SERVER['PHP_SELF'], 'ba.ref', '', $param, '', $sortfield, $sortorder, 'right ');
194 print_liste_field_titre($arrayfields['cp.code']['label'], $_SERVER['PHP_SELF'], 'cp.code', '', $param, '', $sortfield, $sortorder, 'right ');
195 print_liste_field_titre($arrayfields['b.debit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, 'right ');
196 print_liste_field_titre($arrayfields['b.credit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, 'right ');
197 print "</tr>\n";
198
199 // Loop on each record
200 $cash = $bank = $cheque = $other = 0;
201
202 $totalqty = 0;
203 $totalvat = 0;
204 $totalvatperrate = array();
205 $totallocaltax1 = 0;
206 $totallocaltax2 = 0;
207 $cachebankaccount = array();
208 $cacheinvoiceid = array();
209 $transactionspertype = array();
210 $amountpertype = array();
211
212 $totalarray = array();
213 while ($i < $num) {
214 $objp = $db->fetch_object($resql);
215
216 // Load bankaccount
217 if (empty($cachebankaccount[$objp->bankid])) {
218 $bankaccounttmp = new Account($db);
219 $bankaccounttmp->fetch($objp->bankid);
220 $cachebankaccount[$objp->bankid] = $bankaccounttmp;
221 $bankaccount = $bankaccounttmp;
222 } else {
223 $bankaccount = $cachebankaccount[$objp->bankid];
224 }
225
226 $invoicetmp->fetch($objp->facid);
227
228 if (empty($cacheinvoiceid[$objp->facid])) {
229 $cacheinvoiceid[$objp->facid] = $objp->facid; // First time this invoice is found into list of invoice x payments
230 foreach ($invoicetmp->lines as $line) {
231 $totalqty += $line->qty;
232 $totalvat += $line->total_tva;
233 if ($line->tva_tx) {
234 if (empty($totalvatperrate[$line->tva_tx])) {
235 $totalvatperrate[$line->tva_tx] = 0;
236 }
237 $totalvatperrate[$line->tva_tx] += $line->total_tva;
238 }
239 $totallocaltax1 += $line->total_localtax1;
240 $totallocaltax2 += $line->total_localtax2;
241 }
242 }
243
244 print '<tr class="oddeven">';
245
246 // Ref
247 print '<td class="nowrap left">';
248 print $invoicetmp->getNomUrl(1);
249 print '</td>';
250 if (!$i) {
251 $totalarray['nbfield']++;
252 }
253
254 // Date ope
255 print '<td class="nowrap left">';
256 print '<span id="dateoperation_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->do), "day")."</span>";
257 print "</td>\n";
258 if (!$i) {
259 $totalarray['nbfield']++;
260 }
261
262 if ($object->posmodule == "takepos") {
263 $var1 = 'CASHDESK_ID_BANKACCOUNT_CASH'.$object->posnumber;
264 } else {
265 $var1 = 'CASHDESK_ID_BANKACCOUNT_CASH';
266 }
267
268 // Bank account
269 print '<td class="nowrap right">';
270 print $bankaccount->getNomUrl(1);
271 if ($objp->code == 'CHQ') {
272 $cheque += $objp->amount;
273 if (empty($transactionspertype[$objp->code])) {
274 $transactionspertype[$objp->code] = 0;
275 }
276 $transactionspertype[$objp->code] += 1;
277 } elseif ($objp->code == 'CB') {
278 $bank += $objp->amount;
279 if (empty($transactionspertype[$objp->code])) {
280 $transactionspertype[$objp->code] = 0;
281 }
282 $transactionspertype[$objp->code] += 1;
283 } else {
284 if (getDolGlobalString($var1) == $bankaccount->id) {
285 $cash += $objp->amount;
286 // } elseif (getDolGlobalString($var2) == $bankaccount->id) $bank+=$objp->amount;
287 //elseif (getDolGlobalString($var3) == $bankaccount->id) $cheque+=$objp->amount;
288 if (empty($transactionspertype['CASH'])) {
289 $transactionspertype['CASH'] = 0;
290 }
291 $transactionspertype['CASH'] += 1;
292 } else {
293 $other += $objp->amount;
294 if (empty($transactionspertype['OTHER'])) {
295 $transactionspertype['OTHER'] = 0;
296 }
297 $transactionspertype['OTHER'] += 1;
298 }
299 }
300 print "</td>\n";
301 if (!$i) {
302 $totalarray['nbfield']++;
303 }
304
305 // Type
306 print '<td class="right">';
307 print $objp->code;
308 if (empty($amountpertype[$objp->code])) {
309 $amountpertype[$objp->code] = 0;
310 }
311 print "</td>\n";
312 if (!$i) {
313 $totalarray['nbfield']++;
314 }
315
316 // Debit
317 print '<td class="right">';
318 if ($objp->amount < 0) {
319 print '<span class="amount">'.price($objp->amount * -1).'</span>';
320 $totalarray['val']['totaldebfield'] += $objp->amount;
321 $amountpertype[$objp->code] += $objp->amount;
322 }
323 print "</td>\n";
324 if (!$i) {
325 $totalarray['nbfield']++;
326 }
327 if (!$i) {
328 $totalarray['pos'][$totalarray['nbfield']] = 'totaldebfield';
329 }
330
331 // Credit
332 print '<td class="right">';
333 if ($objp->amount > 0) {
334 print '<span class="amount">'.price($objp->amount).'</span>';
335 $totalarray['val']['totalcredfield'] += $objp->amount;
336 $amountpertype[$objp->code] -= $objp->amount;
337 }
338 print "</td>\n";
339 if (!$i) {
340 $totalarray['nbfield']++;
341 }
342 if (!$i) {
343 $totalarray['pos'][$totalarray['nbfield']] = 'totalcredfield';
344 }
345
346 print "</tr>";
347
348 $i++;
349 }
350
351 // Show total line
352 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
353
354 print "</table>";
355 print "</div>";
356
357 //$cash = $amountpertype['LIQ'] + $object->opening;
358 $cash = price2num($cash + $object->opening, 'MT');
359
360 print '<div style="text-align: right">';
361 print '<h2>';
362
363 print $langs->trans("Cash").(!empty($transactionspertype['CASH']) ? ' ('.$transactionspertype['CASH'].')' : '').' : <div class="inline-block amount width100">'.price($cash).'</div>';
364 if ($object->status == $object::STATUS_VALIDATED && $cash != $object->cash) {
365 print ' <> <div class="inline-block amountremaintopay fontsizeunset">'.$langs->trans("Declared").': '.price($object->cash).'</div>';
366 }
367 print "<br>";
368
369 //print '<br>';
370 print $langs->trans("PaymentTypeCHQ").(!empty($transactionspertype['CHQ']) ? ' ('.$transactionspertype['CHQ'].')' : '').' : <div class="inline-block amount width100">'.price($cheque).'</div>';
371 if ($object->status == $object::STATUS_VALIDATED && $cheque != $object->cheque) {
372 print ' <> <div class="inline-block amountremaintopay fontsizeunset">'.$langs->trans("Declared").' : '.price($object->cheque).'</div>';
373 }
374 print "<br>";
375
376 //print '<br>';
377 print $langs->trans("PaymentTypeCB").(!empty($transactionspertype['CB']) ? ' ('.$transactionspertype['CB'].')' : '').' : <div class="inline-block amount width100">'.price($bank).'</div>';
378 if ($object->status == $object::STATUS_VALIDATED && $bank != $object->card) {
379 print ' <> <div class="inline-block amountremaintopay fontsizeunset">'.$langs->trans("Declared").': '.price($object->card).'</div>';
380 }
381 print "<br>";
382
383 // print '<br>';
384 if ($other) {
385 print ''.$langs->trans("Other").($transactionspertype['OTHER'] ? ' ('.$transactionspertype['OTHER'].')' : '').' : <div class="inline-block amount width100">'.price($other)."</div>";
386 print '<br>';
387 }
388
389 print $langs->trans("Total").' ('.$totalqty.' '.$langs->trans("Articles").') : <div class="inline-block amount width100">'.price($cash + $cheque + $bank + $other).'</div>';
390
391 print '<br>'.$langs->trans("TotalVAT").' : <div class="inline-block amount width100">'.price($totalvat).'</div>';
392
393 if ($mysoc->useLocalTax(1)) {
394 print '<br>'.$langs->trans("TotalLT1").' : <div class="inline-block amount width100">'.price($totallocaltax1).'</div>';
395 }
396 if ($mysoc->useLocalTax(1)) {
397 print '<br>'.$langs->trans("TotalLT2").' : <div class="inline-block amount width100">'.price($totallocaltax2).'</div>';
398 }
399
400 if (!empty($totalvatperrate) && is_array($totalvatperrate)) {
401 print '<br><br><div class="small inline-block">'.$langs->trans("VATRate").'</div>';
402 foreach ($totalvatperrate as $keyrate => $valuerate) {
403 print '<br><div class="small">'.$langs->trans("VATRate").' '.vatrate($keyrate, 1).' : <div class="inline-block amount width100">'.price($valuerate).'</div></div>';
404 }
405 }
406
407 print '</h2>';
408 print '</div>';
409
410 print '</form>';
411
412 $db->free($resql);
413} else {
414 dol_print_error($db);
415}
416
417llxFooter();
418
419$db->close();
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:594
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:613
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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='', $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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.