dolibarr  13.0.2
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')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
33 if (!defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
34 
35 require '../../main.inc.php';
36 require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
40 
41 $langs->loadLangs(array("bills", "banks"));
42 
43 $id = GETPOST('id', 'int');
44 
45 $_GET['optioncss'] = "print";
46 
47 $cashcontrol = new CashControl($db);
48 $cashcontrol->fetch($id);
49 
50 //$limit = GETPOST('limit')?GETPOST('limit', 'int'):$conf->liste_limit;
51 $sortorder = 'ASC';
52 $sortfield = 'b.datev,b.dateo,b.rowid';
53 
54 $arrayfields = array(
55  'b.rowid'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
56  'b.dateo'=>array('label'=>$langs->trans("DateOperationShort"), 'checked'=>1),
57  'b.num_chq'=>array('label'=>$langs->trans("Number"), 'checked'=>1),
58  'ba.ref'=>array('label'=>$langs->trans("BankAccount"), 'checked'=>1),
59  'cp.code'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>1),
60  'b.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1, 'position'=>600),
61  'b.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1, 'position'=>605),
62 );
63 
64 $syear = $cashcontrol->year_close;
65 $smonth = $cashcontrol->month_close;
66 $sday = $cashcontrol->day_close;
67 
68 $posmodule = $cashcontrol->posmodule;
69 $terminalid = $cashcontrol->posnumber;
70 
71 
72 /*
73  * View
74  */
75 
76 $param = '';
77 
78 llxHeader('', $langs->trans("CashControl"), '', '', 0, 0, array(), array(), $param);
79 
80 /*$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,";
81 $sql.= " b.fk_account, b.fk_type,";
82 $sql.= " ba.rowid as bankid, ba.ref as bankref,";
83 $sql.= " bu.url_id,";
84 $sql.= " f.module_source, f.ref as ref";
85 $sql.= " FROM ";
86 //if ($bid) $sql.= MAIN_DB_PREFIX."bank_class as l,";
87 $sql.= " ".MAIN_DB_PREFIX."bank_account as ba,";
88 $sql.= " ".MAIN_DB_PREFIX."bank as b";
89 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND type = 'payment'";
90 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON bu.url_id = f.rowid";
91 $sql.= " WHERE b.fk_account = ba.rowid";
92 // Define filter on invoice
93 $sql.= " AND f.module_source = '".$db->escape($cashcontrol->posmodule)."'";
94 $sql.= " AND f.pos_source = '".$db->escape($cashcontrol->posnumber)."'";
95 $sql.= " AND f.entity IN (".getEntity('facture').")";
96 // Define filter on data
97 if ($syear && ! $smonth) $sql.= " AND dateo BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
98 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))."'";
99 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))."'";
100 else dol_print_error('', 'Year not defined');
101 // Define filter on bank account
102 $sql.=" AND (b.fk_account=".$conf->global->CASHDESK_ID_BANKACCOUNT_CASH;
103 $sql.=" OR b.fk_account=".$conf->global->CASHDESK_ID_BANKACCOUNT_CB;
104 $sql.=" OR b.fk_account=".$conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE;
105 $sql.=")";
106 */
107 $sql = "SELECT f.rowid as facid, f.ref, f.datef as do, pf.amount as amount, b.fk_account as bankid, cp.code";
108 $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";
109 $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";
110 $sql .= " AND f.module_source = '".$db->escape($posmodule)."'";
111 $sql .= " AND f.pos_source = '".$db->escape($terminalid)."'";
112 $sql .= " AND f.paye = 1";
113 $sql .= " AND p.entity = ".$conf->entity; // Never share entities for features related to accountancy
114 /*if ($key == 'cash') $sql.=" AND cp.code = 'LIQ'";
115 elseif ($key == 'cheque') $sql.=" AND cp.code = 'CHQ'";
116 elseif ($key == 'card') $sql.=" AND cp.code = 'CB'";
117 else
118 {
119  dol_print_error('Value for key = '.$key.' not supported');
120  exit;
121 }*/
122 if ($syear && !$smonth) $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
123 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))."'";
124 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))."'";
125 else dol_print_error('', 'Year not defined');
126 
127 $resql = $db->query($sql);
128 if ($resql) {
129  $num = $db->num_rows($resql);
130  $i = 0;
131 
132  print "<!-- title of cash fence -->\n";
133  print "<center><h2>";
134  if ($cashcontrol->status != $cashcontrol::STATUS_DRAFT) print $langs->trans("CashControl")." ".$cashcontrol->id;
135  else print $langs->trans("CashControl")." - ".$langs->trans("Draft");
136  print "<br>".$langs->trans("DateCreationShort").": ".dol_print_date($cashcontrol->date_creation, 'dayhour');
137  print "</h2></center>";
138 
139  $invoicetmp = new Facture($db);
140 
141  print "<div style='text-align: right'><h2>";
142  print $langs->trans("InitialBankBalance").' - '.$langs->trans("Cash")." : ".price($cashcontrol->opening);
143  print "</h2></div>";
144 
145  print '<div class="div-table-responsive">';
146  print '<table class="tagtable liste">'."\n";
147 
148  $param = '';
149 
150  // Fields title
151  print '<tr class="liste_titre">';
152  print_liste_field_titre($arrayfields['b.rowid']['label'], $_SERVER['PHP_SELF'], 'b.rowid', '', $param, '', $sortfield, $sortorder);
153  print_liste_field_titre($arrayfields['b.dateo']['label'], $_SERVER['PHP_SELF'], 'b.dateo', '', $param, '"', $sortfield, $sortorder, 'center ');
154  print_liste_field_titre($arrayfields['ba.ref']['label'], $_SERVER['PHP_SELF'], 'ba.ref', '', $param, '', $sortfield, $sortorder, 'right ');
155  print_liste_field_titre($arrayfields['cp.code']['label'], $_SERVER['PHP_SELF'], 'cp.code', '', $param, '', $sortfield, $sortorder, 'right ');
156  print_liste_field_titre($arrayfields['b.debit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, 'right ');
157  print_liste_field_titre($arrayfields['b.credit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, 'right ');
158  print "</tr>\n";
159 
160  // Loop on each record
161  $sign = 1;
162  $cash = $bank = $cheque = $other = 0;
163 
164  $totalarray = array();
165  $cachebankaccount = array();
166  $amountpertype = array();
167  while ($i < $num) {
168  $objp = $db->fetch_object($resql);
169 
170  if (empty($cachebankaccount[$objp->bankid])) {
171  $bankaccounttmp = new Account($db);
172  $bankaccounttmp->fetch($objp->bankid);
173  $cachebankaccount[$objp->bankid] = $bankaccounttmp;
174  $bankaccount = $bankaccounttmp;
175  } else {
176  $bankaccount = $cachebankaccount[$objp->bankid];
177  }
178 
179  $invoicetmp->fetch($objp->facid);
180 
181  /*if ($first == "yes")
182  {
183  print '<tr class="oddeven">';
184  print '<td>'.$langs->trans("InitialBankBalance").' - '.$langs->trans("Cash").'</td>';
185  print '<td></td><td></td><td></td><td class="right">'.price($cashcontrol->opening).'</td>';
186  print '</tr>';
187  $first = "no";
188  }*/
189 
190  print '<tr class="oddeven">';
191 
192  // Ref
193  print '<td class="nowrap left">';
194  print $invoicetmp->getNomUrl(1);
195  print '</td>';
196  if (!$i) $totalarray['nbfield']++;
197 
198  // Date ope
199  print '<td class="nowrap left">';
200  print '<span id="dateoperation_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->do), "day")."</span>";
201  print "</td>\n";
202  if (!$i) $totalarray['nbfield']++;
203 
204  // Bank account
205  print '<td class="nowrap right">';
206  print $bankaccount->getNomUrl(1);
207  if ($cashcontrol->posmodule == "takepos") {
208  $var1 = 'CASHDESK_ID_BANKACCOUNT_CASH'.$cashcontrol->posnumber;
209  } else {
210  $var1 = 'CASHDESK_ID_BANKACCOUNT_CASH';
211  }
212  if ($objp->code == 'CHQ') {
213  $cheque += $objp->amount;
214  } elseif ($objp->code == 'CB') {
215  $bank += $objp->amount;
216  } else {
217  if ($conf->global->$var1 == $bankaccount->id) $cash += $objp->amount;
218  //elseif ($conf->global->$var2 == $bankaccount->id) $bank+=$objp->amount;
219  //elseif ($conf->global->$var3 == $bankaccount->id) $cheque+=$objp->amount;
220  else $other += $objp->amount;
221  }
222  print "</td>\n";
223  if (!$i) $totalarray['nbfield']++;
224 
225  // Type
226  print '<td class="right">';
227  print $objp->code;
228  if (empty($amountpertype[$objp->code])) $amountpertype[$objp->code] = 0;
229  print "</td>\n";
230  if (!$i) $totalarray['nbfield']++;
231 
232  // Debit
233  print '<td class="right">';
234  if ($objp->amount < 0) {
235  print price($objp->amount * -1);
236  $totalarray['val']['totaldebfield'] += $objp->amount;
237  $amountpertype[$objp->code] += $objp->amount;
238  }
239  print "</td>\n";
240  if (!$i) $totalarray['nbfield']++;
241  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totaldebfield';
242 
243  // Credit
244  print '<td class="right">';
245  if ($objp->amount > 0) {
246  print price($objp->amount);
247  $totalarray['val']['totalcredfield'] += $objp->amount;
248  $amountpertype[$objp->code] -= $objp->amount;
249  }
250  print "</td>\n";
251  if (!$i) $totalarray['nbfield']++;
252  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalcredfield';
253 
254  print "</tr>";
255 
256  $i++;
257  }
258 
259  // Show total line
260  include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
261 
262  print "</table>";
263 
264  //$cash = $amountpertype['LIQ'] + $cashcontrol->opening;
265  $cash = price2num($cash + $cashcontrol->opening, 'MT');
266 
267  print "<div style='text-align: right'><h2>";
268  print $langs->trans("Cash").": ".price($cash);
269  if ($cashcontrol->status == $cashcontrol::STATUS_VALIDATED && $cash != $cashcontrol->cash) {
270  print ' <> <span class="amountremaintopay">'.$langs->trans("Declared").': '.price($cashcontrol->cash).'</span>';
271  }
272  print "<br><br>";
273 
274  //print '<br>';
275  print $langs->trans("PaymentTypeCHQ").": ".price($cheque);
276  if ($cashcontrol->status == $cashcontrol::STATUS_VALIDATED && $cheque != $cashcontrol->cheque) {
277  print ' <> <span class="amountremaintopay">'.$langs->trans("Declared").': '.price($cashcontrol->cheque).'</span>';
278  }
279  print "<br><br>";
280 
281  //print '<br>';
282  print $langs->trans("PaymentTypeCB").": ".price($bank);
283  if ($cashcontrol->status == $cashcontrol::STATUS_VALIDATED && $bank != $cashcontrol->card) {
284  print ' <> <span class="amountremaintopay">'.$langs->trans("Declared").': '.price($cashcontrol->card).'</span>';
285  }
286  print "<br><br>";
287 
288  // print '<br>';
289  if ($other) {
290  print '<br>'.$langs->trans("Other").": ".price($other)."<br><br>";
291  }
292  print "</h2></div>";
293 
294  //save totals to DB
295  /*
296  $sql = "UPDATE ".MAIN_DB_PREFIX."pos_cash_fence ";
297  $sql .= "SET";
298  $sql .= " cash='".$db->escape($cash)."'";
299  $sql .= ", card='".$db->escape($bank)."'";
300  $sql .= " where rowid=".$id;
301  $db->query($sql);
302  */
303 
304  print "</div>";
305 
306  print '</form>';
307 
308  $db->free($resql);
309 } else {
310  dol_print_error($db);
311 }
312 
313 llxFooter();
314 
315 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
Class to manage cash fence.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:481
Class to manage bank accounts.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:498
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to manage invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.