dolibarr 18.0.6
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 = "accounting";
37 public $boxlabel = "BoxLastManualEntries";
38 public $depends = array("accounting");
39
43 public $db;
44
45 public $param;
46
47 public $info_box_head = array();
48 public $info_box_contents = array();
49
50
57 public function __construct($db, $param)
58 {
59 global $user;
60
61 $this->db = $db;
62
63 $this->hidden = !$user->hasRight('accounting', 'mouvements', 'lire');
64 }
65
72 public function loadBox($max = 5)
73 {
74 global $user, $langs, $conf;
75
76 include_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
77
78 $bookkeepingstatic = new BookKeeping($this->db);
79
80 $this->info_box_head = array('text' => $langs->trans("BoxTitleLastManualEntries", $max));
81
82 if ($user->hasRight('accounting', 'mouvements', 'lire')) {
83 $sql = "SELECT DISTINCT b.piece_num";
84 $sql .= ", b.doc_date as date_movement";
85 $sql .= ", b.label_operation";
86 $sql .= ", b.montant as amount";
87 $sql .= ", b.code_journal";
88 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b";
89 $sql .= " WHERE b.fk_doc = 0";
90 $sql .= " AND b.entity = ".$conf->entity;
91 $sql .= " ORDER BY b.piece_num DESC ";
92 $sql .= $this->db->plimit($max, 0);
93
94 $result = $this->db->query($sql);
95 if ($result) {
96 $num = $this->db->num_rows($result);
97
98 $line = 0;
99
100 while ($line < $num) {
101 $objp = $this->db->fetch_object($result);
102 $date = $this->db->jdate($objp->date_movement);
103 $journal = $objp->code_journal;
104 $label = $objp->label_operation;
105 $amount = $objp->amount;
106
107 // adding id (rowid) will give two lines (debit and credit)
108 // so rowid isn't in sql request
109 // $bookkeepingstatic->id = $objp->id;
110 $bookkeepingstatic->piece_num = $objp->piece_num;
111
112 $this->info_box_contents[$line][] = array(
113 'td' => '',
114 'text' => $bookkeepingstatic->getNomUrl(1),
115 'asis' => 1,
116 );
117
118 $this->info_box_contents[$line][] = array(
119 'td' => 'class="center nowraponall"',
120 'text' => dol_print_date($date, 'day'),
121 'asis' => 1,
122 );
123
124 $this->info_box_contents[$line][] = array(
125 'td' => 'class="center"',
126 'text' => $journal,
127 'asis' => 1,
128 );
129
130 $this->info_box_contents[$line][] = array(
131 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
132 'text' => $label,
133 'asis' => 1,
134 );
135
136 $this->info_box_contents[$line][] = array(
137 'td' => 'class="nowraponall right amount"',
138 'text' => price($amount, 0, $langs, 0, -1, -1, $conf->currency),
139 );
140
141 $line++;
142 }
143
144 if ($num == 0) {
145 $this->info_box_contents[$line][0] = array(
146 'td' => 'class="center"',
147 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedManualEntries").'</span>'
148 );
149 }
150
151 $this->db->free($result);
152 } else {
153 $this->info_box_contents[0][0] = array(
154 'td' => '',
155 'maxlength'=>500,
156 'text' => ($this->db->error().' sql='.$sql),
157 );
158 }
159 } else {
160 $this->info_box_contents[0][0] = array(
161 'td' => 'class="nohover left"',
162 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
163 );
164 }
165 }
166
175 public function showBox($head = null, $contents = null, $nooutput = 0)
176 {
177 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
178 }
179}
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='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).