dolibarr 21.0.3
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
42
47{
51 public $element = 'commandedet';
52
56 public $table_element = 'commandedet';
57
61 public $oldline;
62
67 public $fk_commande;
68
75 public $commande_id;
76
80 public $fk_parent_line;
81
85 public $fk_facture;
86
90 public $ref_ext;
91
95 public $fk_remise_except;
96
100 public $rang = 0;
101
105 public $fk_fournprice;
106
111 public $pa_ht;
112
116 public $marge_tx;
117
121 public $marque_tx;
122
128 public $remise;
129
134 public $date_start;
135
140 public $date_end;
141
146 public $skip_update_total;
147
148
154 public function __construct($db)
155 {
156 $this->db = $db;
157 }
158
165 public function fetch($rowid)
166 {
167 $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,';
168 $sql .= ' cd.remise, cd.remise_percent, cd.fk_remise_except, cd.subprice, cd.ref_ext,';
169 $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,';
170 $sql .= ' cd.fk_unit,';
171 $sql .= ' cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
172 $sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc, p.tobatch as product_tobatch,';
173 $sql .= ' cd.date_start, cd.date_end, cd.vat_src_code';
174 $sql .= ' FROM '.MAIN_DB_PREFIX.'commandedet as cd';
175 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid';
176 $sql .= ' WHERE cd.rowid = '.((int) $rowid);
177 $result = $this->db->query($sql);
178 if ($result) {
179 $objp = $this->db->fetch_object($result);
180
181 if (!$objp) {
182 $this->error = 'OrderLine with id '. $rowid .' not found sql='.$sql;
183 return 0;
184 }
185
186 $this->rowid = $objp->rowid;
187 $this->id = $objp->rowid;
188 $this->fk_commande = $objp->fk_commande;
189 $this->fk_parent_line = $objp->fk_parent_line;
190 $this->label = $objp->custom_label;
191 $this->desc = $objp->description;
192 $this->qty = $objp->qty;
193 $this->price = $objp->price;
194 $this->subprice = $objp->subprice;
195 $this->ref_ext = $objp->ref_ext;
196 $this->vat_src_code = $objp->vat_src_code;
197 $this->tva_tx = $objp->tva_tx;
198 $this->localtax1_tx = $objp->localtax1_tx;
199 $this->localtax2_tx = $objp->localtax2_tx;
200 $this->remise = $objp->remise;
201 $this->remise_percent = $objp->remise_percent;
202 $this->fk_remise_except = $objp->fk_remise_except;
203 $this->fk_product = $objp->fk_product;
204 $this->product_type = $objp->product_type;
205 $this->info_bits = $objp->info_bits;
206 $this->special_code = $objp->special_code;
207 $this->total_ht = $objp->total_ht;
208 $this->total_tva = $objp->total_tva;
209 $this->total_localtax1 = $objp->total_localtax1;
210 $this->total_localtax2 = $objp->total_localtax2;
211 $this->total_ttc = $objp->total_ttc;
212 $this->fk_fournprice = $objp->fk_fournprice;
213 $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
214 $this->pa_ht = $marginInfos[0];
215 $this->marge_tx = $marginInfos[1];
216 $this->marque_tx = $marginInfos[2];
217 $this->special_code = $objp->special_code;
218 $this->rang = $objp->rang;
219
220 $this->ref = $objp->product_ref; // deprecated
221
222 $this->product_ref = $objp->product_ref;
223 $this->product_label = $objp->product_label;
224 $this->product_desc = $objp->product_desc;
225 $this->product_tobatch = $objp->product_tobatch;
226 $this->fk_unit = $objp->fk_unit;
227
228 $this->date_start = $this->db->jdate($objp->date_start);
229 $this->date_end = $this->db->jdate($objp->date_end);
230
231 $this->fk_multicurrency = $objp->fk_multicurrency;
232 $this->multicurrency_code = $objp->multicurrency_code;
233 $this->multicurrency_subprice = $objp->multicurrency_subprice;
234 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
235 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
236 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
237
238 $this->fetch_optionals();
239
240 $this->db->free($result);
241
242 return 1;
243 } else {
244 $this->error = $this->db->lasterror();
245 return -1;
246 }
247 }
248
256 public function delete(User $user, $notrigger = 0)
257 {
258 global $conf, $langs;
259
260 $error = 0;
261
262 if (empty($this->id) && !empty($this->rowid)) { // For backward compatibility
263 $this->id = $this->rowid;
264 }
265
266 // check if order line is not in a shipment line before deleting
267 $sqlCheckShipmentLine = "SELECT";
268 $sqlCheckShipmentLine .= " ed.rowid";
269 $sqlCheckShipmentLine .= " FROM " . MAIN_DB_PREFIX . "expeditiondet ed";
270 $sqlCheckShipmentLine .= " WHERE ed.fk_elementdet = " . ((int) $this->id);
271
272 $resqlCheckShipmentLine = $this->db->query($sqlCheckShipmentLine);
273 if (!$resqlCheckShipmentLine) {
274 $error++;
275 $this->error = $this->db->lasterror();
276 $this->errors[] = $this->error;
277 } else {
278 $langs->load('errors');
279 $num = $this->db->num_rows($resqlCheckShipmentLine);
280 if ($num > 0) {
281 $error++;
282 $objCheckShipmentLine = $this->db->fetch_object($resqlCheckShipmentLine);
283 $this->error = $langs->trans('ErrorRecordAlreadyExists') . ' : ' . $langs->trans('ShipmentLine') . ' ' . $objCheckShipmentLine->rowid;
284 $this->errors[] = $this->error;
285 }
286 $this->db->free($resqlCheckShipmentLine);
287 }
288 if ($error) {
289 dol_syslog(__METHOD__ . 'Error ; ' . $this->error, LOG_ERR);
290 return -1;
291 }
292
293 $this->db->begin();
294
295 if (!$notrigger) {
296 // Call trigger
297 $result = $this->call_trigger('LINEORDER_DELETE', $user);
298 if ($result < 0) {
299 $error++;
300 }
301 // End call triggers
302 }
303
304 if (!$error) {
305 $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commandedet WHERE rowid = " . ((int) $this->id);
306
307 dol_syslog("OrderLine::delete", LOG_DEBUG);
308 $resql = $this->db->query($sql);
309 if (!$resql) {
310 $this->error = $this->db->lasterror();
311 $error++;
312 }
313 }
314
315 // Remove extrafields
316 if (!$error) {
317 $result = $this->deleteExtraFields();
318 if ($result < 0) {
319 $error++;
320 dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR);
321 }
322 }
323
324 if (!$error) {
325 $this->db->commit();
326 return 1;
327 }
328
329 foreach ($this->errors as $errmsg) {
330 dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR);
331 $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
332 }
333 $this->db->rollback();
334 return -1 * $error;
335 }
336
344 public function insert($user = null, $notrigger = 0)
345 {
346 $error = 0;
347
348 $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'.
349 $this->pa_ht = (float) $this->pa_ht; // convert to float but after checking if value is empty
350
351 dol_syslog(get_class($this)."::insert rang=".$this->rang);
352
353 // Clean parameters
354 if (empty($this->tva_tx)) {
355 $this->tva_tx = 0;
356 }
357 if (empty($this->localtax1_tx)) {
358 $this->localtax1_tx = 0;
359 }
360 if (empty($this->localtax2_tx)) {
361 $this->localtax2_tx = 0;
362 }
363 if (empty($this->localtax1_type)) {
364 $this->localtax1_type = '0';
365 }
366 if (empty($this->localtax2_type)) {
367 $this->localtax2_type = '0';
368 }
369 if (empty($this->total_localtax1)) {
370 $this->total_localtax1 = 0;
371 }
372 if (empty($this->total_localtax2)) {
373 $this->total_localtax2 = 0;
374 }
375 if (empty($this->rang)) {
376 $this->rang = 0;
377 }
378 if (empty($this->remise_percent)) {
379 $this->remise_percent = 0;
380 }
381 if (empty($this->info_bits)) {
382 $this->info_bits = 0;
383 }
384 if (empty($this->special_code)) {
385 $this->special_code = 0;
386 }
387 if (empty($this->fk_parent_line)) {
388 $this->fk_parent_line = 0;
389 }
390 if (empty($this->ref_ext)) {
391 $this->ref_ext = '';
392 }
393
394 // if buy price not defined (if = ''), we set the buyprice as configured in margin admin setup
395 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
396 $result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product);
397 if ($result < 0) {
398 return $result;
399 } else {
400 $this->pa_ht = $result;
401 }
402 }
403
404 // Check parameters
405 if ($this->product_type < 0) {
406 return -1;
407 }
408
409 $this->db->begin();
410
411 // Insertion dans base de la ligne
412 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet';
413 $sql .= ' (fk_commande, fk_parent_line, label, description, qty, ref_ext,';
414 $sql .= ' vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
415 $sql .= ' fk_product, product_type, remise_percent, subprice, price, fk_remise_except,';
416 $sql .= ' special_code, rang, fk_product_fournisseur_price, buy_price_ht,';
417 $sql .= ' info_bits, total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, date_start, date_end,';
418 $sql .= ' fk_unit,';
419 $sql .= ' fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
420 $sql .= ')';
421 $sql .= " VALUES (".$this->fk_commande.",";
422 $sql .= " ".($this->fk_parent_line > 0 ? "'".$this->db->escape($this->fk_parent_line)."'" : "null").",";
423 $sql .= " ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
424 $sql .= " '".$this->db->escape($this->desc)."',";
425 $sql .= " '".price2num($this->qty)."',";
426 $sql .= " '".$this->db->escape($this->ref_ext)."',";
427 $sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").",";
428 $sql .= " '".price2num($this->tva_tx)."',";
429 $sql .= " '".price2num($this->localtax1_tx)."',";
430 $sql .= " '".price2num($this->localtax2_tx)."',";
431 $sql .= " '".$this->db->escape($this->localtax1_type)."',";
432 $sql .= " '".$this->db->escape($this->localtax2_type)."',";
433 $sql .= ' '.((!empty($this->fk_product) && $this->fk_product > 0) ? $this->fk_product : "null").',';
434 $sql .= " '".$this->db->escape($this->product_type)."',";
435 $sql .= " '".price2num($this->remise_percent)."',";
436 $sql .= " ".(price2num($this->subprice) !== '' ? price2num($this->subprice) : "null").",";
437 $sql .= " ".($this->price != '' ? "'".price2num($this->price)."'" : "null").",";
438 $sql .= ' '.(!empty($this->fk_remise_except) ? $this->fk_remise_except : "null").',';
439 $sql .= ' '.((int) $this->special_code).',';
440 $sql .= ' '.((int) $this->rang).',';
441 $sql .= ' '.(!empty($this->fk_fournprice) ? $this->fk_fournprice : "null").',';
442 $sql .= ' '.price2num($this->pa_ht).',';
443 $sql .= " ".((int) $this->info_bits).",";
444 $sql .= " ".price2num($this->total_ht, 'MT').",";
445 $sql .= " ".price2num($this->total_tva, 'MT').",";
446 $sql .= " ".price2num($this->total_localtax1, 'MT').",";
447 $sql .= " ".price2num($this->total_localtax2, 'MT').",";
448 $sql .= " ".price2num($this->total_ttc, 'MT').",";
449 $sql .= " ".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null").',';
450 $sql .= " ".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null").',';
451 $sql .= ' '.(!$this->fk_unit ? 'NULL' : ((int) $this->fk_unit));
452 $sql .= ", ".(!empty($this->fk_multicurrency) ? ((int) $this->fk_multicurrency) : 'NULL');
453 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
454 $sql .= ", ".price2num($this->multicurrency_subprice, 'CU');
455 $sql .= ", ".price2num($this->multicurrency_total_ht, 'CT');
456 $sql .= ", ".price2num($this->multicurrency_total_tva, 'CT');
457 $sql .= ", ".price2num($this->multicurrency_total_ttc, 'CT');
458 $sql .= ')';
459
460 dol_syslog(get_class($this)."::insert", LOG_DEBUG);
461 $resql = $this->db->query($sql);
462 if ($resql) {
463 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'commandedet');
464 $this->rowid = $this->id;
465
466 if (!$error) {
467 $result = $this->insertExtraFields();
468 if ($result < 0) {
469 $error++;
470 }
471 }
472
473 if (!$error && !$notrigger) {
474 // Call trigger
475 $result = $this->call_trigger('LINEORDER_INSERT', $user);
476 if ($result < 0) {
477 $error++;
478 }
479 // End call triggers
480 }
481
482 if (!$error) {
483 $this->db->commit();
484 return $this->id;
485 }
486
487 foreach ($this->errors as $errmsg) {
488 dol_syslog(get_class($this)."::insert ".$errmsg, LOG_ERR);
489 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
490 }
491 $this->db->rollback();
492 return -1 * $error;
493 } else {
494 $this->error = $this->db->error();
495 $this->db->rollback();
496 return -2;
497 }
498 }
499
507 public function update(User $user, $notrigger = 0)
508 {
509 $error = 0;
510
511 $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'.
512
513 // Clean parameters
514 if (empty($this->tva_tx)) {
515 $this->tva_tx = 0;
516 }
517 if (empty($this->localtax1_tx)) {
518 $this->localtax1_tx = 0;
519 }
520 if (empty($this->localtax2_tx)) {
521 $this->localtax2_tx = 0;
522 }
523 if (empty($this->localtax1_type)) {
524 $this->localtax1_type = '0';
525 }
526 if (empty($this->localtax2_type)) {
527 $this->localtax2_type = '0';
528 }
529 if (empty($this->qty)) {
530 $this->qty = 0;
531 }
532 if (empty($this->total_localtax1)) {
533 $this->total_localtax1 = 0;
534 }
535 if (empty($this->total_localtax2)) {
536 $this->total_localtax2 = 0;
537 }
538 if (empty($this->marque_tx)) {
539 $this->marque_tx = 0;
540 }
541 if (empty($this->marge_tx)) {
542 $this->marge_tx = 0;
543 }
544 if (empty($this->remise_percent)) {
545 $this->remise_percent = 0;
546 }
547 if (empty($this->remise)) {
548 $this->remise = 0;
549 }
550 if (empty($this->info_bits)) {
551 $this->info_bits = 0;
552 }
553 if (empty($this->special_code)) {
554 $this->special_code = 0;
555 }
556 if (empty($this->product_type)) {
557 $this->product_type = 0;
558 }
559 if (empty($this->fk_parent_line)) {
560 $this->fk_parent_line = 0;
561 }
562 if (empty($this->pa_ht)) {
563 $this->pa_ht = 0;
564 }
565 if (empty($this->ref_ext)) {
566 $this->ref_ext = '';
567 }
568
569 // if buy price not defined, define buyprice as configured in margin admin
570 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
571 $result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product);
572 if ($result < 0) {
573 return $result;
574 } else {
575 $this->pa_ht = $result;
576 }
577 }
578
579 $this->db->begin();
580
581 // Mise a jour ligne en base
582 $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET";
583 $sql .= " description='".$this->db->escape($this->desc)."'";
584 $sql .= " , label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
585 $sql .= " , vat_src_code=".(!empty($this->vat_src_code) ? "'".$this->db->escape($this->vat_src_code)."'" : "''");
586 $sql .= " , tva_tx=".price2num($this->tva_tx);
587 $sql .= " , localtax1_tx=".price2num($this->localtax1_tx);
588 $sql .= " , localtax2_tx=".price2num($this->localtax2_tx);
589 $sql .= " , localtax1_type='".$this->db->escape($this->localtax1_type)."'";
590 $sql .= " , localtax2_type='".$this->db->escape($this->localtax2_type)."'";
591 $sql .= " , qty=".price2num($this->qty);
592 $sql .= " , ref_ext='".$this->db->escape($this->ref_ext)."'";
593 $sql .= " , subprice=".price2num($this->subprice);
594 $sql .= " , remise_percent=".price2num($this->remise_percent);
595 $sql .= " , price=".price2num($this->price); // TODO A virer
596 $sql .= " , remise=".price2num($this->remise); // TODO A virer
597 if (empty($this->skip_update_total)) {
598 $sql .= " , total_ht=".price2num($this->total_ht);
599 $sql .= " , total_tva=".price2num($this->total_tva);
600 $sql .= " , total_ttc=".price2num($this->total_ttc);
601 $sql .= " , total_localtax1=".price2num($this->total_localtax1);
602 $sql .= " , total_localtax2=".price2num($this->total_localtax2);
603 }
604 $sql .= " , fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? $this->fk_fournprice : "null");
605 $sql .= " , buy_price_ht='".price2num($this->pa_ht)."'";
606 $sql .= " , info_bits=".((int) $this->info_bits);
607 $sql .= " , special_code=".((int) $this->special_code);
608 $sql .= " , date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null");
609 $sql .= " , date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
610 $sql .= " , product_type=".$this->product_type;
611 $sql .= " , fk_parent_line=".(!empty($this->fk_parent_line) ? $this->fk_parent_line : "null");
612 if (!empty($this->rang)) {
613 $sql .= ", rang=".((int) $this->rang);
614 }
615 $sql .= " , fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
616
617 // Multicurrency
618 $sql .= " , multicurrency_subprice=".price2num($this->multicurrency_subprice);
619 $sql .= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
620 $sql .= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
621 $sql .= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
622
623 $sql .= " WHERE rowid = ".((int) $this->rowid);
624
625 dol_syslog(get_class($this)."::update", LOG_DEBUG);
626 $resql = $this->db->query($sql);
627 if ($resql) {
628 if (!$error) {
629 $this->id = $this->rowid;
630 $result = $this->insertExtraFields();
631 if ($result < 0) {
632 $error++;
633 }
634 }
635
636 if (!$error && !$notrigger) {
637 // Call trigger
638 $result = $this->call_trigger('LINEORDER_MODIFY', $user);
639 if ($result < 0) {
640 $error++;
641 }
642 // End call triggers
643 }
644
645 if (!$error) {
646 $this->db->commit();
647 return 1;
648 }
649
650 foreach ($this->errors as $errmsg) {
651 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
652 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
653 }
654 $this->db->rollback();
655 return -1 * $error;
656 } else {
657 $this->error = $this->db->error();
658 $this->db->rollback();
659 return -2;
660 }
661 }
662
663 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
670 public function update_total()
671 {
672 // phpcs:enable
673 $this->db->begin();
674
675 // Clean parameters
676 if (empty($this->total_localtax1)) {
677 $this->total_localtax1 = 0;
678 }
679 if (empty($this->total_localtax2)) {
680 $this->total_localtax2 = 0;
681 }
682
683 // Mise a jour ligne en base
684 $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET";
685 $sql .= " total_ht='".price2num($this->total_ht)."'";
686 $sql .= ",total_tva='".price2num($this->total_tva)."'";
687 $sql .= ",total_localtax1='".price2num($this->total_localtax1)."'";
688 $sql .= ",total_localtax2='".price2num($this->total_localtax2)."'";
689 $sql .= ",total_ttc='".price2num($this->total_ttc)."'";
690 $sql .= " WHERE rowid = ".((int) $this->rowid);
691
692 dol_syslog("OrderLine::update_total", LOG_DEBUG);
693
694 $resql = $this->db->query($sql);
695 if ($resql) {
696 $this->db->commit();
697 return 1;
698 } else {
699 $this->error = $this->db->error();
700 $this->db->rollback();
701 return -2;
702 }
703 }
704}
$object ref
Definition info.php:89
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79