32 if (!defined(
'NOREQUIREMENU')) {
33 define(
'NOREQUIREMENU',
'1');
35 if (!defined(
'NOBROWSERNOTIF')) {
36 define(
'NOBROWSERNOTIF',
'1');
39 $_GET[
'optioncss'] =
"print";
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';
49 $langs->loadLangs(array(
"bills",
"banks"));
58 $sortfield =
'b.datev,b.dateo,b.rowid';
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),
70 $syear = $object->year_close;
71 $smonth = $object->month_close;
72 $sday = $object->day_close;
74 $posmodule = $object->posmodule;
75 $terminalid = $object->posnumber;
78 if ($user->socid > 0) {
82 if (empty($user->rights->cashdesk->run) && empty($user->rights->takepos->run)) {
91 $title = $langs->trans(
"CashControl");
94 llxHeader(
'', $title,
'',
'', 0, 0, array(), array(), $param);
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;
138 if ($syear && !$smonth) {
140 } elseif ($syear && $smonth && !$sday) {
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)).
"'";
148 $resql = $db->query($sql);
150 $num = $db->num_rows(
$resql);
153 print
"<!-- title of cash fence -->\n";
156 if ($object->status != $object::STATUS_DRAFT) {
157 print $langs->trans(
"CashControl").
" ".$object->id;
159 print $langs->trans(
"CashControl").
" - ".$langs->trans(
"Draft");
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;
169 $uservalid =
new User($db);
170 if ($userauthor > 0) {
171 $uservalid->fetch($userauthor);
172 print
'<br>'.$langs->trans(
"Author").
': '.$uservalid->getFullName($langs);
174 print
'<br>'.$langs->trans(
"Period").
': '.$object->year_close.($object->month_close ?
'-'.$object->month_close :
'').($object->day_close ?
'-'.$object->day_close :
'');
177 $invoicetmp =
new Facture($db);
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>';
183 print
'<div class="div-table-responsive">';
184 print
'<table class="tagtable liste">'.
"\n";
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 ');
199 $cash = $bank = $cheque = $other = 0;
203 $totalvatperrate = array();
206 $cachebankaccount = array();
207 $cacheinvoiceid = array();
208 $transactionspertype = array();
209 $amountpertype = array();
211 $totalarray = array();
213 $objp = $db->fetch_object(
$resql);
216 if (empty($cachebankaccount[$objp->bankid])) {
217 $bankaccounttmp =
new Account($db);
218 $bankaccounttmp->fetch($objp->bankid);
219 $cachebankaccount[$objp->bankid] = $bankaccounttmp;
220 $bankaccount = $bankaccounttmp;
222 $bankaccount = $cachebankaccount[$objp->bankid];
225 $invoicetmp->fetch($objp->facid);
227 if (empty($cacheinvoiceid[$objp->facid])) {
228 $cacheinvoiceid[$objp->facid] = $objp->facid;
229 foreach ($invoicetmp->lines as $line) {
230 $totalqty += $line->qty;
231 $totalvat += $line->total_tva;
233 if (empty($totalvatperrate[$line->tva_tx])) {
234 $totalvatperrate[$line->tva_tx] = 0;
236 $totalvatperrate[$line->tva_tx] += $line->total_tva;
238 $totallocaltax1 += $line->total_localtax1;
239 $totallocaltax2 += $line->total_localtax2;
243 print
'<tr class="oddeven">';
246 print
'<td class="nowrap left">';
247 print $invoicetmp->getNomUrl(1);
250 $totalarray[
'nbfield']++;
254 print
'<td class="nowrap left">';
255 print
'<span id="dateoperation_'.$objp->rowid.
'">'.
dol_print_date($db->jdate($objp->do),
"day").
"</span>";
258 $totalarray[
'nbfield']++;
261 if ($object->posmodule ==
"takepos") {
262 $var1 =
'CASHDESK_ID_BANKACCOUNT_CASH'.$object->posnumber;
264 $var1 =
'CASHDESK_ID_BANKACCOUNT_CASH';
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;
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;
281 $transactionspertype[$objp->code] += 1;
283 if ($conf->global->$var1 == $bankaccount->id) {
284 $cash += $objp->amount;
287 if (empty($transactionspertype[
'CASH'])) {
288 $transactionspertype[
'CASH'] = 0;
290 $transactionspertype[
'CASH'] += 1;
292 $other += $objp->amount;
293 if (empty($transactionspertype[
'OTHER'])) {
294 $transactionspertype[
'OTHER'] = 0;
296 $transactionspertype[
'OTHER'] += 1;
301 $totalarray[
'nbfield']++;
305 print
'<td class="right">';
307 if (empty($amountpertype[$objp->code])) {
308 $amountpertype[$objp->code] = 0;
312 $totalarray[
'nbfield']++;
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;
324 $totalarray[
'nbfield']++;
327 $totalarray[
'pos'][$totalarray[
'nbfield']] =
'totaldebfield';
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;
339 $totalarray[
'nbfield']++;
342 $totalarray[
'pos'][$totalarray[
'nbfield']] =
'totalcredfield';
351 include DOL_DOCUMENT_ROOT.
'/core/tpl/list_print_total.tpl.php';
357 $cash =
price2num($cash + $object->opening,
'MT');
359 print
'<div style="text-align: right">';
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>';
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>';
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>';
384 print
''.$langs->trans(
"Other").($transactionspertype[
'OTHER'] ?
' ('.$transactionspertype[
'OTHER'].
')' :
'').
' : <div class="inline-block amount width100">'.
price($other).
"</div>";
388 print $langs->trans(
"Total").
' ('.$totalqty.
' '.$langs->trans(
"Articles").
') : <div class="inline-block amount width100">'.
price($cash + $cheque + $bank + $other).
'</div>';
390 print
'<br>'.$langs->trans(
"TotalVAT").
' : <div class="inline-block amount width100">'.
price($totalvat).
'</div>';
392 if ($mysoc->useLocalTax(1)) {
393 print
'<br>'.$langs->trans(
"TotalLT1").
' : <div class="inline-block amount width100">'.
price($totallocaltax1).
'</div>';
395 if ($mysoc->useLocalTax(1)) {
396 print
'<br>'.$langs->trans(
"TotalLT2").
' : <div class="inline-block amount width100">'.
price($totallocaltax2).
'</div>';
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>';