dolibarr 25.0.0-alpha
fichinterligne.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011-2020 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
7 * Copyright (C) 2015-2025 Charlene Benke <charlene@patas-monkey.com>
8 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
9 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2023-2024 William Mead <william.mead@manchenumerique.fr>
11 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
32require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
33
38{
42 public $db;
43
47 public $error = '';
48
52 public $fk_fichinter;
53
57 public $desc;
58
62 public $date;
67 public $datei;
68
72 public $duration;
73
77 public $special_code;
78
82 public $rang = 0;
83
87 public $tva_tx;
88
93 public $subprice;
94
98 public $element = 'fichinterdet';
99
103 public $table_element = 'fichinterdet';
104
108 public $fk_element = 'fk_fichinter';
109
110
111
117 public function __construct($db)
118 {
119 $this->db = $db;
120 }
121
128 public function fetch($rowid)
129 {
130 dol_syslog("FichinterLigne::fetch", LOG_DEBUG);
131
132 $sql = 'SELECT ft.rowid, ft.fk_fichinter, ft.description, ft.duree, ft.rang, ft.date, ft.product_type, ft.special_code, ft.extraparams';
133 $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
134 $sql .= ' WHERE ft.rowid = '.((int) $rowid);
135
136 $resql = $this->db->query($sql);
137 if ($resql) {
138 if ($this->db->num_rows($resql)) {
139 $objp = $this->db->fetch_object($resql);
140
141 $this->rowid = $objp->rowid;
142 $this->id = $objp->rowid;
143 $this->fk_fichinter = $objp->fk_fichinter;
144 $this->date = $this->db->jdate($objp->date);
145 $this->datei = $this->db->jdate($objp->date); // For backward compatibility
146 $this->desc = $objp->description;
147 $this->product_type = $objp->product_type;
148 $this->duration = $objp->duree;
149 $this->rang = $objp->rang;
150 $this->special_code = $objp->special_code;
151
152 $this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
153
154 $this->db->free($resql);
155
156 $this->fetch_optionals();
157
158 return 1;
159 }
160
161 return 0;
162 } else {
163 $this->error = $this->db->error().' sql='.$sql;
164 return -1;
165 }
166 }
167
175 public function insert($user, $notrigger = 0)
176 {
177 $error = 0;
178
179 dol_syslog("FichinterLigne::insert rang=".$this->rang);
180
181 if (empty($this->date) && !empty($this->datei)) { // For backward compatibility
182 $this->date = $this->datei;
183 }
184
185 // Check parameters
186 if ($this->product_type < 0) {
187 return -1;
188 }
189
190 $this->db->begin();
191
192 $rangToUse = $this->rang;
193 if ($rangToUse == -1) {
194 // Retrieve max rank of intervention line into $rangmax
195 $sql = 'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.'fichinterdet';
196 $sql .= ' WHERE fk_fichinter = '.((int) $this->fk_fichinter);
197 $resql = $this->db->query($sql);
198 if ($resql) {
199 $obj = $this->db->fetch_object($resql);
200 $rangToUse = (int) $obj->max + 1;
201 } else {
202 dol_print_error($this->db);
203 $this->db->rollback();
204 return -1;
205 }
206 }
207
208 // Insert line into database
209 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'fichinterdet';
210 $sql .= ' (fk_fichinter, description, date, duree, rang, product_type, special_code)';
211 $sql .= " VALUES (".((int) $this->fk_fichinter).",";
212 $sql .= " '".$this->db->escape($this->desc)."',";
213 $sql .= " '".$this->db->idate($this->date)."',";
214 $sql .= " ".((int) $this->duration).",";
215 $sql .= ' '.((int) $rangToUse).",";
216 $sql .= " ".((int) $this->product_type).",";
217 $sql .= " ".((int) $this->special_code);
218 $sql .= ')';
219
220 dol_syslog("FichinterLigne::insert", LOG_DEBUG);
221 $resql = $this->db->query($sql);
222 if ($resql) {
223 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'fichinterdet');
224 $this->rowid = $this->id;
225
226 $result = $this->insertExtraFields();
227 if ($result < 0) {
228 $error++;
229 }
230
231
232 $result = $this->update_total();
233
234 if ($result > 0) {
235 $this->rang = $rangToUse;
236
237 if (!$notrigger) {
238 // Call trigger
239 $result = $this->call_trigger('LINEFICHINTER_CREATE', $user);
240 if ($result < 0) {
241 $error++;
242 }
243 // End call triggers
244 }
245 }
246
247 if (!$error) {
248 $this->db->commit();
249 return $result;
250 } else {
251 $this->db->rollback();
252 return -1;
253 }
254 } else {
255 $this->error = $this->db->error()." sql=".$sql;
256 $this->db->rollback();
257 return -1;
258 }
259 }
260
261
269 public function update($user, $notrigger = 0)
270 {
271 $error = 0;
272
273 if (empty($this->date) && !empty($this->datei)) { // For backward compatibility
274 $this->date = $this->datei;
275 }
276
277 $this->db->begin();
278
279 // Update line in database
280 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinterdet SET";
281 $sql .= " description = '".$this->db->escape($this->desc)."',";
282 $sql .= " date = '".$this->db->idate($this->date)."',";
283 $sql .= " duree = ".((int) $this->duration).",";
284 $sql .= " rang = ".((int) $this->rang).",";
285 $sql .= " product_type = ".((int) $this->product_type);
286 $sql .= " WHERE rowid = ".((int) $this->id);
287
288 dol_syslog("FichinterLigne::update", LOG_DEBUG);
289 $resql = $this->db->query($sql);
290 if ($resql) {
291 $result = $this->insertExtraFields();
292 if ($result < 0) {
293 $error++;
294 }
295
296 $result = $this->update_total();
297 if ($result > 0) {
298 if (!$notrigger) {
299 // Call trigger
300 $result = $this->call_trigger('LINEFICHINTER_MODIFY', $user);
301 if ($result < 0) {
302 $error++;
303 }
304 // End call triggers
305 }
306 }
307
308 if (!$error) {
309 $this->db->commit();
310 return $result;
311 } else {
312 $this->error = $this->db->lasterror();
313 $this->db->rollback();
314 return -1;
315 }
316 } else {
317 $this->error = $this->db->lasterror();
318 $this->db->rollback();
319 return -1;
320 }
321 }
322
323 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
329 public function update_total()
330 {
331 // phpcs:enable
332 global $conf;
333
334 $this->db->begin();
335
336 $sql = "SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
337 $sql .= " FROM ".MAIN_DB_PREFIX."fichinterdet";
338 $sql .= " WHERE fk_fichinter=".((int) $this->fk_fichinter);
339 $sql .= " AND product_type <> 9";
340
341 dol_syslog("FichinterLigne::update_total", LOG_DEBUG);
342 $resql = $this->db->query($sql);
343 if ($resql) {
344 $obj = $this->db->fetch_object($resql);
345 $total_duration = 0;
346 if (!empty($obj->total_duration)) {
347 $total_duration = $obj->total_duration;
348 }
349
350 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
351 $sql .= " SET duree = ".((int) $total_duration);
352 $sql .= " , dateo = ".(!empty($obj->dateo) ? "'".$this->db->escape($obj->dateo)."'" : "null");
353 $sql .= " , datee = ".(!empty($obj->datee) ? "'".$this->db->escape($obj->datee)."'" : "null");
354 $sql .= " WHERE rowid = ".((int) $this->fk_fichinter);
355
356 dol_syslog("FichinterLigne::update_total", LOG_DEBUG);
357 $resql = $this->db->query($sql);
358 if ($resql) {
359 $this->db->commit();
360 return 1;
361 } else {
362 $this->error = $this->db->error();
363 $this->db->rollback();
364 return -2;
365 }
366 } else {
367 $this->error = $this->db->error();
368 $this->db->rollback();
369 return -1;
370 }
371 }
372
380 public function deleteLine($user, $notrigger = 0)
381 {
382 $error = 0;
383
384 dol_syslog(get_class($this)."::deleteline lineid=".$this->id);
385
386 $this->db->begin();
387
388 $result = $this->deleteExtraFields();
389 if ($result < 0) {
390 $error++;
391 $this->db->rollback();
392 return -1;
393 }
394
395 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet WHERE rowid = ".((int) $this->id);
396 $resql = $this->db->query($sql);
397
398 if ($resql) {
399 $result = $this->update_total();
400 if ($result > 0) {
401 if (!$notrigger) {
402 // Call trigger
403 $result = $this->call_trigger('LINEFICHINTER_DELETE', $user);
404 if ($result < 0) {
405 $error++;
406 $this->db->rollback();
407 return -1;
408 }
409 // End call triggers
410 }
411
412 $this->db->commit();
413 return $result;
414 } else {
415 $this->db->rollback();
416 return -1;
417 }
418 } else {
419 $this->error = $this->db->error()." sql=".$sql;
420 $this->db->rollback();
421 return -1;
422 }
423 }
424}
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage intervention lines.
deleteLine($user, $notrigger=0)
Delete a intervention line.
fetch($rowid)
Retrieve the line of intervention.
update_total()
Update total duration into llx_fichinter.
update($user, $notrigger=0)
Update intervention into database.
__construct($db)
Constructor.
insert($user, $notrigger=0)
Insert the line into database.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:487