dolibarr 21.0.0-alpha
box_accountancy_last_manual_entries.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28
29
34{
35 public $boxcode = "accountancy_last_manual_entries";
36 public $boximg = "accountancy";
37 public $boxlabel = "BoxLastManualEntries";
38 public $depends = array("accounting");
39
46 public function __construct($db, $param)
47 {
48 global $user;
49
50 $this->db = $db;
51
52 $this->hidden = !$user->hasRight('accounting', 'mouvements', 'lire');
53 }
54
61 public function loadBox($max = 5)
62 {
63 global $user, $langs, $conf;
64
65 include_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
66
67 $bookkeepingstatic = new BookKeeping($this->db);
68
69 $this->info_box_head = array('text' => $langs->trans("BoxTitleLastManualEntries", $max));
70
71 if ($user->hasRight('accounting', 'mouvements', 'lire')) {
72 $sql = "SELECT DISTINCT b.piece_num";
73 $sql .= ", b.doc_date as date_movement";
74 $sql .= ", b.label_operation";
75 $sql .= ", b.montant as amount";
76 $sql .= ", b.code_journal";
77 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b";
78 $sql .= " WHERE b.fk_doc = 0";
79 $sql .= " AND b.entity = ".$conf->entity;
80 $sql .= " ORDER BY b.piece_num DESC ";
81 $sql .= $this->db->plimit($max, 0);
82
83 $result = $this->db->query($sql);
84 if ($result) {
85 $num = $this->db->num_rows($result);
86
87 $line = 0;
88
89 while ($line < $num) {
90 $objp = $this->db->fetch_object($result);
91 $date = $this->db->jdate($objp->date_movement);
92 $journal = $objp->code_journal;
93 $label = $objp->label_operation;
94 $amount = $objp->amount;
95
96 // adding id (rowid) will give two lines (debit and credit)
97 // so rowid isn't in sql request
98 // $bookkeepingstatic->id = $objp->id;
99 $bookkeepingstatic->piece_num = $objp->piece_num;
100
101 $this->info_box_contents[$line][] = array(
102 'td' => '',
103 'text' => $bookkeepingstatic->getNomUrl(1),
104 'asis' => 1,
105 );
106
107 $this->info_box_contents[$line][] = array(
108 'td' => 'class="center nowraponall"',
109 'text' => dol_print_date($date, 'day'),
110 'asis' => 1,
111 );
112
113 $this->info_box_contents[$line][] = array(
114 'td' => 'class="center"',
115 'text' => $journal,
116 'asis' => 1,
117 );
118
119 $this->info_box_contents[$line][] = array(
120 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
121 'text' => $label,
122 'asis' => 1,
123 );
124
125 $this->info_box_contents[$line][] = array(
126 'td' => 'class="nowraponall right amount"',
127 'text' => price($amount, 0, $langs, 0, -1, -1, $conf->currency),
128 );
129
130 $line++;
131 }
132
133 if ($num == 0) {
134 $this->info_box_contents[$line][0] = array(
135 'td' => 'class="center"',
136 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedManualEntries").'</span>'
137 );
138 }
139
140 $this->db->free($result);
141 } else {
142 $this->info_box_contents[0][0] = array(
143 'td' => '',
144 'maxlength'=>500,
145 'text' => ($this->db->error().' sql='.$sql),
146 );
147 }
148 } else {
149 $this->info_box_contents[0][0] = array(
150 'td' => 'class="nohover left"',
151 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
152 );
153 }
154 }
155
164 public function showBox($head = null, $contents = null, $nooutput = 0)
165 {
166 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
167 }
168}
Class to manage Ledger (General Ledger and Subledger)
Class ModeleBoxes.
Class to manage the box to show last manual entries.
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
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).