dolibarr 23.0.3
fournisseur.facture-rec.ligne.class.php
1<?php
2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2017-2024 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2023-2024 Nick Fragoulis
12 * Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
34require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.ligne.class.php';
35
41{
45 public $element = 'invoice_supplier_det_rec';
46
50 public $table_element = 'facture_fourn_det_rec';
51
55 public $fk_facture_fourn;
56
60 public $fk_parent;
61
65 public $fk_product;
66
70 public $ref_supplier;
71
75 public $label;
80 public $description;
81
86 public $pu_ht;
87
92 public $pu_ttc;
93
97 public $qty;
98
102 public $remise_percent;
103
107 public $fk_remise_except;
108
112 public $vat_src_code;
113
117 public $tva_tx;
118
122 public $localtax1_tx;
123
127 public $localtax1_type;
128
132 public $localtax2_tx;
133
137 public $localtax2_type;
138
142 public $product_type;
143
147 public $date_start;
148
152 public $date_end;
153
157 public $info_bits;
158
162 public $special_code;
163
167 public $rang;
168
172 public $fk_user_author;
173
177 public $fk_user_modif;
178
182 public $skip_update_total;
183
184
192 public function delete(User $user, $notrigger = 0)
193 {
194 $error = 0;
195 $this->db->begin();
196
197 if (! $error) {
198 if (! $notrigger) {
199 // Call triggers
200 $result = $this->call_trigger('LINESUPPLIERBILLREC_DELETE', $user);
201 if ($result < 0) {
202 $error++;
203 } // Do also here what you must do to rollback action if trigger fail
204 // End call triggers
205 }
206 }
207
208 if (! $error) {
209 $result = $this->deleteExtraFields();
210 if ($result < 0) {
211 $error++;
212 }
213 }
214
215 if (! $error) {
216 $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element . ' WHERE rowid=' . (int) $this->id;
217
218 $res = $this->db->query($sql);
219 if ($res === false) {
220 $error++;
221 $this->errors[] = $this->db->lasterror();
222 }
223 }
224
225 // Commit or rollback
226 if ($error) {
227 $this->db->rollback();
228 return -1;
229 } else {
230 $this->db->commit();
231 return 1;
232 }
233 }
234
235
242 public function fetch($rowid)
243 {
244 $sql = 'SELECT l.rowid,';
245 $sql .= ' l.fk_facture_fourn, l.fk_parent_line, l.fk_product,';
246 $sql .= ' l.ref as ref_supplier, l.label, l.description as line_desc, l.pu_ht, l.pu_ttc, l.qty, l.remise_percent, l.fk_remise_except,';
247 $sql .= ' l.vat_src_code, l.tva_tx, l.localtax1_tx, l.localtax1_type, l.localtax2_tx, l.localtax2_type,';
248 $sql .= ' l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc,';
249 $sql .= ' l.product_type, l.date_start, l.date_end,';
250 $sql .= ' l.info_bits, l.special_code, l.rang, l.fk_unit, l.import_key, l.extraparams,';
251 $sql .= ' l.fk_user_author, l.fk_user_modif, l.fk_multicurrency,';
252 $sql .= ' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
253 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
254 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det_rec as l';
255 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
256 $sql .= ' WHERE l.rowid = '. (int) $rowid;
257 $sql .= ' ORDER BY l.rang';
258
259 dol_syslog('FactureRec::fetch', LOG_DEBUG);
260 $result = $this->db->query($sql);
261 if ($result) {
262 $objp = $this->db->fetch_object($result);
263
264 $this->id = $objp->rowid;
265 $this->fk_facture_fourn = $objp->fk_facture_fourn;
266 $this->fk_parent = $objp->fk_parent_line;
267 $this->fk_product = $objp->fk_product;
268 $this->ref_supplier = $objp->ref_supplier;
269 $this->label = $objp->label;
270 $this->description = $objp->line_desc;
271 $this->desc = $objp->line_desc;
272 $this->pu_ht = $objp->pu_ht;
273 $this->pu_ttc = $objp->pu_ttc;
274 $this->qty = $objp->qty;
275 $this->remise_percent = $objp->remise_percent;
276 $this->fk_remise_except = $objp->fk_remise_except;
277 $this->vat_src_code = $objp->vat_src_code;
278 $this->tva_tx = $objp->tva_tx;
279 $this->localtax1_tx = $objp->localtax1_tx;
280 $this->localtax1_type = $objp->localtax1_type;
281 $this->localtax2_tx = $objp->localtax2_tx;
282 $this->localtax2_type = $objp->localtax2_type;
283 $this->total_ht = $objp->total_ht;
284 $this->total_tva = $objp->total_tva;
285 $this->total_localtax1 = $objp->total_localtax1;
286 $this->total_localtax2 = $objp->total_localtax2;
287 $this->total_ttc = $objp->total_ttc;
288 $this->product_type = $objp->product_type;
289 $this->product_label = $objp->product_label;
290 $this->date_start = $objp->date_start;
291 $this->date_end = $objp->date_end;
292 $this->info_bits = $objp->info_bits;
293 $this->special_code = $objp->special_code;
294 $this->rang = $objp->rang;
295 $this->fk_unit = $objp->fk_unit;
296 $this->import_key = $objp->import_key;
297 $this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
298 $this->fk_user_author = $objp->fk_user_author;
299 $this->fk_user_modif = $objp->fk_user_modif;
300 $this->fk_multicurrency = $objp->fk_multicurrency;
301 $this->multicurrency_code = $objp->multicurrency_code;
302 $this->multicurrency_subprice = $objp->multicurrency_subprice;
303 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
304 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
305 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
306
307 $this->db->free($result);
308 return 1;
309 } else {
310 $this->error = $this->db->lasterror();
311 return -3;
312 }
313 }
314
315
323 public function update(User $user, $notrigger = 0)
324 {
325 global $conf;
326
327 $error = 0;
328
329 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
330
331 $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture_fourn_det_rec SET';
332 $sql .= ' fk_facture_fourn = ' . (int) $this->fk_facture_fourn;
333 $sql .= ', fk_parent_line = ' . (int) $this->fk_parent;
334 $sql .= ', fk_product = ' . (int) $this->fk_product;
335 $sql .= ', ref = ' . (!empty($this->ref) ? "'" . $this->db->escape($this->ref) . "'" : 'NULL');
336 $sql .= ", label = " . (!empty($this->label) ? "'" . $this->db->escape($this->label) . "'" : 'NULL');
337 $sql .= ", description = '" . $this->db->escape($this->desc ? $this->desc : $this->description) . "'";
338 $sql .= ', pu_ht = ' . price2num($this->pu_ht);
339 $sql .= ', pu_ttc = ' . price2num($this->pu_ttc);
340 $sql .= ', qty = ' . price2num($this->qty);
341 $sql .= ", remise_percent = '" . price2num($this->remise_percent) . "'";
342 $sql .= ', fk_remise_except = ' . (int) $this->fk_remise_except;
343 $sql .= ", vat_src_code = '" . $this->db->escape($this->vat_src_code) . "'";
344 $sql .= ', tva_tx = ' . price2num($this->tva_tx);
345 $sql .= ', localtax1_tx = ' . price2num($this->localtax1_tx);
346 $sql .= ", localtax1_type = '" . $this->db->escape((string) $this->localtax1_type) . "'";
347 $sql .= ', localtax2_tx = ' . price2num($this->localtax2_tx);
348 $sql .= ", localtax2_type = '" . $this->db->escape((string) $this->localtax2_type) . "'";
349 if (empty($this->skip_update_total)) {
350 $sql .= ', total_ht = ' . price2num($this->total_ht);
351 $sql .= ', total_tva = ' . price2num($this->total_tva);
352 $sql .= ', total_localtax1 = ' . price2num($this->total_localtax1);
353 $sql .= ', total_localtax2 = ' . price2num($this->total_localtax2);
354 $sql .= ', total_ttc = ' . price2num($this->total_ttc);
355 }
356 $sql .= ', product_type = ' . (int) $this->product_type;
357 $sql .= ', date_start = ' . (int) $this->date_start;
358 $sql .= ', date_end = ' . (int) $this->date_end;
359 $sql .= ", info_bits = " . ((int) $this->info_bits);
360 $sql .= ', special_code =' . (int) $this->special_code;
361 $sql .= ', rang = ' . (int) $this->rang;
362 $sql .= ', fk_unit = ' .($this->fk_unit ? "'".$this->db->escape((string) $this->fk_unit)."'" : 'null');
363 $sql .= ', fk_user_modif = ' . (int) $user->id;
364 $sql .= ' WHERE rowid = ' . (int) $this->id;
365
366 $this->db->begin();
367
368 dol_syslog(get_class($this). '::updateline', LOG_DEBUG);
369 $resql = $this->db->query($sql);
370 if ($resql) {
371 if (!$error) {
372 $result = $this->insertExtraFields();
373 if ($result < 0) {
374 $error++;
375 }
376 }
377
378 if (!$error && !$notrigger) {
379 // Call trigger
380 $result = $this->call_trigger('LINESUPPLIERBILLREC_MODIFY', $user);
381 if ($result < 0) {
382 $error++;
383 }
384 // End call triggers
385 }
386
387 if ($error) {
388 $this->db->rollback();
389 return -2;
390 } else {
391 $this->db->commit();
392 return 1;
393 }
394 } else {
395 $this->error = $this->db->lasterror();
396 $this->db->rollback();
397 return -2;
398 }
399 }
400}
$object ref
Definition info.php:90
Parent class of all other business classes for details of elements (invoices, contracts,...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage supplier invoice lines of templates.
fetch($rowid)
Get line of template invoice.
update(User $user, $notrigger=0)
Update a line to supplier invoice template .
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.