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