dolibarr 24.0.0-beta
bookkeepingtemplateline.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024 AWeerWolf
3 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
4 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Put here all includes required by your class file
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28
33{
37 public $module = 'accountancy';
38
42 public $element = 'accounting_transaction_template_det';
43
47 public $table_element = 'accounting_transaction_template_det';
48
52 public $ismultientitymanaged = 0;
53
57 public $isextrafieldmanaged = 0;
58
62 public $picto = 'fa-file';
63
89 // BEGIN MODULEBUILDER PROPERTIES
93 public $fields = array(
94 "rowid" => array("type" => "integer", "label" => "TechnicalID", "enabled" => 1, 'position' => 1, 'notnull' => 1, "visible" => 0, "noteditable" => 1, "index" => 1, "css" => "left", "comment" => "Id"),
95 "fk_transaction_template" => array("type" => "integer", "label" => "Template", "enabled" => 1, 'position' => 5, 'notnull' => 1, "visible" => 0, "noteditable" => 1, "foreignkey" => "accounting_transaction_template.rowid"),
96 "general_account" => array("type" => "varchar(32)", "label" => "AccountNumber", "enabled" => 1, 'position' => 10, 'notnull' => 1, "visible" => 1, "css" => "minwidth100"),
97 "general_label" => array("type" => "varchar(255)", "label" => "AccountLabel", "enabled" => 1, 'position' => 20, 'notnull' => 1, "visible" => 1, "css" => "minwidth200"),
98 "subledger_account" => array("type" => "varchar(32)", "label" => "SubledgerAccount", "enabled" => 1, 'position' => 30, 'notnull' => 0, "visible" => 1, "css" => "minwidth100"),
99 "subledger_label" => array("type" => "varchar(255)", "label" => "SubledgerLabel", "enabled" => 1, 'position' => 40, 'notnull' => 0, "visible" => 1, "css" => "minwidth200"),
100 "operation_label" => array("type" => "varchar(255)", "label" => "OperationLabel", "enabled" => 1, 'position' => 50, 'notnull' => 0, "visible" => 1, "css" => "minwidth200"),
101 "debit" => array("type" => "double(24,8)", "label" => "Debit", "enabled" => 1, 'position' => 60, 'notnull' => 0, "visible" => 1, "css" => "maxwidth75 right"),
102 "credit" => array("type" => "double(24,8)", "label" => "Credit", "enabled" => 1, 'position' => 70, 'notnull' => 0, "visible" => 1, "css" => "maxwidth75 right"),
103 );
104 // END MODULEBUILDER PROPERTIES
105
109 public $rowid;
110
114 public $fk_transaction_template;
115
119 public $general_account;
120
124 public $general_label;
125
129 public $subledger_account;
130
134 public $subledger_label;
135
139 public $operation_label;
140
144 public $debit;
145
149 public $credit;
150
154 public $sens;
155
159 public $position;
160
164 public $date_creation;
165
169 public $tms;
170
174 public $fk_user_creat;
175
179 public $fk_user_modif;
180
181
187 public function __construct(DoliDB $db)
188 {
189 global $conf, $langs;
190
191 $this->db = $db;
192
193 if (!getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
194 $this->fields['rowid']['visible'] = 0;
195 }
196
197 // Unset fields that are disabled
198 foreach ($this->fields as $key => $val) {
199 if (isset($val['enabled']) && empty($val['enabled'])) {
200 unset($this->fields[$key]);
201 }
202 }
203
204 // Translate some data of arrayofkeyval
205 if (is_object($langs)) {
206 foreach ($this->fields as $key => $val) {
207 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
208 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
209 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
210 }
211 }
212 }
213 }
214 }
215
223 public function create(User $user, $notrigger = 0)
224 {
225 $resultcreate = $this->createCommon($user, $notrigger);
226 return $resultcreate;
227 }
228
236 public function fetch($id, $noextrafields = 0)
237 {
238 $result = $this->fetchCommon($id, '', '', $noextrafields);
239 return $result;
240 }
241
253 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
254 {
255 dol_syslog(__METHOD__, LOG_DEBUG);
256
257 $records = array();
258
259 $sql = "SELECT ";
260 $sql .= $this->getFieldList('t');
261 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
262 if (isset($this->isextrafieldmanaged) && $this->isextrafieldmanaged == 1) {
263 $sql .= " LEFT JOIN ".$this->db->prefix().$this->table_element."_extrafields as te ON te.fk_object = t.rowid";
264 }
265 $sql .= " WHERE 1 = 1";
266
267 // Manage filter
268 $sqlwhere = array();
269 if (count($filter) > 0) {
270 foreach ($filter as $key => $value) {
271 if ($key === 'customsql') {
272 // Never use 'customsql' with a value from user input since it is injected as is. The value must be hard coded.
273 $sqlwhere[] = $value;
274 continue;
275 }
276
277 $columnName = preg_replace('/^t\./', '', $key);
278
279 if (isset($this->fields[$columnName])) {
280 $type = $this->fields[$columnName]['type'];
281 if (preg_match('/^integer/', $type)) {
282 if (is_int($value)) {
283 // single value
284 $sqlwhere[] = $key . " = " . intval($value);
285 } elseif (is_array($value)) {
286 if (empty($value)) {
287 continue;
288 }
289 $sqlwhere[] = $key . ' IN (' . $this->db->sanitize(implode(',', array_map('intval', $value))) . ')';
290 }
291 continue;
292 } elseif (in_array($type, array('date', 'datetime', 'timestamp'))) {
293 $sqlwhere[] = $key . " = '" . $this->db->idate($value) . "'";
294 continue;
295 }
296 }
297
298 // when the $key doesn't fall into the previously handled categories, we do as if the column were a varchar/text
299 if (is_array($value) && count($value)) {
300 $escapedValues = array();
301 foreach ($value as $v) {
302 $escapedValues[] = $this->db->escape($v);
303 }
304 $value = implode(',', $escapedValues);
305 $sqlwhere[] = $key . ' IN (' . $this->db->sanitize($value, 1) . ')';
306 } elseif (is_scalar($value)) {
307 if (strpos($value, '%') === false) {
308 $sqlwhere[] = $key . " = '" . $this->db->sanitize($this->db->escape($value)) . "'";
309 } else {
310 $sqlwhere[] = $key . " LIKE '%" . $this->db->escape($this->db->escapeforlike($value)) . "%'";
311 }
312 }
313 }
314 }
315 if (count($sqlwhere) > 0) {
316 $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
317 }
318
319 if (!empty($sortfield)) {
320 $sql .= $this->db->order($sortfield, $sortorder);
321 }
322 if (!empty($limit)) {
323 $sql .= $this->db->plimit($limit, $offset);
324 }
325
326 $resql = $this->db->query($sql);
327 if ($resql) {
328 $num = $this->db->num_rows($resql);
329 $i = 0;
330 while ($i < ($limit ? min($limit, $num) : $num)) {
331 $obj = $this->db->fetch_object($resql);
332
333 $record = new self($this->db);
334 $record->setVarsFromFetchObj($obj);
335
336 $records[$record->id] = $record;
337
338 $i++;
339 }
340 $this->db->free($resql);
341
342 return $records;
343 } else {
344 $this->errors[] = 'Error '.$this->db->lasterror();
345 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
346
347 return -1;
348 }
349 }
350
358 public function update(User $user, $notrigger = 0)
359 {
360 return $this->updateCommon($user, $notrigger);
361 }
362
370 public function delete(User $user, $notrigger = 0)
371 {
372 return $this->deleteCommon($user, $notrigger);
373 }
374}
Class for BookkeepingTemplateLine.
update(User $user, $notrigger=0)
Update object into database.
create(User $user, $notrigger=0)
Create object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
fetch($id, $noextrafields=0)
Load object in memory from the database.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.