dolibarr 21.0.0-alpha
orderline.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
6 * Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2011 Jean Heimburger <jean@tiaris.info>
8 * Copyright (C) 2012-2014 Christophe Battarel <christophe.battarel@altairis.fr>
9 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
10 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
11 * Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
12 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
13 * Copyright (C) 2016-2022 Ferran Marcet <fmarcet@2byte.es>
14 * Copyright (C) 2021-2024 Frédéric France <frederic.france@free.fr>
15 * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
16 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
17 * Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 */
32
39require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
40require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
41
46{
50 public $element = 'commandedet';
51
55 public $table_element = 'commandedet';
56
60 public $oldline;
61
66 public $fk_commande;
67
74 public $commande_id;
75
79 public $fk_parent_line;
80
84 public $fk_facture;
85
89 public $ref_ext;
90
94 public $fk_remise_except;
95
99 public $rang = 0;
100
104 public $fk_fournprice;
105
110 public $pa_ht;
111
115 public $marge_tx;
116
120 public $marque_tx;
121
127 public $remise;
128
133 public $date_start;
134
139 public $date_end;
140
145 public $skip_update_total;
146
147
153 public function __construct($db)
154 {
155 $this->db = $db;
156 }
157
164 public function fetch($rowid)
165 {
166 $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_parent_line, cd.fk_product, cd.product_type, cd.label as custom_label, cd.description, cd.price, cd.qty, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx,';
167 $sql .= ' cd.remise, cd.remise_percent, cd.fk_remise_except, cd.subprice, cd.ref_ext,';
168 $sql .= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht, cd.rang, cd.special_code,';
169 $sql .= ' cd.fk_unit,';
170 $sql .= ' cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
171 $sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc, p.tobatch as product_tobatch,';
172 $sql .= ' cd.date_start, cd.date_end, cd.vat_src_code';
173 $sql .= ' FROM '.MAIN_DB_PREFIX.'commandedet as cd';
174 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid';
175 $sql .= ' WHERE cd.rowid = '.((int) $rowid);
176 $result = $this->db->query($sql);
177 if ($result) {
178 $objp = $this->db->fetch_object($result);
179
180 if (!$objp) {
181 $this->error = 'OrderLine with id '. $rowid .' not found sql='.$sql;
182 return 0;
183 }
184
185 $this->rowid = $objp->rowid;
186 $this->id = $objp->rowid;
187 $this->fk_commande = $objp->fk_commande;
188 $this->fk_parent_line = $objp->fk_parent_line;
189 $this->label = $objp->custom_label;
190 $this->desc = $objp->description;
191 $this->qty = $objp->qty;
192 $this->price = $objp->price;
193 $this->subprice = $objp->subprice;
194 $this->ref_ext = $objp->ref_ext;
195 $this->vat_src_code = $objp->vat_src_code;
196 $this->tva_tx = $objp->tva_tx;
197 $this->localtax1_tx = $objp->localtax1_tx;
198 $this->localtax2_tx = $objp->localtax2_tx;
199 $this->remise = $objp->remise;
200 $this->remise_percent = $objp->remise_percent;
201 $this->fk_remise_except = $objp->fk_remise_except;
202 $this->fk_product = $objp->fk_product;
203 $this->product_type = $objp->product_type;
204 $this->info_bits = $objp->info_bits;
205 $this->special_code = $objp->special_code;
206 $this->total_ht = $objp->total_ht;
207 $this->total_tva = $objp->total_tva;
208 $this->total_localtax1 = $objp->total_localtax1;
209 $this->total_localtax2 = $objp->total_localtax2;
210 $this->total_ttc = $objp->total_ttc;
211 $this->fk_fournprice = $objp->fk_fournprice;
212 $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
213 $this->pa_ht = $marginInfos[0];
214 $this->marge_tx = $marginInfos[1];
215 $this->marque_tx = $marginInfos[2];
216 $this->special_code = $objp->special_code;
217 $this->rang = $objp->rang;
218
219 $this->ref = $objp->product_ref; // deprecated
220
221 $this->product_ref = $objp->product_ref;
222 $this->product_label = $objp->product_label;
223 $this->product_desc = $objp->product_desc;
224 $this->product_tobatch = $objp->product_tobatch;
225 $this->fk_unit = $objp->fk_unit;
226
227 $this->date_start = $this->db->jdate($objp->date_start);
228 $this->date_end = $this->db->jdate($objp->date_end);
229
230 $this->fk_multicurrency = $objp->fk_multicurrency;
231 $this->multicurrency_code = $objp->multicurrency_code;
232 $this->multicurrency_subprice = $objp->multicurrency_subprice;
233 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
234 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
235 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
236
237 $this->fetch_optionals();
238
239 $this->db->free($result);
240
241 return 1;
242 } else {
243 $this->error = $this->db->lasterror();
244 return -1;
245 }
246 }
247
255 public function delete(User $user, $notrigger = 0)
256 {
257 global $conf, $langs;
258
259 $error = 0;
260
261 if (empty($this->id) && !empty($this->rowid)) { // For backward compatibility
262 $this->id = $this->rowid;
263 }
264
265 // check if order line is not in a shipment line before deleting
266 $sqlCheckShipmentLine = "SELECT";
267 $sqlCheckShipmentLine .= " ed.rowid";
268 $sqlCheckShipmentLine .= " FROM " . MAIN_DB_PREFIX . "expeditiondet ed";
269 $sqlCheckShipmentLine .= " WHERE ed.fk_elementdet = " . ((int) $this->id);
270
271 $resqlCheckShipmentLine = $this->db->query($sqlCheckShipmentLine);
272 if (!$resqlCheckShipmentLine) {
273 $error++;
274 $this->error = $this->db->lasterror();
275 $this->errors[] = $this->error;
276 } else {
277 $langs->load('errors');
278 $num = $this->db->num_rows($resqlCheckShipmentLine);
279 if ($num > 0) {
280 $error++;
281 $objCheckShipmentLine = $this->db->fetch_object($resqlCheckShipmentLine);
282 $this->error = $langs->trans('ErrorRecordAlreadyExists') . ' : ' . $langs->trans('ShipmentLine') . ' ' . $objCheckShipmentLine->rowid;
283 $this->errors[] = $this->error;
284 }
285 $this->db->free($resqlCheckShipmentLine);
286 }
287 if ($error) {
288 dol_syslog(__METHOD__ . 'Error ; ' . $this->error, LOG_ERR);
289 return -1;
290 }
291
292 $this->db->begin();
293
294 if (!$notrigger) {
295 // Call trigger
296 $result = $this->call_trigger('LINEORDER_DELETE', $user);
297 if ($result < 0) {
298 $error++;
299 }
300 // End call triggers
301 }
302
303 if (!$error) {
304 $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commandedet WHERE rowid = " . ((int) $this->id);
305
306 dol_syslog("OrderLine::delete", LOG_DEBUG);
307 $resql = $this->db->query($sql);
308 if (!$resql) {
309 $this->error = $this->db->lasterror();
310 $error++;
311 }
312 }
313
314 // Remove extrafields
315 if (!$error) {
316 $result = $this->deleteExtraFields();
317 if ($result < 0) {
318 $error++;
319 dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR);
320 }
321 }
322
323 if (!$error) {
324 $this->db->commit();
325 return 1;
326 }
327
328 foreach ($this->errors as $errmsg) {
329 dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR);
330 $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
331 }
332 $this->db->rollback();
333 return -1 * $error;
334 }
335
343 public function insert($user = null, $notrigger = 0)
344 {
345 $error = 0;
346
347 $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
348
349 dol_syslog(get_class($this)."::insert rang=".$this->rang);
350
351 // Clean parameters
352 if (empty($this->tva_tx)) {
353 $this->tva_tx = 0;
354 }
355 if (empty($this->localtax1_tx)) {
356 $this->localtax1_tx = 0;
357 }
358 if (empty($this->localtax2_tx)) {
359 $this->localtax2_tx = 0;
360 }
361 if (empty($this->localtax1_type)) {
362 $this->localtax1_type = 0;
363 }
364 if (empty($this->localtax2_type)) {
365 $this->localtax2_type = 0;
366 }
367 if (empty($this->total_localtax1)) {
368 $this->total_localtax1 = 0;
369 }
370 if (empty($this->total_localtax2)) {
371 $this->total_localtax2 = 0;
372 }
373 if (empty($this->rang)) {
374 $this->rang = 0;
375 }
376 if (empty($this->remise_percent)) {
377 $this->remise_percent = 0;
378 }
379 if (empty($this->info_bits)) {
380 $this->info_bits = 0;
381 }
382 if (empty($this->special_code)) {
383 $this->special_code = 0;
384 }
385 if (empty($this->fk_parent_line)) {
386 $this->fk_parent_line = 0;
387 }
388 if (empty($this->pa_ht)) {
389 $this->pa_ht = 0;
390 }
391 if (empty($this->ref_ext)) {
392 $this->ref_ext = '';
393 }
394
395 // if buy price not defined, define buyprice as configured in margin admin
396 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
397 $result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product);
398 if ($result < 0) {
399 return $result;
400 } else {
401 $this->pa_ht = $result;
402 }
403 }
404
405 // Check parameters
406 if ($this->product_type < 0) {
407 return -1;
408 }
409
410 $this->db->begin();
411
412 // Insertion dans base de la ligne
413 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet';
414 $sql .= ' (fk_commande, fk_parent_line, label, description, qty, ref_ext,';
415 $sql .= ' vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
416 $sql .= ' fk_product, product_type, remise_percent, subprice, price, fk_remise_except,';
417 $sql .= ' special_code, rang, fk_product_fournisseur_price, buy_price_ht,';
418 $sql .= ' info_bits, total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, date_start, date_end,';
419 $sql .= ' fk_unit,';
420 $sql .= ' fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
421 $sql .= ')';
422 $sql .= " VALUES (".$this->fk_commande.",";
423 $sql .= " ".($this->fk_parent_line > 0 ? "'".$this->db->escape($this->fk_parent_line)."'" : "null").",";
424 $sql .= " ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
425 $sql .= " '".$this->db->escape($this->desc)."',";
426 $sql .= " '".price2num($this->qty)."',";
427 $sql .= " '".$this->db->escape($this->ref_ext)."',";
428 $sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").",";
429 $sql .= " '".price2num($this->tva_tx)."',";
430 $sql .= " '".price2num($this->localtax1_tx)."',";
431 $sql .= " '".price2num($this->localtax2_tx)."',";
432 $sql .= " '".$this->db->escape($this->localtax1_type)."',";
433 $sql .= " '".$this->db->escape($this->localtax2_type)."',";
434 $sql .= ' '.((!empty($this->fk_product) && $this->fk_product > 0) ? $this->fk_product : "null").',';
435 $sql .= " '".$this->db->escape($this->product_type)."',";
436 $sql .= " '".price2num($this->remise_percent)."',";
437 $sql .= " ".(price2num($this->subprice) !== '' ? price2num($this->subprice) : "null").",";
438 $sql .= " ".($this->price != '' ? "'".price2num($this->price)."'" : "null").",";
439 $sql .= ' '.(!empty($this->fk_remise_except) ? $this->fk_remise_except : "null").',';
440 $sql .= ' '.((int) $this->special_code).',';
441 $sql .= ' '.((int) $this->rang).',';
442 $sql .= ' '.(!empty($this->fk_fournprice) ? $this->fk_fournprice : "null").',';
443 $sql .= ' '.price2num($this->pa_ht).',';
444 $sql .= " ".((int) $this->info_bits).",";
445 $sql .= " ".price2num($this->total_ht, 'MT').",";
446 $sql .= " ".price2num($this->total_tva, 'MT').",";
447 $sql .= " ".price2num($this->total_localtax1, 'MT').",";
448 $sql .= " ".price2num($this->total_localtax2, 'MT').",";
449 $sql .= " ".price2num($this->total_ttc, 'MT').",";
450 $sql .= " ".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null").',';
451 $sql .= " ".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null").',';
452 $sql .= ' '.(!$this->fk_unit ? 'NULL' : ((int) $this->fk_unit));
453 $sql .= ", ".(!empty($this->fk_multicurrency) ? ((int) $this->fk_multicurrency) : 'NULL');
454 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
455 $sql .= ", ".price2num($this->multicurrency_subprice, 'CU');
456 $sql .= ", ".price2num($this->multicurrency_total_ht, 'CT');
457 $sql .= ", ".price2num($this->multicurrency_total_tva, 'CT');
458 $sql .= ", ".price2num($this->multicurrency_total_ttc, 'CT');
459 $sql .= ')';
460
461 dol_syslog(get_class($this)."::insert", LOG_DEBUG);
462 $resql = $this->db->query($sql);
463 if ($resql) {
464 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'commandedet');
465 $this->rowid = $this->id;
466
467 if (!$error) {
468 $result = $this->insertExtraFields();
469 if ($result < 0) {
470 $error++;
471 }
472 }
473
474 if (!$error && !$notrigger) {
475 // Call trigger
476 $result = $this->call_trigger('LINEORDER_INSERT', $user);
477 if ($result < 0) {
478 $error++;
479 }
480 // End call triggers
481 }
482
483 if (!$error) {
484 $this->db->commit();
485 return 1;
486 }
487
488 foreach ($this->errors as $errmsg) {
489 dol_syslog(get_class($this)."::insert ".$errmsg, LOG_ERR);
490 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
491 }
492 $this->db->rollback();
493 return -1 * $error;
494 } else {
495 $this->error = $this->db->error();
496 $this->db->rollback();
497 return -2;
498 }
499 }
500
508 public function update(User $user, $notrigger = 0)
509 {
510 $error = 0;
511
512 $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
513
514 // Clean parameters
515 if (empty($this->tva_tx)) {
516 $this->tva_tx = 0;
517 }
518 if (empty($this->localtax1_tx)) {
519 $this->localtax1_tx = 0;
520 }
521 if (empty($this->localtax2_tx)) {
522 $this->localtax2_tx = 0;
523 }
524 if (empty($this->localtax1_type)) {
525 $this->localtax1_type = 0;
526 }
527 if (empty($this->localtax2_type)) {
528 $this->localtax2_type = 0;
529 }
530 if (empty($this->qty)) {
531 $this->qty = 0;
532 }
533 if (empty($this->total_localtax1)) {
534 $this->total_localtax1 = 0;
535 }
536 if (empty($this->total_localtax2)) {
537 $this->total_localtax2 = 0;
538 }
539 if (empty($this->marque_tx)) {
540 $this->marque_tx = 0;
541 }
542 if (empty($this->marge_tx)) {
543 $this->marge_tx = 0;
544 }
545 if (empty($this->remise_percent)) {
546 $this->remise_percent = 0;
547 }
548 if (empty($this->remise)) {
549 $this->remise = 0;
550 }
551 if (empty($this->info_bits)) {
552 $this->info_bits = 0;
553 }
554 if (empty($this->special_code)) {
555 $this->special_code = 0;
556 }
557 if (empty($this->product_type)) {
558 $this->product_type = 0;
559 }
560 if (empty($this->fk_parent_line)) {
561 $this->fk_parent_line = 0;
562 }
563 if (empty($this->pa_ht)) {
564 $this->pa_ht = 0;
565 }
566 if (empty($this->ref_ext)) {
567 $this->ref_ext = '';
568 }
569
570 // if buy price not defined, define buyprice as configured in margin admin
571 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
572 $result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product);
573 if ($result < 0) {
574 return $result;
575 } else {
576 $this->pa_ht = $result;
577 }
578 }
579
580 $this->db->begin();
581
582 // Mise a jour ligne en base
583 $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET";
584 $sql .= " description='".$this->db->escape($this->desc)."'";
585 $sql .= " , label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
586 $sql .= " , vat_src_code=".(!empty($this->vat_src_code) ? "'".$this->db->escape($this->vat_src_code)."'" : "''");
587 $sql .= " , tva_tx=".price2num($this->tva_tx);
588 $sql .= " , localtax1_tx=".price2num($this->localtax1_tx);
589 $sql .= " , localtax2_tx=".price2num($this->localtax2_tx);
590 $sql .= " , localtax1_type='".$this->db->escape($this->localtax1_type)."'";
591 $sql .= " , localtax2_type='".$this->db->escape($this->localtax2_type)."'";
592 $sql .= " , qty=".price2num($this->qty);
593 $sql .= " , ref_ext='".$this->db->escape($this->ref_ext)."'";
594 $sql .= " , subprice=".price2num($this->subprice);
595 $sql .= " , remise_percent=".price2num($this->remise_percent);
596 $sql .= " , price=".price2num($this->price); // TODO A virer
597 $sql .= " , remise=".price2num($this->remise); // TODO A virer
598 if (empty($this->skip_update_total)) {
599 $sql .= " , total_ht=".price2num($this->total_ht);
600 $sql .= " , total_tva=".price2num($this->total_tva);
601 $sql .= " , total_ttc=".price2num($this->total_ttc);
602 $sql .= " , total_localtax1=".price2num($this->total_localtax1);
603 $sql .= " , total_localtax2=".price2num($this->total_localtax2);
604 }
605 $sql .= " , fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? $this->fk_fournprice : "null");
606 $sql .= " , buy_price_ht='".price2num($this->pa_ht)."'";
607 $sql .= " , info_bits=".((int) $this->info_bits);
608 $sql .= " , special_code=".((int) $this->special_code);
609 $sql .= " , date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null");
610 $sql .= " , date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
611 $sql .= " , product_type=".$this->product_type;
612 $sql .= " , fk_parent_line=".(!empty($this->fk_parent_line) ? $this->fk_parent_line : "null");
613 if (!empty($this->rang)) {
614 $sql .= ", rang=".((int) $this->rang);
615 }
616 $sql .= " , fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
617
618 // Multicurrency
619 $sql .= " , multicurrency_subprice=".price2num($this->multicurrency_subprice);
620 $sql .= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
621 $sql .= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
622 $sql .= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
623
624 $sql .= " WHERE rowid = ".((int) $this->rowid);
625
626 dol_syslog(get_class($this)."::update", LOG_DEBUG);
627 $resql = $this->db->query($sql);
628 if ($resql) {
629 if (!$error) {
630 $this->id = $this->rowid;
631 $result = $this->insertExtraFields();
632 if ($result < 0) {
633 $error++;
634 }
635 }
636
637 if (!$error && !$notrigger) {
638 // Call trigger
639 $result = $this->call_trigger('LINEORDER_MODIFY', $user);
640 if ($result < 0) {
641 $error++;
642 }
643 // End call triggers
644 }
645
646 if (!$error) {
647 $this->db->commit();
648 return 1;
649 }
650
651 foreach ($this->errors as $errmsg) {
652 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
653 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
654 }
655 $this->db->rollback();
656 return -1 * $error;
657 } else {
658 $this->error = $this->db->error();
659 $this->db->rollback();
660 return -2;
661 }
662 }
663
664 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
671 public function update_total()
672 {
673 // phpcs:enable
674 $this->db->begin();
675
676 // Clean parameters
677 if (empty($this->total_localtax1)) {
678 $this->total_localtax1 = 0;
679 }
680 if (empty($this->total_localtax2)) {
681 $this->total_localtax2 = 0;
682 }
683
684 // Mise a jour ligne en base
685 $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET";
686 $sql .= " total_ht='".price2num($this->total_ht)."'";
687 $sql .= ",total_tva='".price2num($this->total_tva)."'";
688 $sql .= ",total_localtax1='".price2num($this->total_localtax1)."'";
689 $sql .= ",total_localtax2='".price2num($this->total_localtax2)."'";
690 $sql .= ",total_ttc='".price2num($this->total_ttc)."'";
691 $sql .= " WHERE rowid = ".((int) $this->rowid);
692
693 dol_syslog("OrderLine::update_total", LOG_DEBUG);
694
695 $resql = $this->db->query($sql);
696 if ($resql) {
697 $this->db->commit();
698 return 1;
699 } else {
700 $this->error = $this->db->error();
701 $this->db->rollback();
702 return -2;
703 }
704 }
705}
$object ref
Definition info.php:79
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...
defineBuyPrice($unitPrice=0.0, $discountPercent=0.0, $fk_product=0)
Get buy price to use for margin calculation.
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.
Superclass for orders classes.
Class to manage order lines.
insert($user=null, $notrigger=0)
Insert line into database.
update(User $user, $notrigger=0)
Update the line object into db.
update_total()
Update DB line fields total_xxx Used by migration.
__construct($db)
Constructor.
fetch($rowid)
Load line order.
Class to manage Dolibarr users.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getMarginInfos($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
Return an array with margins information of a line.