dolibarr  13.0.2
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 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 
29 
34 {
35  public $boxcode = "accountancy_last_manual_entries";
36  public $boximg = "object_invoice";
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->rights->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->rights->accounting->mouvements->lire)
83  {
84  $sql = "SELECT DISTINCT b.piece_num";
85  $sql .= ", b.doc_date as date_movement";
86  $sql .= ", b.label_operation";
87  $sql .= ", b.montant as amount";
88  $sql .= ", b.code_journal";
89  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b";
90  $sql .= " WHERE b.fk_doc = 0";
91  $sql .= " AND b.entity = ".$conf->entity;
92  $sql .= " ORDER BY b.piece_num DESC ";
93  $sql .= $this->db->plimit($max, 0);
94 
95  $result = $this->db->query($sql);
96  if ($result) {
97  $num = $this->db->num_rows($result);
98 
99  $line = 0;
100 
101  while ($line < $num) {
102  $objp = $this->db->fetch_object($result);
103  $date = $this->db->jdate($objp->date_movement);
104  $journal = $objp->code_journal;
105  $label = $objp->label_operation;
106  $amount = $objp->amount;
107 
108  $bookkeepingstatic->id = $objp->id;
109  $bookkeepingstatic->piece_num = $objp->piece_num;
110 
111  $this->info_box_contents[$line][] = array(
112  'td' => '',
113  'text' => $bookkeepingstatic->getNomUrl(1),
114  'asis' => 1,
115  );
116 
117  $this->info_box_contents[$line][] = array(
118  'td' => 'class="right"',
119  'text' => dol_print_date($date, 'day'),
120  'asis' => 1,
121  );
122 
123  $this->info_box_contents[$line][] = array(
124  'td' => 'class="center"',
125  'text' => $journal,
126  'asis' => 1,
127  );
128 
129  $this->info_box_contents[$line][] = array(
130  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
131  'text' => $label,
132  'asis' => 1,
133  );
134 
135  $this->info_box_contents[$line][] = array(
136  'td' => 'class="nowraponall right"',
137  'text' => price($amount, 0, $langs, 0, -1, -1, $conf->currency),
138  );
139 
140  $line++;
141  }
142 
143  if ($num == 0) $this->info_box_contents[$line][0] = array(
144  'td' => 'class="center"',
145  'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedManualEntries").'</span>'
146  );
147 
148  $this->db->free($result);
149  } else {
150  $this->info_box_contents[0][0] = array(
151  'td' => '',
152  'maxlength'=>500,
153  'text' => ($this->db->error().' sql='.$sql),
154  );
155  }
156  } else {
157  $this->info_box_contents[0][0] = array(
158  'td' => 'class="nohover left"',
159  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
160  );
161  }
162  }
163 
172  public function showBox($head = null, $contents = null, $nooutput = 0)
173  {
174  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
175  }
176 }
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
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...
Class to manage Ledger (General Ledger and Subledger)
Class to manage the box to show last manual entries.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).