dolibarr 25.0.0-alpha
expeditionligne.class.php
1<?php
2/* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
5 * Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
6 * Copyright (C) 2011-2020 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
9 * Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
10 * Copyright (C) 2014-2017 Francis Appels <francis.appels@yahoo.com>
11 * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
12 * Copyright (C) 2016-2024 Ferran Marcet <fmarcet@2byte.es>
13 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
14 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
15 * Copyright (C) 2020 Lenin Rivas <lenin@leninrivas.com>
16 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
17 * Copyright (C) 2025 Nick Fragoulis
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.'/expedition/class/expeditionlinebatch.class.php';
41
46{
50 public $element = 'expeditiondet';
51
55 public $table_element = 'expeditiondet';
56
60 public $parent_element = 'expedition';
61
65 public $fk_parent_attribute = 'fk_expedition';
66
73 public $line_id; // deprecated
74
78 public $fk_element;
79
83 public $origin_id;
84
88 public $fk_elementdet;
89
93 public $origin_line_id;
94
98 public $fk_parent;
99
103 public $element_type;
104
105
112 public $fk_origin; // Example: 'orderline'
113
117 public $fk_expedition;
118
122 public $db;
123
127 public $qty;
128
132 public $qty_shipped;
133
137 public $fk_product;
138
144 public $detail_batch;
145
150 public $detail_children;
151
156 public $details_entrepot;
157
158
162 public $entrepot_id;
163
168 public $fk_entrepot;
169
170
174 public $qty_asked;
175
181 public $ref;
182
186 public $product_ref;
187
193 public $libelle;
194
198 public $product_label;
199
203 public $label;
204
210 public $desc;
211
215 public $product_desc;
216
221 public $product_type = 0;
222
226 public $rang;
227
231 public $weight;
232
236 public $weight_units;
237
241 public $length;
242
246 public $length_units;
247
251 public $width;
252
256 public $width_units;
257
261 public $height;
262
266 public $height_units;
267
271 public $surface;
272
276 public $surface_units;
277
281 public $volume;
282
286 public $volume_units;
287
293 public $stockable_product = 1;
294
298 public $remise_percent;
299
303 public $tva_tx;
304
308 public $total_ht;
309
313 public $total_ttc;
314
318 public $total_tva;
319
323 public $total_localtax1;
324
328 public $total_localtax2;
329
330
336 public function __construct($db)
337 {
338 $this->db = $db;
339 }
340
347 public function fetch($rowid)
348 {
349 $sql = 'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_product, ed.fk_parent, ed.description, ed.fk_unit, ed.fk_elementdet, ed.element_type, ed.qty, ed.rang, ed.extraparams';
350 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as ed';
351 $sql .= ' WHERE ed.rowid = '.((int) $rowid);
352 $result = $this->db->query($sql);
353 if ($result) {
354 $objp = $this->db->fetch_object($result);
355 $this->id = $objp->rowid;
356 $this->fk_expedition = $objp->fk_expedition;
357 $this->entrepot_id = $objp->fk_entrepot;
358 $this->fk_entrepot = $objp->fk_entrepot;
359 $this->fk_product = $objp->fk_product;
360 $this->fk_parent = $objp->fk_parent;
361 $this->description = $objp->description;
362 $this->fk_unit = $objp->fk_unit;
363 $this->fk_elementdet = $objp->fk_elementdet;
364 $this->element_type = $objp->element_type;
365 $this->qty = $objp->qty;
366 $this->rang = $objp->rang;
367
368 $this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
369
370 $this->db->free($result);
371
372 return 1;
373 } else {
374 $this->errors[] = $this->db->lasterror();
375 $this->error = $this->db->lasterror();
376 return -1;
377 }
378 }
379
387 public function insert($user = null, $notrigger = 0)
388 {
389 global $langs;
390 $error = 0;
391
392 $skip_check_parameters = false;
393
394 // Handling parent line subtotal line
395 if (!empty($this->element_type)
396 && !empty($this->fk_elementdet)
397 && $this->element_type == 'commande') {
398 $objectsrc_line = new OrderLine($this->db);
399 $objectsrc_line->fetch($this->fk_elementdet);
400 $skip_check_parameters = $objectsrc_line->special_code == SUBTOTALS_SPECIAL_CODE;
401 }
402
403 // Check parameters
404 $origin_id = $this->origin_id;
405 if ($origin_id > 0) {
406 if ((empty($this->fk_expedition)
407 || (empty($this->fk_elementdet) && empty($this->fk_parent)) // at least origin line id of parent line id is set
408 || !is_numeric($this->qty))
409 && !$skip_check_parameters) {
410 $langs->load('errors');
411 $this->errors[] = $langs->trans('ErrorMandatoryParametersNotProvided');
412 return -1;
413 }
414 } else {
415 if (empty($this->fk_expedition) || !is_numeric($this->qty)) {
416 $langs->load('errors');
417 $this->errors[] = $langs->trans('ErrorMandatoryParametersNotProvided');
418 return -1;
419 }
420 }
421 $this->db->begin();
422
423 if (getDolGlobalString('STOCK_EXPEDITION_NO_MORE_THAN_ORDER') && !empty($this->fk_elementdet) && !empty($this->fk_expedition)) {
424 $this->checkQtyVsOrderLine($this->fk_elementdet, $this->qty, 0);
425 if (!empty($this->error)) {
426 $this->db->rollback();
427 return -5;
428 }
429 }
430
431 if (empty($this->rang)) {
432 $this->rang = 0;
433 }
434
435 // Rank to use
436 $ranktouse = $this->rang;
437 if ($ranktouse == -1) {
438 $rangmax = $this->line_max($this->fk_expedition);
439 $ranktouse = $rangmax + 1;
440 }
441
442 $sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet (";
443 $sql .= "fk_expedition";
444 $sql .= ", fk_entrepot";
445 $sql .= ", fk_elementdet";
446 $sql .= ", fk_parent";
447 $sql .= ", fk_product";
448 $sql .= ", element_type";
449 $sql .= ", qty";
450 $sql .= ", fk_unit";
451 $sql .= ", description";
452 $sql .= ", rang";
453 $sql .= ") VALUES (";
454 $sql .= ((int) $this->fk_expedition);
455 $sql .= ", ".(empty($this->entrepot_id) ? 'NULL' : ((int) $this->entrepot_id));
456 $sql .= ", ".(empty($this->fk_elementdet) ? 'NULL' : ((int) $this->fk_elementdet));
457 $sql .= ", ".(empty($this->fk_parent) ? 'NULL' : ((int) $this->fk_parent));
458 $sql .= ", ".(empty($this->fk_product) ? 'NULL' : ((int) $this->fk_product));
459 $sql .= ", '".(empty($this->element_type) ? 'order' : $this->db->escape($this->element_type))."'";
460 $sql .= ", ".price2num($this->qty, 'MS');
461 $sql .= ", ".((int) $this->fk_unit);
462 $sql .= ", '".(empty($this->description) ? '' : $this->db->escape($this->description))."'";
463 $sql .= ", ".((int) $ranktouse);
464 $sql .= ")";
465
466 dol_syslog(get_class($this)."::insert", LOG_DEBUG);
467 $resql = $this->db->query($sql);
468 if ($resql) {
469 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."expeditiondet");
470
471 if (!$error) {
472 $result = $this->insertExtraFields();
473 if ($result < 0) {
474 $error++;
475 }
476 }
477
478 if (!$error && !$notrigger) {
479 // Call trigger
480 $result = $this->call_trigger('LINESHIPPING_INSERT', $user);
481 if ($result < 0) {
482 $error++;
483 }
484 // End call triggers
485 }
486
487 if ($error) {
488 foreach ($this->errors as $errmsg) {
489 dol_syslog(__METHOD__.' '.$errmsg, LOG_ERR);
490 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
491 }
492 }
493 } else {
494 $error++;
495 }
496
497 if ($error) {
498 $this->db->rollback();
499 return -1;
500 } else {
501 $this->db->commit();
502 return $this->id;
503 }
504 }
505
514 public function findAllChild($line_id, &$list = array(), $mode = 0)
515 {
516 if ($line_id > 0) {
517 // find all child
518 $sql = "SELECT ed.rowid as child_line_id";
519 if ($mode == 1) {
520 $sql .= ", ed.fk_product";
521 $sql .= ", ed.fk_parent";
522 $sql .= ", " . $this->db->ifsql('eb.rowid IS NULL', 'ed.qty', 'eb.qty') . " as qty";
523 $sql .= ", " . $this->db->ifsql('eb.rowid IS NULL', 'ed.fk_entrepot', 'eb.fk_warehouse') . " as fk_warehouse";
524 $sql .= ", eb.batch, eb.eatby, eb.sellby";
525 }
526 $sql .= " FROM " . $this->db->prefix() . $this->table_element . " as ed";
527 $sql .= " LEFT JOIN " . $this->db->prefix() . "expeditiondet_batch as eb ON eb.fk_expeditiondet = " . ((int) $line_id);
528 $sql .= " WHERE ed.fk_parent = " . ((int) $line_id);
529 $sql .= $this->db->order('ed.fk_product,ed.rowid', 'ASC,ASC');
530
531 $resql = $this->db->query($sql);
532 if ($resql) {
533 while ($obj = $this->db->fetch_object($resql)) {
534 $child_line_id = (int) $obj->child_line_id;
535 if (!isset($list[$line_id])) {
536 $list[$line_id] = array();
537 }
538
539 if ($mode == 0) {
540 $list[$line_id][] = $child_line_id;
541 } elseif ($mode == 1) {
542 $line_obj = new stdClass();
543 $line_obj->rowid = $child_line_id;
544 $line_obj->fk_product = $obj->fk_product;
545 $line_obj->fk_parent = $obj->fk_parent;
546 $line_obj->qty = $obj->qty;
547 $line_obj->fk_warehouse = $obj->fk_warehouse;
548 $line_obj->batch = $obj->batch;
549 $line_obj->eatby = $obj->eatby;
550 $line_obj->sellby = $obj->sellby;
551 $line_obj->iskit = 0;
552 $line_obj->incdec = 0;
553 $list[$line_id][] = $line_obj;
554 }
555
556 $this->findAllChild($child_line_id, $list, $mode);
557 }
558 $this->db->free($resql);
559 } else {
560 $this->error = $this->db->lasterror();
561 $this->errors[] = $this->error;
562 dol_syslog(__METHOD__.' '.$this->error, LOG_ERR);
563 }
564 }
565
566 return 1;
567 }
568
576 public function delete($user = null, $notrigger = 0)
577 {
578 $error = 0;
579
580 $this->db->begin();
581
582 // virtual products : delete all children and batch
583 // Standalone dispatch allocations also belong to their source line.
584 if ((getDolGlobalInt('PRODUIT_SOUSPRODUITS') || $this->element_type == 'shipping') && !($this->fk_parent > 0)) {
585 // find all children
586 $line_id_list = array();
587 $result = $this->findAllChild($this->id, $line_id_list);
588 if ($result) {
589 $child_line_id_list = array_reverse($line_id_list, true);
590 foreach ($child_line_id_list as $child_line_id_arr) {
591 foreach ($child_line_id_arr as $child_line_id) {
592 // delete batch expedition line
593 if (isModEnabled('productbatch')) {
594 $sql = "DELETE FROM " . $this->db->prefix() . "expeditiondet_batch";
595 $sql .= " WHERE fk_expeditiondet = " . ((int) $child_line_id);
596 if (!$this->db->query($sql)) {
597 $error++;
598 $this->errors[] = $this->db->lasterror() . " - sql=$sql";
599 }
600 }
601
602 $sql = "DELETE FROM " . $this->db->prefix() . "expeditiondet";
603 $sql .= " WHERE rowid = " . ((int) $child_line_id);
604 if (!$this->db->query($sql)) {
605 $error++;
606 $this->errors[] = $this->db->lasterror() . " - sql=$sql";
607 }
608
609 if ($error) {
610 break;
611 }
612 }
613 if ($error) {
614 break;
615 }
616 }
617 } else {
618 $error++;
619 }
620 }
621
622 if (!$error) {
623 // delete batch expedition line
624 if (isModEnabled('productbatch')) {
625 $sql = "DELETE FROM ".$this->db->prefix()."expeditiondet_batch";
626 $sql .= " WHERE fk_expeditiondet = ".((int) $this->id);
627
628 if (!$this->db->query($sql)) {
629 $this->errors[] = $this->db->lasterror()." - sql=$sql";
630 $error++;
631 }
632 }
633
634 $sql = "DELETE FROM ".$this->db->prefix()."expeditiondet";
635 $sql .= " WHERE rowid = ".((int) $this->id);
636
637 if (!$error && $this->db->query($sql)) {
638 // Remove extrafields
639 if (!$error) {
640 $result = $this->deleteExtraFields();
641 if ($result < 0) {
642 $this->errors[] = $this->error;
643 $error++;
644 }
645 }
646 if (!$error && !$notrigger) {
647 // Call trigger
648 $result = $this->call_trigger('LINESHIPPING_DELETE', $user);
649 if ($result < 0) {
650 $this->errors[] = $this->error;
651 $error++;
652 }
653 // End call triggers
654 }
655 } else {
656 $this->errors[] = $this->db->lasterror()." - sql=$sql";
657 $error++;
658 }
659 }
660
661 if (!$error) {
662 $this->db->commit();
663 return 1;
664 } else {
665 foreach ($this->errors as $errmsg) {
666 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
667 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
668 }
669 $this->db->rollback();
670 return -1 * $error;
671 }
672 }
673
681 public function update($user = null, $notrigger = 0)
682 {
683 global $langs;
684 $error = 0;
685
686 dol_syslog(get_class($this)."::update id=$this->id, entrepot_id=$this->entrepot_id, product_id=$this->fk_product, qty=$this->qty");
687
688 $this->db->begin();
689
690 if (!empty($this->id) && empty($this->fk_elementdet)) {
691 $sql = "SELECT fk_elementdet FROM ".MAIN_DB_PREFIX."expeditiondet";
692 $sql .= " WHERE rowid = ".((int) $this->id);
693 $resql = $this->db->query($sql);
694 if ($resql) {
695 $obj = $this->db->fetch_object($resql);
696 if ($obj) {
697 $this->fk_elementdet = $obj->fk_elementdet;
698 }
699 }
700 }
701
702 if (getDolGlobalString('STOCK_EXPEDITION_NO_MORE_THAN_ORDER') && !empty($this->fk_elementdet)) {
703 $qty_to_check = $this->qty;
704 if (!empty($this->detail_batch)) {
705 if (is_array($this->detail_batch)) {
706 $qty_to_check = array_sum(array_column($this->detail_batch, 'qty'));
707 } else {
708 $qty_to_check = $this->detail_batch->qty;
709 }
710 }
711 $this->checkQtyVsOrderLine($this->fk_elementdet, $qty_to_check, $this->id);
712 if (!empty($this->error)) {
713 $this->db->rollback();
714 return -5;
715 }
716 }
717
718 // Clean parameters
719 if (empty($this->qty)) {
720 $this->qty = 0;
721 }
722 $qty = price2num($this->qty);
723 $fk_unit = $this->fk_unit;
724 $remainingQty = 0;
725 $batch = null;
726 $batch_id = 0;
727 $expedition_batch_id = 0;
728 $origin_id = $this->origin_id;
729 if ($origin_id > 0) {
730 if (is_array($this->detail_batch)) { // array of ExpeditionLineBatch
731 if (count($this->detail_batch) > 1) {
732 dol_syslog(get_class($this).'::update only possible for one batch', LOG_ERR);
733 $this->errors[] = 'ErrorBadParameters';
734 $error++;
735 } else {
736 $batch = $this->detail_batch[0]->batch;
737 $batch_id = $this->detail_batch[0]->fk_origin_stock;
738 $expedition_batch_id = $this->detail_batch[0]->id;
739 if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id) {
740 dol_syslog(get_class($this).'::update only possible for batch of same warehouse', LOG_ERR);
741 $this->errors[] = 'ErrorBadParameters';
742 $error++;
743 }
744 $qty = price2num($this->detail_batch[0]->qty);
745 }
746 } elseif (!empty($this->detail_batch)) {
747 $batch = $this->detail_batch->batch;
748 $batch_id = $this->detail_batch->fk_origin_stock;
749 $expedition_batch_id = $this->detail_batch->id;
750 if ($this->entrepot_id != $this->detail_batch->entrepot_id) {
751 dol_syslog(get_class($this).'::update only possible for batch of same warehouse', LOG_ERR);
752 $this->errors[] = 'ErrorBadParameters';
753 $error++;
754 }
755 $qty = price2num($this->detail_batch->qty);
756 }
757
758 // check parameters
759 if (!isset($this->id) || !isset($this->entrepot_id)) {
760 dol_syslog(get_class($this).'::update missing line id and/or warehouse id', LOG_ERR);
761 $langs->load('errors');
762 $this->errors[] = $langs->trans('ErrorMandatoryParametersNotProvided');
763 $error++;
764 return -1;
765 }
766
767 // update lot
768 if (!empty($batch) && isModEnabled('productbatch')) {
769 $batch_id_str = $batch_id ?? 'null';
770 dol_syslog(get_class($this)."::update expedition batch id=$expedition_batch_id, batch_id=$batch_id_str, batch=$batch");
771
772 if (empty($batch_id) || empty($this->fk_product)) {
773 dol_syslog(get_class($this).'::update missing fk_origin_stock (batch_id) and/or fk_product', LOG_ERR);
774 $langs->load('errors');
775 $this->errors[] = $langs->trans('ErrorMandatoryParametersNotProvided');
776 $error++;
777 }
778
779 // fetch remaining lot qty
780 $shipmentlinebatch = new ExpeditionLineBatch($this->db);
781 $lotArray = $shipmentlinebatch->fetchAll($this->id);
782 if (!$error && $lotArray < 0) {
783 $this->errors[] = $this->db->lasterror()." - ExpeditionLineBatch::fetchAll";
784 $error++;
785 } else {
786 // calculate new total line qty
787 foreach ($lotArray as $lot) {
788 if ($expedition_batch_id != $lot->id) {
789 $remainingQty += $lot->qty;
790 }
791 }
792 $qty += $remainingQty;
793
794 //fetch lot details
795 // fetch from product_lot
796 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
797 $lot = new Productlot($this->db);
798 if ($lot->fetch(0, $this->fk_product, $batch) < 0) {
799 $this->errors = array_merge($this->errors, $lot->errors);
800 $error++;
801 }
802 if (!$error && !empty($expedition_batch_id)) {
803 // delete lot expedition line
804 $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet_batch";
805 $sql .= " WHERE fk_expeditiondet = ".((int) $this->id);
806 $sql .= " AND rowid = ".((int) $expedition_batch_id);
807
808 if (!$this->db->query($sql)) {
809 $this->errors[] = $this->db->lasterror()." - sql=$sql";
810 $error++;
811 }
812 }
813 if (!$error && $this->detail_batch->qty > 0) {
814 // create lot expedition line
815 if (isset($lot->id)) {
816 $shipmentLot = new ExpeditionLineBatch($this->db);
817 $shipmentLot->batch = $lot->batch;
818 $shipmentLot->eatby = $lot->eatby;
819 $shipmentLot->sellby = $lot->sellby;
820 $shipmentLot->fk_warehouse = $this->detail_batch->entrepot_id;
821 $shipmentLot->qty = $this->detail_batch->qty;
822 $shipmentLot->fk_origin_stock = (int) $batch_id;
823 if ($shipmentLot->create($this->id) < 0) {
824 $this->errors = $shipmentLot->errors;
825 $error++;
826 }
827 }
828 }
829 }
830 }
831 }
832 if (!$error) {
833 // update line
834 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
835 $sql .= " fk_entrepot = ".($this->entrepot_id > 0 ? ((int) $this->entrepot_id) : 'null');
836 $sql .= " , qty = ".((float) price2num($qty, 'MS'));
837 $sql .= " , fk_unit = ".((int) $this->fk_unit);
838 $sql .= " WHERE rowid = ".((int) $this->id);
839
840 if (!$this->db->query($sql)) {
841 $this->errors[] = $this->db->lasterror()." - sql=$sql";
842 $error++;
843 }
844 }
845
846 if (!$error) {
847 $result = $this->insertExtraFields();
848 if ($result < 0) {
849 $this->errors[] = $this->error;
850 $error++;
851 }
852 }
853
854 if (!$error && !$notrigger) {
855 // Call trigger
856 $result = $this->call_trigger('LINESHIPPING_MODIFY', $user);
857 if ($result < 0) {
858 $this->errors[] = $this->error;
859 $error++;
860 }
861 // End call triggers
862 }
863 if (!$error) {
864 $this->db->commit();
865 return 1;
866 } else {
867 foreach ($this->errors as $errmsg) {
868 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
869 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
870 }
871 $this->db->rollback();
872 return -1 * $error;
873 }
874 }
875
885 private function checkQtyVsOrderLine(int $fk_elementdet, float $qty, int $exclude_line_id): bool
886 {
887 global $langs;
888
889 // Ordered quantity on the source order line
890 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
891 $orderline = new OrderLine($this->db);
892 if ($orderline->fetch($fk_elementdet) <= 0) {
893 return true; // Order line not found, skip check
894 }
895 if ($orderline->product_type == 9) {
896 return true; // Skip check for title/separator lines, they have no deliverable quantity
897 }
898 $qty_ordered = (float) $orderline->qty;
899
900 // Quantity already shipped on other shipment lines
901 $sql = "SELECT COALESCE(SUM(ed.qty), 0) as qty_shipped";
902 $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
903 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expedition as e ON e.rowid = ed.fk_expedition";
904 $sql .= " WHERE ed.fk_elementdet = ".((int) $fk_elementdet);
905 $sql .= " AND e.fk_statut >= 0"; // exclude only deleted ones
906 if ($exclude_line_id > 0) {
907 $sql .= " AND ed.rowid != ".((int) $exclude_line_id); // exclude current line being edited
908 }
909
910 $resql = $this->db->query($sql);
911 if (!$resql) {
912 return true;
913 }
914 $obj = $this->db->fetch_object($resql);
915 $qty_already_shipped = $obj ? (float) $obj->qty_shipped : 0;
916
917 $qty_remaining = $qty_ordered - $qty_already_shipped;
918
919 if ($qty > $qty_remaining) {
920 $langs->load('errors');
921 $product_ref = !empty($orderline->product_ref) ? $orderline->product_ref : $orderline->desc;
922 $this->error = $langs->trans('ErrorExpeditionQtyTooHigh', $qty, max(0, $qty_remaining), $product_ref);
923 return false;
924 }
925
926 return true;
927 }
928}
deleteExtraFields()
Delete all extra fields values for the current object.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
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 lines of shipment.
insert($user=null, $notrigger=0)
Insert line into database.
fetch($rowid)
Load line expedition.
findAllChild($line_id, &$list=array(), $mode=0)
Find all children.
__construct($db)
Constructor.
checkQtyVsOrderLine(int $fk_elementdet, float $qty, int $exclude_line_id)
Check that qty to ship does not exceed remaining qty on order line.
update($user=null, $notrigger=0)
Update a line in database.
CRUD class for batch number management within shipment.
Class to manage order lines.
Class with list of lots and properties.
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, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.