dolibarr 21.0.0-beta
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 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
85 public $pu_ht;
86
90 public $pu_ttc;
91
95 public $qty;
96
100 public $remise_percent;
101
105 public $fk_remise_except;
106
110 public $vat_src_code;
111
115 public $tva_tx;
116
120 public $localtax1_tx;
121
125 public $localtax1_type;
126
130 public $localtax2_tx;
131
135 public $localtax2_type;
136
140 public $product_type;
141
145 public $date_start;
146
150 public $date_end;
151
155 public $info_bits;
156
160 public $special_code;
161
165 public $rang;
166
170 public $fk_user_author;
171
175 public $fk_user_modif;
176
180 public $skip_update_total;
181
182
190 public function delete(User $user, $notrigger = 0)
191 {
192 $error = 0;
193 $this->db->begin();
194
195 if (! $error) {
196 if (! $notrigger) {
197 // Call triggers
198 $result = $this->call_trigger('LINESUPPLIERBILLREC_DELETE', $user);
199 if ($result < 0) {
200 $error++;
201 } // Do also here what you must do to rollback action if trigger fail
202 // End call triggers
203 }
204 }
205
206 if (! $error) {
207 $result = $this->deleteExtraFields();
208 if ($result < 0) {
209 $error++;
210 }
211 }
212
213 if (! $error) {
214 $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element . ' WHERE rowid=' . (int) $this->id;
215
216 $res = $this->db->query($sql);
217 if ($res === false) {
218 $error++;
219 $this->errors[] = $this->db->lasterror();
220 }
221 }
222
223 // Commit or rollback
224 if ($error) {
225 $this->db->rollback();
226 return -1;
227 } else {
228 $this->db->commit();
229 return 1;
230 }
231 }
232
233
240 public function fetch($rowid)
241 {
242 $sql = 'SELECT l.rowid,';
243 $sql .= ' l.fk_facture_fourn, l.fk_parent_line, l.fk_product,';
244 $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,';
245 $sql .= ' l.vat_src_code, l.tva_tx, l.localtax1_tx, l.localtax1_type, l.localtax2_tx, l.localtax2_type,';
246 $sql .= ' l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc,';
247 $sql .= ' l.product_type, l.date_start, l.date_end,';
248 $sql .= ' l.info_bits, l.special_code, l.rang, l.fk_unit, l.import_key,';
249 $sql .= ' l.fk_user_author, l.fk_user_modif, l.fk_multicurrency,';
250 $sql .= ' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
251 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
252 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det_rec as l';
253 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
254 $sql .= ' WHERE l.rowid = '. (int) $rowid;
255 $sql .= ' ORDER BY l.rang';
256
257 dol_syslog('FactureRec::fetch', LOG_DEBUG);
258 $result = $this->db->query($sql);
259 if ($result) {
260 $objp = $this->db->fetch_object($result);
261
262 $this->id = $objp->rowid;
263 $this->fk_facture_fourn = $objp->fk_facture_fourn;
264 $this->fk_parent = $objp->fk_parent_line;
265 $this->fk_product = $objp->fk_product;
266 $this->ref_supplier = $objp->ref_supplier;
267 $this->label = $objp->label;
268 $this->description = $objp->line_desc;
269 $this->desc = $objp->line_desc;
270 $this->pu_ht = $objp->pu_ht;
271 $this->pu_ttc = $objp->pu_ttc;
272 $this->qty = $objp->qty;
273 $this->remise_percent = $objp->remise_percent;
274 $this->fk_remise_except = $objp->fk_remise_except;
275 $this->vat_src_code = $objp->vat_src_code;
276 $this->tva_tx = $objp->tva_tx;
277 $this->localtax1_tx = $objp->localtax1_tx;
278 $this->localtax1_type = $objp->localtax1_type;
279 $this->localtax2_tx = $objp->localtax2_tx;
280 $this->localtax2_type = $objp->localtax2_type;
281 $this->total_ht = $objp->total_ht;
282 $this->total_tva = $objp->total_tva;
283 $this->total_localtax1 = $objp->total_localtax1;
284 $this->total_localtax2 = $objp->total_localtax2;
285 $this->total_ttc = $objp->total_ttc;
286 $this->product_type = $objp->product_type;
287 $this->date_start = $objp->date_start;
288 $this->date_end = $objp->date_end;
289 $this->info_bits = $objp->info_bits;
290 $this->special_code = $objp->special_code;
291 $this->rang = $objp->rang;
292 $this->fk_unit = $objp->fk_unit;
293 $this->import_key = $objp->import_key;
294 $this->fk_user_author = $objp->fk_user_author;
295 $this->fk_user_modif = $objp->fk_user_modif;
296 $this->fk_multicurrency = $objp->fk_multicurrency;
297 $this->multicurrency_code = $objp->multicurrency_code;
298 $this->multicurrency_subprice = $objp->multicurrency_subprice;
299 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
300 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
301 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
302
303 $this->db->free($result);
304 return 1;
305 } else {
306 $this->error = $this->db->lasterror();
307 return -3;
308 }
309 }
310
311
319 public function update(User $user, $notrigger = 0)
320 {
321 global $conf;
322
323 $error = 0;
324
325 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
326
327 $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture_fourn_det_rec SET';
328 $sql .= ' fk_facture_fourn = ' . (int) $this->fk_facture_fourn;
329 $sql .= ', fk_parent_line = ' . (int) $this->fk_parent;
330 $sql .= ', fk_product = ' . (int) $this->fk_product;
331 $sql .= ', ref = ' . (!empty($this->ref) ? "'" . $this->db->escape($this->ref) . "'" : 'NULL');
332 $sql .= ", label = " . (!empty($this->label) ? "'" . $this->db->escape($this->label) . "'" : 'NULL');
333 $sql .= ", description = '" . $this->db->escape($this->desc ? $this->desc : $this->description) . "'";
334 $sql .= ', pu_ht = ' . price2num($this->pu_ht);
335 $sql .= ', pu_ttc = ' . price2num($this->pu_ttc);
336 $sql .= ', qty = ' . price2num($this->qty);
337 $sql .= ", remise_percent = '" . price2num($this->remise_percent) . "'";
338 $sql .= ', fk_remise_except = ' . (int) $this->fk_remise_except;
339 $sql .= ", vat_src_code = '" . $this->db->escape($this->vat_src_code) . "'";
340 $sql .= ', tva_tx = ' . price2num($this->tva_tx);
341 $sql .= ', localtax1_tx = ' . price2num($this->localtax1_tx);
342 $sql .= ", localtax1_type = '" . $this->db->escape($this->localtax1_type) . "'";
343 $sql .= ', localtax2_tx = ' . price2num($this->localtax2_tx);
344 $sql .= ", localtax2_type = '" . $this->db->escape($this->localtax2_type) . "'";
345 if (empty($this->skip_update_total)) {
346 $sql .= ', total_ht = ' . price2num($this->total_ht);
347 $sql .= ', total_tva = ' . price2num($this->total_tva);
348 $sql .= ', total_localtax1 = ' . price2num($this->total_localtax1);
349 $sql .= ', total_localtax2 = ' . price2num($this->total_localtax2);
350 $sql .= ', total_ttc = ' . price2num($this->total_ttc);
351 }
352 $sql .= ', product_type = ' . (int) $this->product_type;
353 $sql .= ', date_start = ' . (int) $this->date_start;
354 $sql .= ', date_end = ' . (int) $this->date_end;
355 $sql .= ", info_bits = " . ((int) $this->info_bits);
356 $sql .= ', special_code =' . (int) $this->special_code;
357 $sql .= ', rang = ' . (int) $this->rang;
358 $sql .= ', fk_unit = ' .($this->fk_unit ? "'".$this->db->escape($this->fk_unit)."'" : 'null');
359 $sql .= ', fk_user_modif = ' . (int) $user->id;
360 $sql .= ' WHERE rowid = ' . (int) $this->id;
361
362 $this->db->begin();
363
364 dol_syslog(get_class($this). '::updateline', LOG_DEBUG);
365 $resql = $this->db->query($sql);
366 if ($resql) {
367 if (!$error) {
368 $result = $this->insertExtraFields();
369 if ($result < 0) {
370 $error++;
371 }
372 }
373
374 if (!$error && !$notrigger) {
375 // Call trigger
376 $result = $this->call_trigger('LINESUPPLIERBILLREC_MODIFY', $user);
377 if ($result < 0) {
378 $error++;
379 }
380 // End call triggers
381 }
382
383 if ($error) {
384 $this->db->rollback();
385 return -2;
386 } else {
387 $this->db->commit();
388 return 1;
389 }
390 } else {
391 $this->error = $this->db->lasterror();
392 $this->db->rollback();
393 return -2;
394 }
395 }
396}
$object ref
Definition info.php:89
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79