dolibarr 24.0.3
reception.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.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-2017 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-2020 Francis Appels <francis.appels@yahoo.com>
11 * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
12 * Copyright (C) 2016-2022 Ferran Marcet <fmarcet@2byte.es>
13 * Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
14 * Copyright (C) 2022-2025 Frédéric France <frederic.france@free.fr>
15 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
16 * Copyright (C) 2025 Nick Fragoulis
17 * Copyright (C) 2026 Mathieu Moulin <mathieu@iprospective.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/commonobject.class.php';
40require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php";
41require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
42require_once DOL_DOCUMENT_ROOT.'/reception/class/receptionlinebatch.class.php';
43if (isModEnabled("propal")) {
44 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
45}
46if (isModEnabled('order')) {
47 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
48}
49
50
55{
56 use CommonIncoterm;
57
62 public $TRIGGER_PREFIX = 'RECEPTION'; // to be overridden in child class implementations, i.e. 'BILL', 'TASK', 'PROPAL', etc.
63
67 public $code = "";
68
72 public $element = "reception";
73
77 public $fk_element = "fk_reception";
78
82 public $table_element = "reception";
83
87 public $table_element_line = "receptiondet_batch";
88
92 public $picto = 'dollyrevert';
93
97 public $socid;
101 public $ref_supplier;
102
106 public $entrepot_id;
110 public $tracking_number;
114 public $tracking_url;
118 public $billed;
119
123 public $weight;
127 public $trueWeight;
131 public $weight_units;
135 public $trueWidth;
139 public $width_units;
143 public $trueHeight;
147 public $height_units;
151 public $trueDepth;
155 public $depth_units;
159 public $trueSize;
163 public $size_units;
167 public $user_author_id;
168
172 public $date_delivery;
173
179 public $date;
180
184 public $date_reception;
185
189 public $date_valid;
190
194 public $fk_user_author;
195
199 public $fk_user_valid;
200
204 public $meths;
208 public $listmeths; // List of carriers
209
213 public $lines = array();
214
215
220 public $detail_batch;
221
222 const STATUS_CANCELED = -1;
223 const STATUS_DRAFT = 0;
224 const STATUS_VALIDATED = 1;
225 const STATUS_CLOSED = 2;
226
227
233 public function __construct($db)
234 {
235 $this->db = $db;
236
237 $this->ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
238 $this->isextrafieldmanaged = 1;
239 }
240
247 public function getNextNumRef($soc)
248 {
249 global $langs, $conf;
250 $langs->load("receptions");
251
252 if (getDolGlobalString('RECEPTION_ADDON_NUMBER')) {
253 $mybool = false;
254
255 $file = getDolGlobalString('RECEPTION_ADDON_NUMBER') . ".php";
256 $classname = getDolGlobalString('RECEPTION_ADDON_NUMBER');
257
258 // Include file with class
259 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
260
261 foreach ($dirmodels as $reldir) {
262 $dir = dol_buildpath($reldir."core/modules/reception/");
263
264 // Load file with numbering class (if found)
265 $mybool = ((bool) @include_once $dir.$file) || $mybool;
266 }
267
268 if (!$mybool) {
269 dol_print_error(null, "Failed to include file ".$file);
270 return '';
271 }
272
273 $obj = new $classname();
274 '@phan-var-force ModelNumRefReception $obj';
277 $numref = $obj->getNextValue($soc, $this);
278
279 if ($numref != "") {
280 return $numref;
281 } else {
282 dol_print_error($this->db, get_class($this)."::getNextNumRef ".$obj->error);
283 return "";
284 }
285 } else {
286 print $langs->trans("Error")." ".$langs->trans("Error_RECEPTION_ADDON_NUMBER_NotDefined");
287 return "";
288 }
289 }
290
298 public function create($user, $notrigger = 0)
299 {
300 global $conf;
301
302 $now = dol_now();
303
304 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
305 $error = 0;
306
307 // Clean parameters
308 $this->tracking_number = dol_sanitizeFileName($this->tracking_number);
309 if (empty($this->fk_project)) {
310 $this->fk_project = 0;
311 }
312 if (empty($this->weight_units)) {
313 $this->weight_units = 0;
314 }
315 if (empty($this->size_units)) {
316 $this->size_units = 0;
317 }
318 if (empty($this->date_creation)) {
319 $this->date_creation = $now;
320 }
321
322 $this->entity = setEntity($this);
323
324 $this->user = $user;
325
326 $this->db->begin();
327
328 $sql = "INSERT INTO ".MAIN_DB_PREFIX."reception (";
329 $sql .= "ref";
330 $sql .= ", entity";
331 $sql .= ", ref_supplier";
332 $sql .= ", date_creation";
333 $sql .= ", fk_user_author";
334 $sql .= ", date_reception";
335 $sql .= ", date_delivery";
336 $sql .= ", fk_soc";
337 $sql .= ", fk_projet";
338 $sql .= ", fk_shipping_method";
339 $sql .= ", tracking_number";
340 $sql .= ", weight";
341 $sql .= ", size";
342 $sql .= ", width";
343 $sql .= ", height";
344 $sql .= ", weight_units";
345 $sql .= ", size_units";
346 $sql .= ", note_private";
347 $sql .= ", note_public";
348 $sql .= ", model_pdf";
349 $sql .= ", fk_incoterms, location_incoterms";
350 $sql .= ") VALUES (";
351 $sql .= "'(PROV)'";
352 $sql .= ", ".((int) $this->entity);
353 $sql .= ", ".($this->ref_supplier ? "'".$this->db->escape($this->ref_supplier)."'" : "null");
354 $sql .= ", '".$this->db->idate($this->date_creation)."'";
355 $sql .= ", ".((int) $user->id);
356 $sql .= ", ".($this->date_reception > 0 ? "'".$this->db->idate($this->date_reception)."'" : "null");
357 $sql .= ", ".($this->date_delivery > 0 ? "'".$this->db->idate($this->date_delivery)."'" : "null");
358 $sql .= ", ".($this->socid > 0 ? ((int) $this->socid) : "null");
359 $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : "null");
360 $sql .= ", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) : "null");
361 $sql .= ", '".$this->db->escape($this->tracking_number)."'";
362 $sql .= ", ".(is_null($this->weight) ? "NULL" : ((float) $this->weight));
363 $sql .= ", ".(is_null($this->trueDepth) ? "NULL" : ((float) $this->trueDepth));
364 $sql .= ", ".(is_null($this->trueWidth) ? "NULL" : ((float) $this->trueWidth));
365 $sql .= ", ".(is_null($this->trueHeight) ? "NULL" : ((float) $this->trueHeight));
366 $sql .= ", ".((int) $this->weight_units);
367 $sql .= ", ".((int) $this->size_units);
368 $sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
369 $sql .= ", ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
370 $sql .= ", ".(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null");
371 $sql .= ", ".(int) $this->fk_incoterms;
372 $sql .= ", '".$this->db->escape($this->location_incoterms)."'";
373 $sql .= ")";
374
375 dol_syslog(get_class($this)."::create", LOG_DEBUG);
376
377 $resql = $this->db->query($sql);
378
379 if ($resql) {
380 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."reception");
381
382 // update ref
383 $initialref = '(PROV'.$this->id.')';
384 if (!empty($this->ref)) {
385 $initialref = $this->ref;
386 }
387
388 $sql = "UPDATE ".MAIN_DB_PREFIX."reception";
389 $sql .= " SET ref = '".$this->db->escape($initialref)."'";
390 $sql .= " WHERE rowid = ".((int) $this->id);
391
392 dol_syslog(get_class($this)."::create", LOG_DEBUG);
393 if ($this->db->query($sql)) {
394 // Insert of lines
395 $num = count($this->lines);
396 for ($i = 0; $i < $num; $i++) {
397 $this->lines[$i]->fk_reception = $this->id;
398
399 if ($this->lines[$i]->create($user) <= 0) {
400 $this->setErrorsFromObject($this->lines[$i]);
401 $error++;
402 }
403 }
404
405 if (!$error && $this->id && $this->origin_id) {
406 $ret = $this->add_object_linked();
407 if (!$ret) {
408 $error++;
409 }
410 }
411
412 // Create extrafields
413 if (!$error) {
414 $result = $this->insertExtraFields();
415 if ($result < 0) {
416 $error++;
417 }
418 }
419
420 if (!$error && !$notrigger) {
421 // Call trigger
422 $result = $this->call_trigger('RECEPTION_CREATE', $user);
423 if ($result < 0) {
424 $error++;
425 }
426 // End call triggers
427 }
428
429 if (!$error) {
430 $this->db->commit();
431 return $this->id;
432 } else {
433 foreach ($this->errors as $errmsg) {
434 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
435 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
436 }
437 $this->db->rollback();
438 return -1 * $error;
439 }
440 } else {
441 $error++;
442 $this->error = $this->db->lasterror()." - sql=$sql";
443 $this->db->rollback();
444 return -2;
445 }
446 } else {
447 $error++;
448 $this->error = $this->db->error()." - sql=$sql";
449 $this->db->rollback();
450 return -1;
451 }
452 }
453
454 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
467 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = [], $parent_line_id = 0, $product_id = 0)
468 {
469 //phpcs:enable
470 global $user;
471
472 $receptionline = new ReceptionLineBatch($this->db);
473 $receptionline->fk_reception = $this->id;
474 $receptionline->entrepot_id = $entrepot_id;
475 $receptionline->fk_elementdet = $origin_line_id;
476 $receptionline->element_type = $this->origin;
477 $receptionline->fk_parent = $parent_line_id;
478 $receptionline->fk_product = $product_id;
479 $receptionline->qty = $qty;
480 $receptionline->rang = $rang;
481 $receptionline->array_options = $array_options;
482
483 if (!($receptionline->fk_product > 0)) {
484 $order_line = new CommandeFournisseurLigne($this->db);
485 $order_line->fetch($receptionline->fk_elementdet);
486 $receptionline->fk_product = $order_line->fk_product;
487 }
488
489 if (($lineId = $receptionline->insert($user)) < 0) {
490 $this->errors[] = $receptionline->error;
491 }
492 return $lineId;
493 }
494
503 public function fetch($id, $ref = '', $ref_ext = '')
504 {
505 // Check parameters
506 if (empty($id) && empty($ref) && empty($ref_ext)) {
507 return -1;
508 }
509
510 $sql = "SELECT e.rowid, e.entity, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.fk_user_author, e.fk_statut as status, e.fk_projet as fk_project, e.billed";
511 $sql .= ", e.fk_user_valid";
512 $sql .= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
513 $sql .= ", e.date_reception as date_reception, e.model_pdf, e.date_delivery, e.date_valid";
514 $sql .= ", e.fk_shipping_method, e.tracking_number";
515 $sql .= ", el.fk_source as origin_id, el.sourcetype as origin";
516 $sql .= ", e.note_private, e.note_public";
517 $sql .= ', e.fk_incoterms, e.location_incoterms';
518 $sql .= ', i.libelle as label_incoterms';
519 $sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
520 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."' AND el.sourcetype = 'order_supplier'";
521 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid';
522
523 if ($id) {
524 $sql .= " WHERE e.rowid = ".((int) $id);
525 } else {
526 $sql .= " WHERE e.entity IN (".getEntity('reception').")";
527 if ($ref) {
528 $sql .= " AND e.ref = '".$this->db->escape($ref)."'";
529 } elseif ($ref_ext) {
530 $sql .= " AND e.ref_ext = '".$this->db->escape($ref_ext)."'";
531 }
532 }
533
534 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
535 $result = $this->db->query($sql);
536 if ($result) {
537 if ($this->db->num_rows($result)) {
538 $obj = $this->db->fetch_object($result);
539
540 $this->id = $obj->rowid;
541 $this->entity = $obj->entity;
542 $this->ref = $obj->ref;
543 $this->socid = $obj->socid;
544 $this->ref_supplier = $obj->ref_supplier;
545 $this->ref_ext = $obj->ref_ext;
546 $this->statut = $obj->status;
547 $this->status = $obj->status;
548 $this->billed = $obj->billed;
549 $this->fk_project = $obj->fk_project;
550 $this->user_author_id = $obj->fk_user_author;
551 $this->fk_user_author = $obj->fk_user_author;
552 $this->fk_user_valid = $obj->fk_user_valid;
553 $this->date_creation = $this->db->jdate($obj->date_creation);
554 $this->date = $this->db->jdate($obj->date_reception); // TODO deprecated
555 $this->date_reception = $this->db->jdate($obj->date_reception); // Date real
556 $this->date_delivery = $this->db->jdate($obj->date_delivery); // Date planned
557 $this->date_valid = $this->db->jdate($obj->date_valid); // Date validation
558 $this->model_pdf = $obj->model_pdf;
559 $this->shipping_method_id = $obj->fk_shipping_method;
560 $this->tracking_number = $obj->tracking_number;
561 $this->origin = ($obj->origin ? $obj->origin : ($obj->origin_id > 0 ? 'commande' : '')); // For compatibility. A standalone reception has no origin.
562 $this->origin_type = ($obj->origin ? $obj->origin : ($obj->origin_id > 0 ? 'commande' : '')); // For compatibility. A standalone reception has no origin.
563 $this->origin_id = $obj->origin_id;
564
565 $this->trueWeight = $obj->weight;
566 $this->weight_units = $obj->weight_units;
567
568 $this->trueWidth = $obj->width;
569 $this->width_units = $obj->size_units;
570 $this->trueHeight = $obj->height;
571 $this->height_units = $obj->size_units;
572 $this->trueDepth = $obj->size;
573 $this->depth_units = $obj->size_units;
574
575 $this->note_public = $obj->note_public;
576 $this->note_private = $obj->note_private;
577
578 // A denormalized value
579 $this->trueSize = $obj->size."x".$obj->width."x".$obj->height;
580 $this->size_units = $obj->size_units;
581
582 //Incoterms
583 $this->fk_incoterms = $obj->fk_incoterms;
584 $this->location_incoterms = $obj->location_incoterms;
585 $this->label_incoterms = $obj->label_incoterms;
586
587 $this->db->free($result);
588
589 //$file = $conf->reception->dir_output."/".get_exdir(0, 0, 0, 1, $this, 'reception')."/".$this->id.".pdf";
590 //$this->pdf_filename = $file;
591
592 // Tracking url
593 $this->getUrlTrackingStatus($obj->tracking_number);
594
595 /*
596 * Thirdparty
597 */
598 $result = $this->fetch_thirdparty();
599
600
601 // Retrieve all extrafields for reception
602 // fetch optionals attributes and labels
603 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
604 $extrafields = new ExtraFields($this->db);
605 $extrafields->fetch_name_optionals_label($this->table_element, true);
606 $this->fetch_optionals();
607
608 /*
609 * Lines
610 */
611 if (empty($obj->origin_id)) {
612 $result = $this->fetch_lines_free();
613 } else {
614 $result = $this->fetch_lines();
615 }
616 if ($result < 0) {
617 return -3;
618 }
619
620 return 1;
621 } else {
622 dol_syslog(get_class($this).'::Fetch no reception found', LOG_ERR);
623 $this->error = 'Reception with id '.$id.' not found';
624 return 0;
625 }
626 } else {
627 $this->error = $this->db->error();
628 return -1;
629 }
630 }
631
639 public function valid($user, $notrigger = 0)
640 {
641 global $conf, $langs;
642
643 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
644
645 dol_syslog(get_class($this)."::valid");
646
647 // Protection
648 if ($this->statut) {
649 dol_syslog(get_class($this)."::valid no draft status", LOG_WARNING);
650 return 0;
651 }
652
653 if (!((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer'))
654 || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate')))) {
655 $this->error = 'Permission denied';
656 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
657 return -1;
658 }
659
660 $this->db->begin();
661
662 $error = 0;
663
664 // Define new ref
665 $soc = new Societe($this->db);
666 $soc->fetch($this->socid);
667
668
669 // Define new ref
670 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
671 $numref = $this->getNextNumRef($soc);
672 } else {
673 $numref = (string) $this->ref;
674 }
675
676 $this->newref = dol_sanitizeFileName($numref);
677
678 $now = dol_now();
679
680 // Validate
681 $sql = "UPDATE ".MAIN_DB_PREFIX."reception SET";
682 $sql .= " ref='".$this->db->escape($numref)."'";
683 $sql .= ", fk_statut = 1";
684 $sql .= ", date_valid = '".$this->db->idate($now)."'";
685 $sql .= ", fk_user_valid = ".((int) $user->id);
686 $sql .= " WHERE rowid = ".((int) $this->id);
687 dol_syslog(get_class($this)."::valid update reception", LOG_DEBUG);
688 $resql = $this->db->query($sql);
689 if (!$resql) {
690 $this->error = $this->db->lasterror();
691 $error++;
692 }
693
694 // If stock increment is done on reception (recommended choice)
695 if (!$error && isModEnabled('stock') && getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION')) {
696 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
697
698 $langs->load("agenda");
699
700 // Loop on each product line to add a stock movement
701 // TODO in future, reception lines may not be linked to order line
702 $sql = "SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
703 $sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
704 $sql .= " ed.eatby, ed.sellby, ed.batch,";
705 $sql .= " ed.fk_elementdet, ed.cost_price";
706 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
707 $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed";
708 $sql .= " WHERE ed.fk_reception = ".((int) $this->id);
709 $sql .= " AND cd.rowid = ed.fk_elementdet";
710
711 dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
712 $resql = $this->db->query($sql);
713 if ($resql) {
714 $cpt = $this->db->num_rows($resql);
715 for ($i = 0; $i < $cpt; $i++) {
716 $obj = $this->db->fetch_object($resql);
717
718 $qty = $obj->qty;
719
720 if ($qty == 0 || ($qty < 0 && !getDolGlobalInt('RECEPTION_ALLOW_NEGATIVE_QTY'))) {
721 continue;
722 }
723
724 dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid);
725
726 //var_dump($this->lines[$i]);
727 $mouvS = new MouvementStock($this->db);
728 $mouvS->origin = &$this;
729 $mouvS->setOrigin($this->element, $this->id, $obj->fk_elementdet, $obj->rowid);
730
731 if (empty($obj->batch)) {
732 // line without batch detail
733
734 // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record.
735 $inventorycode = '';
736 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionValidatedInDolibarr", $numref), '', '', '', '', 0, $inventorycode);
737
738 if (intval($result) < 0) {
739 $error++;
740 $this->setErrorsFromObject($mouvS);
741 break;
742 }
743 } else {
744 // line with batch detail
745
746 // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record.
747 // Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version)
748 $inventorycode = '';
749 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, '', 0, $inventorycode);
750
751 if (intval($result) < 0) {
752 $error++;
753 $this->setErrorsFromObject($mouvS);
754 break;
755 }
756 }
757 }
758 } else {
759 $this->db->rollback();
760 $this->error = $this->db->error();
761 return -2;
762 }
763 }
764
765 if (!$error && $this->origin_id > 0) {
766 // Change status of purchase order to "reception in process" or "totally received"
767 $status = $this->getStatusDispatch();
768 if ($status < 0) {
769 $error++;
770 } else {
771 $trigger_key = '';
772 if ($this->origin_object instanceof CommandeFournisseur && $status == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) {
773 $ret = $this->origin_object->Livraison($user, dol_now(), 'tot', '');
774 if ($ret < 0) {
775 $error++;
776 $this->errors = array_merge($this->errors, $this->origin_object->errors);
777 }
778 } else {
779 $ret = $this->setStatut($status, $this->origin_id, 'commande_fournisseur', $trigger_key);
780 if ($ret < 0) {
781 $error++;
782 }
783 }
784 }
785 }
786
787 if (!$error && !$notrigger) {
788 // Call trigger
789 $result = $this->call_trigger('RECEPTION_VALIDATE', $user);
790 if ($result < 0) {
791 $error++;
792 }
793 // End call triggers
794 }
795
796 if (!$error) {
797 $this->oldref = $this->ref;
798
799 // Rename directory if dir was a temporary ref
800 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
801 // Now we rename also files into index
802 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'reception/".$this->db->escape($this->newref)."'";
803 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'reception/".$this->db->escape($this->ref)."' AND entity = ".((int) $conf->entity);
804 $resql = $this->db->query($sql);
805 if (!$resql) {
806 $error++;
807 $this->error = $this->db->lasterror();
808 }
809 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'reception/".$this->db->escape($this->newref)."'";
810 $sql .= " WHERE filepath = 'reception/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
811 $resql = $this->db->query($sql);
812 if (!$resql) {
813 $error++;
814 $this->error = $this->db->lasterror();
815 }
816
817 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
818 $oldref = dol_sanitizeFileName($this->ref);
819 $newref = dol_sanitizeFileName($numref);
820 $dirsource = $conf->reception->dir_output.'/'.$oldref;
821 $dirdest = $conf->reception->dir_output.'/'.$newref;
822 if (!$error && file_exists($dirsource)) {
823 dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest);
824
825 if (@rename($dirsource, $dirdest)) {
826 dol_syslog("Rename ok");
827 // Rename docs starting with $oldref with $newref
828 $listoffiles = dol_dir_list($conf->reception->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
829 foreach ($listoffiles as $fileentry) {
830 $dirsource = $fileentry['name'];
831 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
832 $dirsource = $fileentry['path'].'/'.$dirsource;
833 $dirdest = $fileentry['path'].'/'.$dirdest;
834 @rename($dirsource, $dirdest);
835 }
836 }
837 }
838 }
839 }
840
841 // Set new ref and current status
842 if (!$error) {
843 $this->ref = $numref;
844 $this->statut = self::STATUS_VALIDATED;
845 $this->status = self::STATUS_VALIDATED;
846 }
847
848 if (!$error) {
849 $this->db->commit();
850 return 1;
851 } else {
852 foreach ($this->errors as $errmsg) {
853 dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR);
854 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
855 }
856 $this->db->rollback();
857 return -1 * $error;
858 }
859 }
860
866 public function getStatusDispatch()
867 {
868 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
869 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
870
872
873 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin == 'order_supplier' || $this->origin == 'commandeFournisseur')) {
874 if (empty($this->origin_object)) {
875 $this->fetch_origin();
876 if ($this->origin_object instanceof CommonObject && empty($this->origin_object->lines)) {
877 $res = $this->origin_object->fetch_lines();
878 $this->commandeFournisseur = null; // deprecated
879 if ($res < 0) {
880 return $res;
881 }
882 } elseif ($this->origin_object instanceof CommandeFournisseur && empty($this->origin_object->lines)) {
883 $res = $this->origin_object->fetch_lines();
884 $this->commandeFournisseur = $this->origin_object; // deprecated
885 if ($res < 0) {
886 return $res;
887 }
888 }
889 }
890
891 $qty_received = array();
892 $qty_wished = array();
893
894 $supplierorderdispatch = new CommandeFournisseurDispatch($this->db);
895 $filter = array('t.fk_element' => $this->origin_id);
896 if (getDolGlobalInt('SUPPLIER_ORDER_USE_DISPATCH_STATUS')) {
897 $filter['t.status'] = 1; // Restrict to lines with status validated
898 }
899
900 $ret = $supplierorderdispatch->fetchAll('', '', 0, 0, $filter);
901 if ($ret < 0) {
902 $this->setErrorsFromObject($supplierorderdispatch);
903 return $ret;
904 } else {
905 // Lines of draft receptions are not received yet
906 $draft_lines = array();
907 $sql = "SELECT rb.rowid FROM ".MAIN_DB_PREFIX."receptiondet_batch as rb";
908 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."reception as r ON r.rowid = rb.fk_reception";
909 $sql .= " WHERE rb.fk_element = ".((int) $this->origin_id);
910 $sql .= " AND r.fk_statut = ".self::STATUS_DRAFT;
911 $resql = $this->db->query($sql);
912 if (!$resql) {
913 $this->error = $this->db->lasterror();
914 return -1;
915 }
916 while ($obj = $this->db->fetch_object($resql)) {
917 $draft_lines[(int) $obj->rowid] = (int) $obj->rowid;
918 }
919 $this->db->free($resql);
920
921 // build array with quantity received by product in all supplier orders (origin)
922 foreach ($supplierorderdispatch->lines as $dispatch_line) {
923 if (isset($draft_lines[(int) $dispatch_line->id])) {
924 continue;
925 }
926 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
927 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
928 } else {
929 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
930 }
931 }
932
933 // qty wished in origin (purchase order, ...)
934 foreach ($this->origin_object->lines as $origin_line) {
935 // exclude lines not qualified for reception
936 if (($origin_line->product_type > 0 && (!getDolGlobalInt('STOCK_SUPPORTS_SERVICES') || empty($origin_line->stockable_product))) || $origin_line->product_type > 1) {
937 continue;
938 }
939 if (array_key_exists($origin_line->fk_product, $qty_wished)) {
940 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
941 } else {
942 $qty_wished[$origin_line->fk_product] = $origin_line->qty;
943 }
944 }
945
946 // compare array
947 $diff_array = array_diff_assoc($qty_received, $qty_wished); // Warning: $diff_array is done only on common keys.
948 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
949 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
950
951 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) { // no diff => mean everything is received
953 } elseif (getDolGlobalInt('SUPPLIER_ORDER_MORE_THAN_WISHED')) {
954 // set totally received if more products received than ordered
955 $close = 0;
956
957 if (count($diff_array) > 0) {
958 // there are some difference between the two arrays
959 // scan the array of results
960 foreach ($diff_array as $key => $value) {
961 // if the quantity delivered is greater or equal to ordered quantity @phan-suppress-next-line PhanTypeInvalidDimOffset
962 if ($qty_received[$key] >= $qty_wished[$key]) {
963 $close++;
964 }
965 }
966 }
967
968 if ($close == count($diff_array)) {
969 // all the products are received equal or more than the ordered quantity
971 }
972 }
973 }
974 }
975
976 return $status;
977 }
978
995 public function addline($entrepot_id, $id, $qty, $array_options = [], $comment = '', $eatby = null, $sellby = null, $batch = '', $cost_price = 0)
996 {
997 global $conf, $langs, $user;
998
999 $num = count($this->lines);
1000 $line = new CommandeFournisseurDispatch($this->db);
1001
1002 $line->fk_entrepot = $entrepot_id;
1003 $line->fk_commandefourndet = $id;
1004 $line->qty = $qty;
1005
1006 $supplierorderline = new CommandeFournisseurLigne($this->db);
1007 $result = $supplierorderline->fetch($id);
1008 if ($result <= 0) {
1009 $this->setErrorsFromObject($supplierorderline);
1010 return -1;
1011 }
1012
1013 $fk_product = 0;
1014 if (isModEnabled('stock') && !empty($supplierorderline->fk_product)) {
1015 $fk_product = $supplierorderline->fk_product;
1016
1017 if (!($entrepot_id > 0) && !getDolGlobalInt('STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
1018 $langs->load("errors");
1019 $this->error = $langs->trans("ErrorWarehouseRequiredIntoReceptionLine");
1020 return -1;
1021 }
1022 }
1023
1024 // Check batch is set
1025 $product = new Product($this->db);
1026 $product->fetch($fk_product);
1027 if (isModEnabled('productbatch')) {
1028 $langs->load("errors");
1029 if (!empty($product->status_batch) && empty($batch)) {
1030 $this->error = $langs->trans('ErrorProductNeedBatchNumber', $product->ref);
1031 return -1;
1032 } elseif (empty($product->status_batch) && !empty($batch)) {
1033 $this->error = $langs->trans('ErrorProductDoesNotNeedBatchNumber', $product->ref);
1034 return -1;
1035 }
1036
1037 // check sell-by / eat-by date is mandatory
1038 $errorMsgArr = Productlot::checkSellOrEatByMandatoryFromProductAndDates($product, $sellby, $eatby);
1039 if (!empty($errorMsgArr)) {
1040 $errorMessage = '<b>' . $product->ref . '</b> : ';
1041 $errorMessage .= '<ul>';
1042 foreach ($errorMsgArr as $errorMsg) {
1043 $errorMessage .= '<li>' . $errorMsg . '</li>';
1044 }
1045 $errorMessage .= '</ul>';
1046 $this->error = $errorMessage;
1047 return -1;
1048 }
1049 }
1050 unset($product);
1051
1052 // extrafields
1053 $line->array_options = $supplierorderline->array_options;
1054 if (!getDolGlobalInt('MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1055 foreach ($array_options as $key => $value) {
1056 $line->array_options[$key] = $value;
1057 }
1058 }
1059
1060 $line->fk_product = $fk_product;
1061 $line->fk_commande = $supplierorderline->fk_commande;
1062 $line->fk_user = $user->id;
1063 $line->comment = $comment;
1064 $line->batch = $batch;
1065 $line->eatby = $eatby;
1066 $line->sellby = $sellby;
1067 $line->status = 1;
1068 $line->cost_price = $cost_price;
1069 $line->fk_reception = $this->id;
1070
1071 $this->lines[$num] = $line;
1072
1073 return $num;
1074 }
1075
1088 public function addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $array_options = [])
1089 {
1090 global $mysoc, $langs, $user;
1091
1092 if ($this->status == self::STATUS_DRAFT) {
1093 if (empty($rang)) {
1094 $rang = 0;
1095 }
1096
1097 $qty = (float) price2num($qty);
1098
1099 $this->db->begin();
1100
1101 // Rank to use
1102 $ranktouse = $rang;
1103 if ($ranktouse == -1) {
1104 $rangmax = $this->line_max($this->fk_reception);
1105 $ranktouse = $rangmax + 1;
1106 }
1107
1108 // Insert line
1109 $this->line = new ReceptionLineBatch($this->db);
1110 $this->line->fk_reception = $this->id;
1111 $this->line->element_type = $element_type;
1112 $this->line->fk_product = $fk_product;
1113 $this->line->description = $description;
1114
1115 $this->line->qty = (float) $qty;
1116 $this->line->fk_unit = $fk_unit;
1117 $this->line->rang = $ranktouse;
1118
1119 if (is_array($array_options) && count($array_options) > 0) {
1120 $this->line->array_options = $array_options;
1121 }
1122
1123 $result = $this->line->insert($user);
1124 if ($result > 0) {
1125 if (!isset($this->context['createfromclone'])) {
1126 if ($this->fk_reception) {
1127 $this->line_order(true, 'DESC');
1128 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
1129 $linecount = count($this->lines);
1130 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
1131 $this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1);
1132 }
1133 }
1134 $this->lines[] = $this->line;
1135 }
1136
1137 $this->db->commit();
1138 return $this->line->id;
1139 } else {
1140 $this->error = $this->line->error;
1141 dol_syslog(get_class($this)."::addlinefree error=".$this->error, LOG_ERR);
1142 $this->db->rollback();
1143 return -2;
1144 }
1145 } else {
1146 dol_syslog(get_class($this)."::addlinefree status of reception must be Draft to allow use of ->addlinefree()", LOG_ERR);
1147 return -3;
1148 }
1149 }
1150
1165 public function updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $notrigger, $array_options = array())
1166 {
1167 global $mysoc, $langs, $user;
1168
1169 if ($this->statut == self::STATUS_DRAFT) {
1170 $this->db->begin();
1171
1172 if (empty($qty)) {
1173 $qty = 0;
1174 }
1175 if (empty($rang)) {
1176 $rang = 0;
1177 }
1178
1179 $qty = (float) $qty;
1180 $description = trim((string) $description);
1181
1182 // Fetch current line from the database and then clone the object and set it in $oldline property
1183 $line = new ReceptionLineBatch($this->db);
1184
1185 $line->fetch($rowid);
1186 $line->fetch_optionals();
1187
1188 if (!empty($line->fk_product)) {
1189 $product = new Product($this->db);
1190 $result = $product->fetch($line->fk_product);
1191 $product_type = $product->type;
1192 }
1193
1194 $staticline = clone $line;
1195
1196 $line->oldline = $staticline;
1197 $this->line = $line;
1198 $this->line->context = $this->context;
1199 $this->line->rang = $rang;
1200 $this->line->fk_reception = $this->id;
1201 $this->line->element_type = $element_type;
1202 $this->line->fk_product = $line->fk_product;
1203 $this->line->qty = $qty;
1204 $this->line->fk_unit = $fk_unit;
1205 $this->line->description = $description;
1206
1207 if (is_array($array_options) && count($array_options) > 0) {
1208 // We replace values in this->line->array_options only for entries defined into $array_options
1209 foreach ($array_options as $key => $value) {
1210 $this->line->array_options[$key] = $array_options[$key];
1211 }
1212 }
1213
1214
1215 $result = $this->line->update($user, $notrigger);
1216 if ($result > 0) {
1217 // Reorder if child line
1218
1219
1220 $this->db->commit();
1221 return $result;
1222 } else {
1223 $this->error = $this->line->error;
1224
1225 $this->db->rollback();
1226 return -1;
1227 }
1228 } else {
1229 $this->error = get_class($this)."::updatelinefree reception status makes operation forbidden";
1230 $this->errors = array('ReceptionStatusMakeOperationForbidden');
1231 return -2;
1232 }
1233 }
1234
1235 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1241 public function fetch_lines_free()
1242 {
1243 // phpcs:enable
1244 $this->lines = array();
1245
1246 $sql = 'SELECT rc.rowid, rc.fk_reception, rc.fk_entrepot, rc.fk_product, rc.fk_unit, rc.description, rc.fk_elementdet, rc.fk_element, rc.element_type, rc.qty, rc.rang';
1247 $sql .= ' FROM '.MAIN_DB_PREFIX.'receptiondet_batch as rc';
1248 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = rc.fk_product)';
1249 $sql .= ' WHERE rc.fk_reception = '.((int) $this->id);
1250
1251 $sql .= ' ORDER BY rc.rang, rc.rowid';
1252
1253 dol_syslog(get_class($this)."::fetch_lines_free", LOG_DEBUG);
1254 $result = $this->db->query($sql);
1255 if ($result) {
1256 $num = $this->db->num_rows($result);
1257
1258 $i = 0;
1259 while ($i < $num) {
1260 $objp = $this->db->fetch_object($result);
1261
1262 $line = new ReceptionLineBatch($this->db);
1263
1264 $line->rowid = $objp->rowid;
1265 $line->id = $objp->rowid;
1266 $line->fk_reception = $this->id;
1267
1268 $line->description = $objp->description;
1269 $line->qty = $objp->qty;
1270 $line->fk_entrepot = $objp->fk_entrepot;
1271 $line->fk_product = $objp->fk_product;
1272
1273 $line->rang = $objp->rang;
1274
1275
1276 $line->fk_element = $objp->fk_element;
1277 $line->fk_unit = $objp->fk_unit;
1278 $line->fk_elementdet = $objp->fk_elementdet;
1279 $line->fk_element_type = $objp->element_type;
1280 $line->fetch_optionals();
1281
1282 $this->lines[$i] = $line;
1283
1284 $i++;
1285 }
1286
1287 $this->db->free($result);
1288
1289 return 1;
1290 } else {
1291 $this->error = $this->db->error();
1292 return -3;
1293 }
1294 }
1295
1301 public function getLinesArray()
1302 {
1303 return $this->fetch_lines_free();
1304 }
1305
1313 public function update($user = null, $notrigger = 0)
1314 {
1315 global $conf;
1316 $error = 0;
1317
1318 // Clean parameters
1319
1320 if (isset($this->ref)) {
1321 $this->ref = trim($this->ref);
1322 }
1323 if (isset($this->entity)) {
1324 $this->entity = (int) $this->entity;
1325 }
1326 if (isset($this->ref_supplier)) {
1327 $this->ref_supplier = trim($this->ref_supplier);
1328 }
1329 if (isset($this->socid)) {
1330 $this->socid = (int) trim((string) $this->socid);
1331 }
1332 if (isset($this->fk_user_author)) {
1333 $this->fk_user_author = (int) $this->fk_user_author;
1334 }
1335 if (isset($this->fk_user_valid)) {
1336 $this->fk_user_valid = (int) $this->fk_user_valid;
1337 }
1338 if (isset($this->shipping_method_id)) {
1339 $this->shipping_method_id = (int) $this->shipping_method_id;
1340 }
1341 if (isset($this->tracking_number)) {
1342 $this->tracking_number = trim($this->tracking_number);
1343 }
1344 if (isset($this->statut)) {
1345 $this->statut = (int) $this->statut;
1346 }
1347 if (isset($this->trueDepth)) {
1348 $this->trueDepth = price2num($this->trueDepth);
1349 }
1350 if (isset($this->trueWidth)) {
1351 $this->trueWidth = price2num($this->trueWidth);
1352 }
1353 if (isset($this->trueHeight)) {
1354 $this->trueHeight = price2num($this->trueHeight);
1355 }
1356 $this->size_units = (int) $this->size_units;
1357
1358 if (isset($this->trueWeight)) {
1359 $this->weight = price2num($this->trueWeight);
1360 }
1361 $this->weight_units = (int) $this->weight_units;
1362
1363 if (isset($this->note_private)) {
1364 $this->note_private = trim($this->note_private);
1365 }
1366 if (isset($this->note_public)) {
1367 $this->note_public = trim($this->note_public);
1368 }
1369 if (isset($this->model_pdf)) {
1370 $this->model_pdf = trim($this->model_pdf);
1371 }
1372
1373
1374 // Check parameters
1375 // Put here code to add control on parameters values
1376
1377 // Update request
1378 $sql = "UPDATE ".MAIN_DB_PREFIX."reception SET";
1379
1380 $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").",";
1381 $sql .= " ref_supplier=".(isset($this->ref_supplier) ? "'".$this->db->escape($this->ref_supplier)."'" : "null").",";
1382 $sql .= " fk_soc=".(isset($this->socid) ? ((int) $this->socid) : "null").",";
1383 $sql .= " date_creation=".(dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').",";
1384 $sql .= " fk_user_author=".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) : "null").",";
1385 $sql .= " date_valid=".(dol_strlen($this->date_valid) != 0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').",";
1386 $sql .= " fk_user_valid=".(isset($this->fk_user_valid) ? ((int) $this->fk_user_valid) : "null").",";
1387 $sql .= " date_reception=".(dol_strlen($this->date_reception) != 0 ? "'".$this->db->idate($this->date_reception)."'" : 'null').",";
1388 $sql .= " date_delivery=".(dol_strlen($this->date_delivery) != 0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
1389 $sql .= " fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? ((int) $this->shipping_method_id) : "null").",";
1390 $sql .= " tracking_number=".(isset($this->tracking_number) ? "'".$this->db->escape($this->tracking_number)."'" : "null").",";
1391 $sql .= " fk_statut=".(isset($this->statut) ? ((int) $this->statut) : "null").",";
1392 $sql .= " height=".(($this->trueHeight != '') ? (float) $this->trueHeight : "null").",";
1393 $sql .= " width=".(($this->trueWidth != '') ? (float) $this->trueWidth : "null").",";
1394 $sql .= " size_units=".((int) $this->size_units).",";
1395 $sql .= " size=".(($this->trueDepth != '') ? (float) $this->trueDepth : "null").",";
1396 $sql .= " weight_units=".((int) $this->weight_units).",";
1397 $sql .= " weight=".(($this->trueWeight != '') ? (float) $this->trueWeight : "null").",";
1398 $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
1399 $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").",";
1400 $sql .= " model_pdf=".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null").",";
1401 $sql .= " fk_projet=".((isset($this->fk_project) && $this->fk_project > 0) ? ((int) $this->fk_project) : "null").",";
1402 $sql .= " entity = ".((int) $conf->entity);
1403 $sql .= " WHERE rowid=".((int) $this->id);
1404
1405 $this->db->begin();
1406
1407 dol_syslog(get_class($this)."::update", LOG_DEBUG);
1408 $resql = $this->db->query($sql);
1409 if (!$resql) {
1410 $error++;
1411 $this->errors[] = "Error ".$this->db->lasterror();
1412 }
1413
1414 if (!$error) {
1415 if (!$notrigger) {
1416 // Call trigger
1417 $result = $this->call_trigger('RECEPTION_MODIFY', $user);
1418 if ($result < 0) {
1419 $error++;
1420 }
1421 // End call triggers
1422 }
1423 }
1424
1425 // Commit or rollback
1426 if ($error) {
1427 foreach ($this->errors as $errmsg) {
1428 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1429 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1430 }
1431 $this->db->rollback();
1432 return -1 * $error;
1433 } else {
1434 $this->db->commit();
1435 return 1;
1436 }
1437 }
1438
1445 public function delete(User $user)
1446 {
1447 global $conf, $langs, $user;
1448 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1449
1450 $error = 0;
1451 $this->error = '';
1452
1453
1454 $this->db->begin();
1455
1456 // Stock control
1457 if (isModEnabled('stock') && ((getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION') && $this->status > Reception::STATUS_DRAFT)
1458 || (getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION_CLOSE') && $this->status == Reception::STATUS_CLOSED))
1459 ) {
1460 require_once DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php";
1461
1462 $langs->load("agenda");
1463
1464 // Loop on each product line to add a stock movement
1465 $sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as receptiondet_batch_id";
1466 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
1467 $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed";
1468 $sql .= " WHERE ed.fk_reception = ".((int) $this->id);
1469 $sql .= " AND cd.rowid = ed.fk_elementdet";
1470
1471 dol_syslog(get_class($this)."::delete select details", LOG_DEBUG);
1472 $resql = $this->db->query($sql);
1473 if ($resql) {
1474 $cpt = $this->db->num_rows($resql);
1475 for ($i = 0; $i < $cpt; $i++) {
1476 dol_syslog(get_class($this)."::delete movement index ".$i);
1477 $obj = $this->db->fetch_object($resql);
1478
1479 // Same lines as the ones that moved the stock in valid() and setClosed()
1480 if ($obj->qty == 0 || ($obj->qty < 0 && !getDolGlobalInt('RECEPTION_ALLOW_NEGATIVE_QTY'))) {
1481 continue;
1482 }
1483
1484 $mouvS = new MouvementStock($this->db);
1485 // we do not log origin because it will be deleted
1486 $mouvS->origin = null;
1487
1488 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ReceptionDeletedInDolibarr", $this->ref), '', $obj->eatby ? $this->db->jdate($obj->eatby) : null, $obj->sellby ? $this->db->jdate($obj->sellby) : null, $obj->batch); // Price is set to 0, because we don't want to see WAP changed
1489 if ($result < 0) {
1490 $error++;
1491 $this->error = $mouvS->error;
1492 $this->errors = $mouvS->errors;
1493 }
1494 }
1495 } else {
1496 $error++;
1497 $this->errors[] = "Error ".$this->db->lasterror();
1498 }
1499 }
1500
1501 if (!$error) {
1502 $sanitized_main = MAIN_DB_PREFIX.'receptiondet_batch';
1503 $sanitized_ef = $sanitized_main."_extrafields";
1504
1505 $sqlef = "DELETE FROM ".$sanitized_ef." WHERE fk_object IN (SELECT rowid FROM ".$sanitized_main." WHERE fk_reception = ".((int) $this->id).")";
1506
1507 $sql = "DELETE FROM ".MAIN_DB_PREFIX."receptiondet_batch";
1508 $sql .= " WHERE fk_reception = ".((int) $this->id);
1509
1510 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1511 // Delete linked object
1512 $res = $this->deleteObjectLinked();
1513 if ($res < 0) {
1514 $error++;
1515 }
1516
1517 if (!$error) {
1518 $sql = "DELETE FROM ".MAIN_DB_PREFIX."reception";
1519 $sql .= " WHERE rowid = ".((int) $this->id);
1520
1521 if ($this->db->query($sql)) {
1522 // Call trigger
1523 $result = $this->call_trigger('RECEPTION_DELETE', $user);
1524 if ($result < 0) {
1525 $error++;
1526 }
1527 // End call triggers
1528
1529 if (!empty($this->origin) && $this->origin_id > 0) {
1530 $this->fetch_origin();
1532 '@phan-var-force CommandeFournisseur $origin_object';
1534 if ($origin_object->status == 4) { // If order source of reception is "partially received"
1535 // Check if there is no more reception. If not, we can move back status of order to "validated" instead of "reception in progress"
1536 $origin_object->loadReceptions();
1537 //var_dump($this->$origin->receptions);exit;
1538 if (count($origin_object->receptions) <= 0) {
1539 $origin_object->setStatut(3); // CommandeFournisseur ordered
1540 }
1541 }
1542 }
1543
1544 if (!$error) {
1545 $this->db->commit();
1546
1547 // We delete PDFs
1548 $ref = dol_sanitizeFileName($this->ref);
1549 if (!empty($conf->reception->dir_output)) {
1550 $dir = $conf->reception->dir_output.'/'.$ref;
1551 $file = $dir.'/'.$ref.'.pdf';
1552 if (file_exists($file)) {
1553 if (!dol_delete_file($file)) {
1554 return 0;
1555 }
1556 }
1557 if (file_exists($dir)) {
1558 if (!dol_delete_dir_recursive($dir)) {
1559 $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
1560 return 0;
1561 }
1562 }
1563 }
1564
1565 return 1;
1566 } else {
1567 $this->db->rollback();
1568 return -1;
1569 }
1570 } else {
1571 $this->error = $this->db->lasterror()." - sql=$sql";
1572 $this->db->rollback();
1573 return -3;
1574 }
1575 } else {
1576 $this->error = $this->db->lasterror()." - sql=$sql";
1577 $this->db->rollback();
1578 return -2;
1579 }
1580 } else {
1581 $this->error = $this->db->lasterror()." - sql=$sql";
1582 $this->db->rollback();
1583 return -1;
1584 }
1585 } else {
1586 $this->db->rollback();
1587 return -1;
1588 }
1589 }
1590
1598 public function deleteLine($user, $lineid)
1599 {
1600 if ($this->status != self::STATUS_DRAFT) {
1601 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
1602 return -2;
1603 }
1604
1605 $line = new ReceptionLineBatch($this->db);
1606 if ($line->fetch($lineid) <= 0) {
1607 $this->error = 'ErrorRecordNotFound';
1608 return -1;
1609 }
1610 if ($line->fk_reception != $this->id) {
1611 $this->error = 'ErrorLineIDDoesNotMatchWithObjectID';
1612 return -1;
1613 }
1614
1615 $this->db->begin();
1616 if ($line->delete($user) > 0) {
1617 $this->db->commit();
1618 return 1;
1619 }
1620 $this->error = $line->error;
1621 $this->db->rollback();
1622 return -1;
1623 }
1624
1625 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1631 public function fetch_lines()
1632 {
1633 // phpcs:enable
1634 $this->lines = array();
1635
1636 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
1637
1638 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."receptiondet_batch";
1639 $sql .= " WHERE fk_reception = ".((int) $this->id);
1640
1641 $resql = $this->db->query($sql);
1642
1643 if (!empty($resql)) {
1644 while ($obj = $this->db->fetch_object($resql)) {
1645 $line = new CommandeFournisseurDispatch($this->db);
1646
1647 $line->fetch($obj->rowid);
1648
1649 // TODO Remove or keep this ?
1650 $line->fetch_product();
1651
1652 $sql_commfourndet = 'SELECT qty, ref, label, description, tva_tx, vat_src_code, localtax1_tx, localtax2_tx, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva, date_start, date_end, product_type';
1653 $sql_commfourndet .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet';
1654 $sql_commfourndet .= ' WHERE rowid = '.((int) $line->fk_commandefourndet);
1655 $sql_commfourndet .= ' ORDER BY rang';
1656
1657 $resql_commfourndet = $this->db->query($sql_commfourndet);
1658 if (!empty($resql_commfourndet)) {
1659 $obj = $this->db->fetch_object($resql_commfourndet);
1660 $line->qty_asked = $obj->qty;
1661 $line->description = $obj->description;
1662 $line->desc = $obj->description;
1663 $line->tva_tx = $obj->tva_tx;
1664 $line->vat_src_code = $obj->vat_src_code;
1665 $line->localtax1_tx = $obj->localtax1_tx;
1666 $line->localtax2_tx = $obj->localtax2_tx;
1667 $line->subprice = $obj->subprice;
1668 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1669 $line->remise_percent = $obj->remise_percent;
1670 $line->label = !empty($obj->label) ? $obj->label : (is_object($line->product) ? $line->product->label : '');
1671 $line->ref_supplier = $obj->ref;
1672 $line->total_ht = $obj->total_ht;
1673 $line->total_ttc = $obj->total_ttc;
1674 $line->total_tva = $obj->total_tva;
1675 $line->date_start = $this->db->jdate($obj->date_start);
1676 $line->date_end = $this->db->jdate($obj->date_end);
1677 $line->product_type = $obj->product_type;
1678 } else {
1679 $line->qty_asked = 0;
1680 $line->description = '';
1681 $line->desc = '';
1682 $line->label = $obj->label;
1683 }
1684
1685 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1686 $tva = $pu_ht * $line->tva_tx / 100;
1687 $this->total_ht += $pu_ht;
1688 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1689
1690 $this->total_ttc += $pu_ht + $tva;
1691
1692 if (isModEnabled('productbatch') && !empty($line->batch)) {
1693 $detail_batch = new stdClass();
1694 $detail_batch->eatby = $line->eatby;
1695 $detail_batch->sellby = $line->sellby;
1696 $detail_batch->batch = $line->batch;
1697 $detail_batch->qty = $line->qty;
1698
1699 $line->detail_batch[] = $detail_batch;
1700 }
1701
1702 $this->lines[] = $line;
1703 }
1704
1705 return 1;
1706 } else {
1707 return -1;
1708 }
1709 }
1710
1721 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $notooltip = 0)
1722 {
1723 global $langs, $hookmanager;
1724
1725 $result = '';
1726 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Reception").'</u>';
1727 $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1728 $label .= '<br><b>'.$langs->trans('RefSupplier').':</b> '.($this->ref_supplier ? $this->ref_supplier : '');
1729
1730 $url = DOL_URL_ROOT.'/reception/card.php?id='.$this->id;
1731
1732 if ($short) {
1733 return $url;
1734 }
1735
1736 $linkclose = '';
1737 if (empty($notooltip)) {
1738 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1739 $label = $langs->trans("Reception");
1740 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1741 }
1742 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
1743 $linkclose .= ' class="classfortooltip"';
1744 }
1745
1746 $linkstart = '<a href="'.$url.'"';
1747 $linkstart .= $linkclose.'>';
1748 $linkend = '</a>';
1749
1750 $result .= $linkstart;
1751 if ($withpicto) {
1752 $result .= img_object(($notooltip ? '' : $label), $this->picto, '', 0, 0, $notooltip ? 0 : 1);
1753 }
1754 if ($withpicto != 2) {
1755 $result .= $this->ref;
1756 }
1757
1758 $result .= $linkend;
1759
1760 global $action;
1761 $hookmanager->initHooks(array($this->element . 'dao'));
1762 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1763 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1764 if ($reshook > 0) {
1765 $result = $hookmanager->resPrint;
1766 } else {
1767 $result .= $hookmanager->resPrint;
1768 }
1769 return $result;
1770 }
1771
1778 public function getLibStatut($mode = 0)
1779 {
1780 return $this->LibStatut($this->statut, $mode);
1781 }
1782
1783 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1791 public function LibStatut($status, $mode)
1792 {
1793 // phpcs:enable
1794 global $langs;
1795
1796 // List of long language codes for status
1797 $this->labelStatus[-1] = 'StatusReceptionCanceled';
1798 $this->labelStatus[0] = 'StatusReceptionDraft';
1799 // product to receive if stock increase is on close or already received if stock increase is on validation
1800 $this->labelStatus[1] = 'StatusReceptionValidated';
1801 if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION")) {
1802 $this->labelStatus[1] = 'StatusReceptionValidatedReceived';
1803 }
1804 if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION_CLOSE")) {
1805 $this->labelStatus[1] = 'StatusReceptionValidatedToReceive';
1806 }
1807 $this->labelStatus[2] = 'StatusReceptionProcessed';
1808
1809 // List of short language codes for status
1810 $this->labelStatusShort[-1] = 'StatusReceptionCanceledShort';
1811 $this->labelStatusShort[0] = 'StatusReceptionDraftShort';
1812 $this->labelStatusShort[1] = 'StatusReceptionValidatedShort';
1813 $this->labelStatusShort[2] = 'StatusReceptionProcessedShort';
1814
1815 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1816 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1817
1818 $statusType = 'status'.$status;
1819 if ($status == self::STATUS_VALIDATED) {
1820 $statusType = 'status4';
1821 }
1822 if ($status == self::STATUS_CLOSED) {
1823 $statusType = 'status6';
1824 }
1825
1826 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1827 }
1828
1836 public function getKanbanView($option = '', $arraydata = null)
1837 {
1838 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1839
1840 $return = '<div class="box-flex-item box-flex-grow-zero">';
1841 $return .= '<div class="info-box info-box-sm">';
1842 $return .= '<div class="info-box-icon bg-infobox-action">';
1843 $return .= img_picto('', 'order');
1844 $return .= '</div>';
1845 $return .= '<div class="info-box-content">';
1846 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1847 if ($selected >= 0) {
1848 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1849 }
1850 if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) {
1851 $return .= '<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).'</div>';
1852 }
1853 /*if (property_exists($this, 'total_ht')) {
1854 $return .= '<div class="info-box-ref amount">'.price($this->total_ht, 0, $langs, 0, -1, -1, getDolCurrency()).' '.$langs->trans('HT').'</div>';
1855 }*/
1856 if (method_exists($this, 'getLibStatut')) {
1857 $return .= '<div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1858 }
1859 $return .= '</div>';
1860 $return .= '</div>';
1861 $return .= '</div>';
1862
1863 return $return;
1864 }
1865
1873 public function initAsSpecimen()
1874 {
1875 global $langs;
1876
1877 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
1878 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
1879 $now = dol_now();
1880
1881 dol_syslog(get_class($this)."::initAsSpecimen");
1882
1883 $order = new CommandeFournisseur($this->db);
1884 $order->initAsSpecimen();
1885
1886 // Initialise parameters
1887 $this->id = 0;
1888 $this->ref = 'SPECIMEN';
1889 $this->specimen = 1;
1890 $this->statut = 1;
1891 $this->status = 1;
1892 $this->date = $now;
1893 $this->date_creation = $now;
1894 $this->date_valid = $now;
1895 $this->date_delivery = $now;
1896 $this->date_reception = $now + 24 * 3600;
1897 $this->entrepot_id = 0;
1898 $this->socid = 1;
1899 $this->origin_id = 1;
1900 $this->origin_type = 'supplier_order';
1901 $this->origin_object = $order;
1902 $this->note_private = 'Private note';
1903 $this->note_public = 'Public note';
1904 $this->tracking_number = 'TRACKID-ABC123';
1905 $this->fk_incoterms = 1;
1906 $nbp = min(1000, GETPOSTINT('nblines') ? GETPOSTINT('nblines') : 5); // We can force the nb of lines to test from command line (but not more than 1000)
1907 $xnbp = 0;
1908 while ($xnbp < $nbp) {
1909 $line = new CommandeFournisseurDispatch($this->db);
1910 $line->desc = $langs->trans("Description")." ".$xnbp;
1911 $line->libelle = $langs->trans("Description")." ".$xnbp; // deprecated
1912 $line->label = $langs->trans("Description")." ".$xnbp;
1913 $line->qty = 10;
1914
1915 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1916
1917 $this->lines[] = $line;
1918 $xnbp++;
1919 }
1920
1921 return 1;
1922 }
1923
1931 public function setDeliveryDate($user, $delivery_date)
1932 {
1933 // phpcs:enable
1934 if ($user->hasRight('reception', 'creer')) {
1935 $sql = "UPDATE ".MAIN_DB_PREFIX."reception";
1936 $sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null');
1937 $sql .= " WHERE rowid = ".((int) $this->id);
1938
1939 dol_syslog(get_class($this)."::setDeliveryDate", LOG_DEBUG);
1940 $resql = $this->db->query($sql);
1941 if ($resql) {
1942 $this->date_delivery = $delivery_date;
1943 return 1;
1944 } else {
1945 $this->error = $this->db->error();
1946 return -1;
1947 }
1948 } else {
1949 return -2;
1950 }
1951 }
1952
1960 public function setReceptionDate($user, $reception_date)
1961 {
1962 if ($user->hasRight('reception', 'creer')) {
1963 $sql = "UPDATE ".MAIN_DB_PREFIX."reception";
1964 $sql .= " SET date_reception = ".($reception_date ? "'".$this->db->idate($reception_date)."'" : 'null');
1965 $sql .= " WHERE rowid = ".((int) $this->id);
1966
1967 dol_syslog(get_class($this)."::setReceptionDate", LOG_DEBUG);
1968 $resql = $this->db->query($sql);
1969 if ($resql) {
1970 $this->date_reception = $reception_date;
1971 return 1;
1972 } else {
1973 $this->error = $this->db->error();
1974 return -1;
1975 }
1976 } else {
1977 return -2;
1978 }
1979 }
1980
1981 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1987 public function fetch_delivery_methods()
1988 {
1989 // phpcs:enable
1990 global $langs;
1991 $this->meths = array();
1992
1993 $sql = "SELECT em.rowid, em.code, em.libelle";
1994 $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1995 $sql .= " WHERE em.active = 1";
1996 $sql .= " ORDER BY em.libelle ASC";
1997
1998 $resql = $this->db->query($sql);
1999 if ($resql) {
2000 while ($obj = $this->db->fetch_object($resql)) {
2001 $label = $langs->trans('ReceptionMethod'.$obj->code);
2002 $this->meths[$obj->rowid] = ($label != 'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
2003 }
2004 }
2005 }
2006
2007 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2014 public function list_delivery_methods($id = 0)
2015 {
2016 // phpcs:enable
2017 global $langs;
2018
2019 $this->listmeths = array();
2020 $i = 0;
2021
2022 $sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
2023 $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
2024 if (!empty($id)) {
2025 $sql .= " WHERE em.rowid = ".((int) $id);
2026 }
2027
2028 $resql = $this->db->query($sql);
2029 if ($resql) {
2030 while ($obj = $this->db->fetch_object($resql)) {
2031 $this->listmeths[$i]['rowid'] = $obj->rowid;
2032 $this->listmeths[$i]['code'] = $obj->code;
2033 $label = $langs->trans('ReceptionMethod'.$obj->code);
2034 $this->listmeths[$i]['libelle'] = ($label != 'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
2035 $this->listmeths[$i]['description'] = $obj->description;
2036 $this->listmeths[$i]['tracking'] = $obj->tracking;
2037 $this->listmeths[$i]['active'] = $obj->active;
2038 $i++;
2039 }
2040 }
2041 }
2042
2049 public function getUrlTrackingStatus($value = '')
2050 {
2051 if (!empty($this->shipping_method_id)) {
2052 $sql = "SELECT em.code, em.tracking";
2053 $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
2054 $sql .= " WHERE em.rowid = ".((int) $this->shipping_method_id);
2055
2056 $resql = $this->db->query($sql);
2057 if ($resql) {
2058 if ($obj = $this->db->fetch_object($resql)) {
2059 $tracking = $obj->tracking;
2060 }
2061 }
2062 }
2063
2064 if (!empty($tracking) && !empty($value)) {
2065 $url = str_replace('{TRACKID}', $value, $tracking);
2066 $this->tracking_url = sprintf('<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value : 'url'));
2067 } else {
2068 $this->tracking_url = $value;
2069 }
2070 }
2071
2077 public function setClosed()
2078 {
2079 global $conf, $langs, $user;
2080
2081 $error = 0;
2082
2083 // Protection. This avoid to move stock later when we should not
2084 if ($this->statut == Reception::STATUS_CLOSED) {
2085 dol_syslog(get_class($this)."::setClosed already in closed status", LOG_WARNING);
2086 return 0;
2087 }
2088 // Only a validated reception can be closed (a draft reception must not move stock)
2089 if ($this->statut != Reception::STATUS_VALIDATED) {
2090 $langs->load("receptions");
2091 $this->error = $langs->trans('StatusOfRefMustBe', $this->ref, $langs->transnoentitiesnoconv('StatusReceptionValidatedShort'));
2092 dol_syslog(get_class($this)."::setClosed reception is not validated", LOG_WARNING);
2093 return -1;
2094 }
2095
2096 $this->db->begin();
2097
2098 $sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET fk_statut = '.self::STATUS_CLOSED;
2099 $sql .= " WHERE rowid = ".((int) $this->id).' AND fk_statut = '.self::STATUS_VALIDATED;
2100
2101 $resql = $this->db->query($sql);
2102 if ($resql && $this->db->affected_rows($resql) <= 0) {
2103 // Status in database is not validated (already closed or back to draft): no stock movement
2104 $this->db->rollback();
2105 $langs->load("receptions");
2106 $this->error = $langs->trans('StatusOfRefMustBe', $this->ref, $langs->transnoentitiesnoconv('StatusReceptionValidatedShort'));
2107 dol_syslog(get_class($this)."::setClosed reception is not validated in database", LOG_WARNING);
2108 return -1;
2109 }
2110 if ($resql) {
2111 // Set order billed if 100% of order is received (qty in reception lines match qty in order lines)
2112 if ($this->origin == 'order_supplier' && $this->origin_id > 0) {
2113 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
2114
2115 $order = new CommandeFournisseur($this->db);
2116 $order->fetch($this->origin_id);
2117
2118 $order->loadReceptions(self::STATUS_CLOSED); // Fill $order->receptions = array(orderlineid => qty)
2119
2120 $receptions_match_order = 1;
2121 foreach ($order->lines as $line) {
2122 $lineid = $line->id;
2123 $qty = $line->qty;
2124 if (($line->product_type == 0 || getDolGlobalInt('STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
2125 $receptions_match_order = 0;
2126 $text = 'Qty for order line id '.$lineid.' is '.$qty.'. However in the receptions with status Reception::STATUS_CLOSED='.self::STATUS_CLOSED.' we have qty = '.$order->receptions[$lineid].', so we can t close order';
2127 dol_syslog($text);
2128 break;
2129 }
2130 }
2131 if ($receptions_match_order) {
2132 dol_syslog("Qty for the ".count($order->lines)." lines of order have same value for receptions with status Reception::STATUS_CLOSED=".self::STATUS_CLOSED.', so we close order');
2133 $order->Livraison($user, dol_now(), 'tot', 'Reception '.$this->ref);
2134 }
2135 }
2136
2137 $this->statut = self::STATUS_CLOSED;
2138 $this->status = self::STATUS_CLOSED;
2139
2140 // If stock increment is done on closing
2141 if (!$error && isModEnabled('stock') && getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
2142 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
2143
2144 $langs->load("agenda");
2145
2146 // Loop on each product line to add a stock movement
2147 // TODO possibilite de receptionner a partir d'une propale ou autre origine ?
2148 $sql = "SELECT cd.fk_product, cd.subprice,";
2149 $sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
2150 $sql .= " ed.eatby, ed.sellby, ed.batch,";
2151 $sql .= " ed.fk_elementdet, ed.cost_price";
2152 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
2153 $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed";
2154 $sql .= " WHERE ed.fk_reception = ".((int) $this->id);
2155 $sql .= " AND cd.rowid = ed.fk_elementdet";
2156
2157 dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
2158 $resql = $this->db->query($sql);
2159
2160 if ($resql) {
2161 $cpt = $this->db->num_rows($resql);
2162 for ($i = 0; $i < $cpt; $i++) {
2163 $obj = $this->db->fetch_object($resql);
2164
2165 $qty = $obj->qty;
2166
2167 if ($qty == 0 || ($qty < 0 && !getDolGlobalInt('RECEPTION_ALLOW_NEGATIVE_QTY'))) {
2168 continue;
2169 }
2170
2171 dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid);
2172
2173 $mouvS = new MouvementStock($this->db);
2174 $mouvS->origin = &$this;
2175 $mouvS->setOrigin($this->element, $this->id, $obj->fk_elementdet, $obj->rowid);
2176
2177 if (empty($obj->batch)) {
2178 // line without batch detail
2179
2180 // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2181 $inventorycode = '';
2182 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionClassifyClosedInDolibarr", $this->ref), '', '', '', '', 0, $inventorycode);
2183 if ($result < 0) {
2184 $this->error = $mouvS->error;
2185 $this->errors = $mouvS->errors;
2186 $error++;
2187 break;
2188 }
2189 } else {
2190 // line with batch detail
2191
2192 // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2193 $inventorycode = '';
2194 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionClassifyClosedInDolibarr", $this->ref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, '', 0, $inventorycode);
2195
2196 if ($result < 0) {
2197 $this->error = $mouvS->error;
2198 $this->errors = $mouvS->errors;
2199 $error++;
2200 break;
2201 }
2202 }
2203 }
2204 } else {
2205 $this->error = $this->db->lasterror();
2206 $error++;
2207 }
2208 }
2209
2210 // Call trigger
2211 if (!$error) {
2212 $result = $this->call_trigger('RECEPTION_CLOSED', $user);
2213 if ($result < 0) {
2214 $error++;
2215 }
2216 }
2217 } else {
2218 dol_print_error($this->db);
2219 $error++;
2220 }
2221
2222 if (!$error) {
2223 $this->db->commit();
2224 return 1;
2225 } else {
2226 $this->statut = self::STATUS_VALIDATED;
2227 $this->status = self::STATUS_VALIDATED;
2228 $this->db->rollback();
2229 return -1;
2230 }
2231 }
2232
2238 public function setBilled()
2239 {
2240 global $user;
2241 $error = 0;
2242
2243 $this->db->begin();
2244
2245 if ($this->statut == Reception::STATUS_VALIDATED) {
2246 // do not close if already closed
2247 $this->setClosed();
2248 }
2249
2250 $sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET billed=1';
2251 $sql .= " WHERE rowid = ".((int) $this->id).' AND fk_statut > 0';
2252
2253 $resql = $this->db->query($sql);
2254 if ($resql) {
2255 $this->billed = 1;
2256
2257 // Call trigger
2258 $result = $this->call_trigger('RECEPTION_BILLED', $user);
2259 if ($result < 0) {
2260 $this->billed = 0;
2261 $error++;
2262 }
2263 } else {
2264 $error++;
2265 $this->errors[] = $this->db->lasterror;
2266 }
2267
2268 if (empty($error)) {
2269 $this->db->commit();
2270 return 1;
2271 } else {
2272 $this->db->rollback();
2273 return -1;
2274 }
2275 }
2276
2282 public function reOpen()
2283 {
2284 global $langs, $user;
2285
2286 $error = 0;
2287
2288 // Protection: only a closed reception can be reopened (with stock on closing, it removes the stock added by the closing)
2289 if ($this->statut != self::STATUS_CLOSED) {
2290 $langs->load("receptions");
2291 $this->error = $langs->trans('StatusOfRefMustBe', $this->ref, $langs->transnoentitiesnoconv('StatusReceptionProcessedShort'));
2292 return -1;
2293 }
2294
2295 $this->db->begin();
2296
2297 $sql = 'UPDATE '.MAIN_DB_PREFIX.'reception SET fk_statut=1, billed=0';
2298 $sql .= " WHERE rowid = ".((int) $this->id).' AND fk_statut = '.self::STATUS_CLOSED;
2299
2300 $resql = $this->db->query($sql);
2301 $rollbackStatus = $this->status;
2302 $rollbackBilled = $this->billed;
2303 if ($resql) {
2304 if ($this->db->affected_rows($resql) <= 0) {
2305 // Status in database is not closed (reopened meanwhile): no stock movement
2306 $this->db->rollback();
2307 $langs->load("receptions");
2308 $this->error = $langs->trans('StatusOfRefMustBe', $this->ref, $langs->transnoentitiesnoconv('StatusReceptionProcessedShort'));
2309 return -1;
2310 }
2311 $this->statut = self::STATUS_VALIDATED;
2312 $this->status = self::STATUS_VALIDATED;
2313 $this->billed = 0;
2314
2315 // If stock increment is done on closing
2316 if (!$error && isModEnabled('stock') && getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
2317 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
2318 $numref = (string) $this->ref;
2319 $langs->load("agenda");
2320
2321 // Loop on each product line to add a stock movement
2322 // TODO possibilite de receptionner a partir d'une propale ou autre origine
2323 $sql = "SELECT ed.fk_product, cd.subprice,";
2324 $sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
2325 $sql .= " ed.eatby, ed.sellby, ed.batch,";
2326 $sql .= " ed.fk_elementdet, ed.cost_price";
2327 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
2328 $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed";
2329 $sql .= " WHERE ed.fk_reception = ".((int) $this->id);
2330 $sql .= " AND cd.rowid = ed.fk_elementdet";
2331
2332 dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
2333 $resql = $this->db->query($sql);
2334 if ($resql) {
2335 $cpt = $this->db->num_rows($resql);
2336 for ($i = 0; $i < $cpt; $i++) {
2337 $obj = $this->db->fetch_object($resql);
2338
2339 $qty = $obj->qty;
2340
2341 if ($qty == 0 || ($qty < 0 && !getDolGlobalInt('RECEPTION_ALLOW_NEGATIVE_QTY'))) {
2342 continue;
2343 }
2344 dol_syslog(get_class($this)."::reopen reception movement index ".$i." ed.rowid=".$obj->rowid);
2345
2346 //var_dump($this->lines[$i]);
2347 $mouvS = new MouvementStock($this->db);
2348 $mouvS->origin = &$this;
2349 $mouvS->setOrigin($this->element, $this->id, $obj->fk_elementdet, $obj->rowid);
2350
2351 if (empty($obj->batch)) {
2352 // line without batch detail
2353
2354 // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2355 $inventorycode = '';
2356 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionUnClassifyCloseddInDolibarr", $numref), '', '', '', '', 0, $inventorycode);
2357
2358 if ($result < 0) {
2359 $this->error = $mouvS->error;
2360 $this->errors = $mouvS->errors;
2361 $error++;
2362 break;
2363 }
2364 } else {
2365 // line with batch detail
2366
2367 // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2368 $inventorycode = '';
2369 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionUnClassifyCloseddInDolibarr", $numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, 0, $inventorycode);
2370 if ($result < 0) {
2371 $this->error = $mouvS->error;
2372 $this->errors = $mouvS->errors;
2373 $error++;
2374 break;
2375 }
2376 }
2377 }
2378 } else {
2379 $this->error = $this->db->lasterror();
2380 $error++;
2381 }
2382 }
2383
2384 if (!$error) {
2385 // Call trigger
2386 $result = $this->call_trigger('RECEPTION_REOPEN', $user);
2387 if ($result < 0) {
2388 $error++;
2389 }
2390 }
2391
2392 if (!$error && $this->origin == 'order_supplier') {
2393 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
2394
2395 $commande = new CommandeFournisseur($this->db);
2396 $commande->fetch($this->origin_id);
2397 $result = $commande->setStatus($user, 4);
2398 if ($result < 0) {
2399 $error++;
2400 $this->error = $commande->error;
2401 $this->errors = $commande->errors;
2402 }
2403 }
2404 } else {
2405 $error++;
2406 $this->errors[] = $this->db->lasterror();
2407 }
2408
2409 if (!$error) {
2410 $this->db->commit();
2411 return 1;
2412 } else {
2413 $this->statut = $this->status = $rollbackStatus;
2414 $this->billed = $rollbackBilled;
2415 $this->db->rollback();
2416 return -1;
2417 }
2418 }
2419
2426 public function setDraft($user)
2427 {
2428 // phpcs:enable
2429 global $langs;
2430
2431 $error = 0;
2432
2433 // Protection
2434 if ($this->statut <= self::STATUS_DRAFT) {
2435 return 0;
2436 }
2437
2438 if (!((!getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer'))
2439 || (getDolGlobalInt('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate')))) {
2440 $this->error = 'Permission denied';
2441 return -1;
2442 }
2443
2444 $this->db->begin();
2445
2446 $sql = "UPDATE ".MAIN_DB_PREFIX."reception";
2447 $sql .= " SET fk_statut = ".self::STATUS_DRAFT;
2448 $sql .= " WHERE rowid = ".((int) $this->id);
2449 $sql .= " AND fk_statut = ".((int) $this->statut); // Status may have changed since the object was loaded
2450
2451 dol_syslog(__METHOD__, LOG_DEBUG);
2452 $resql = $this->db->query($sql);
2453 if ($resql && $this->db->affected_rows($resql) <= 0) {
2454 // Status in database is not the one of the object (changed meanwhile): no stock movement
2455 $this->db->rollback();
2456 $langs->load("receptions");
2457 $this->error = $langs->trans('StatusOfRefMustBe', $this->ref, $langs->transnoentitiesnoconv($this->statut == self::STATUS_CLOSED ? 'StatusReceptionProcessedShort' : 'StatusReceptionValidatedShort'));
2458 return -1;
2459 }
2460 if ($resql) {
2461 // If stock increment is done on validation, or on closing and the reception was closed, we revert it
2462 if (!$error && isModEnabled('stock') && (getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION') || (getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION_CLOSE') && $this->statut == self::STATUS_CLOSED))) {
2463 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
2464
2465 $langs->load("agenda");
2466
2467 // Loop on each product line to add a stock movement
2468 // TODO possibilite de receptionner a partir d'une propale ou autre origine
2469 $sql = "SELECT cd.fk_product, cd.subprice,";
2470 $sql .= " ed.rowid, ed.qty, ed.fk_entrepot,";
2471 $sql .= " ed.eatby, ed.sellby, ed.batch,";
2472 $sql .= " ed.fk_elementdet, ed.cost_price";
2473 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
2474 $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as ed";
2475 $sql .= " WHERE ed.fk_reception = ".((int) $this->id);
2476 $sql .= " AND cd.rowid = ed.fk_elementdet";
2477
2478 dol_syslog(get_class($this)."::valid select details", LOG_DEBUG);
2479 $resql = $this->db->query($sql);
2480 if ($resql) {
2481 $cpt = $this->db->num_rows($resql);
2482 for ($i = 0; $i < $cpt; $i++) {
2483 $obj = $this->db->fetch_object($resql);
2484
2485 $qty = $obj->qty;
2486
2487 if ($qty == 0 || ($qty < 0 && !getDolGlobalInt('RECEPTION_ALLOW_NEGATIVE_QTY'))) {
2488 continue;
2489 }
2490
2491 dol_syslog(get_class($this)."::reopen reception movement index ".$i." ed.rowid=".$obj->rowid);
2492
2493 //var_dump($this->lines[$i]);
2494 $mouvS = new MouvementStock($this->db);
2495 $mouvS->origin = &$this;
2496 $mouvS->setOrigin($this->element, $this->id, $obj->fk_elementdet, $obj->rowid);
2497
2498 if (empty($obj->batch)) {
2499 // line without batch detail
2500
2501 // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2502 $inventorycode = '';
2503 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionBackToDraftInDolibarr", $this->ref), '', '', '', '', 0, $inventorycode);
2504 if ($result < 0) {
2505 $this->error = $mouvS->error;
2506 $this->errors = $mouvS->errors;
2507 $error++;
2508 break;
2509 }
2510 } else {
2511 // line with batch detail
2512
2513 // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record
2514 $inventorycode = '';
2515 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans("ReceptionBackToDraftInDolibarr", $this->ref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, 0, $inventorycode);
2516 if ($result < 0) {
2517 $this->error = $mouvS->error;
2518 $this->errors = $mouvS->errors;
2519 $error++;
2520 break;
2521 }
2522 }
2523 }
2524 } else {
2525 $this->error = $this->db->lasterror();
2526 $error++;
2527 }
2528 }
2529
2530 if (!$error) {
2531 // Call trigger
2532 $result = $this->call_trigger('RECEPTION_UNVALIDATE', $user);
2533 if ($result < 0) {
2534 $error++;
2535 }
2536 }
2537 if ($this->origin == 'order_supplier') {
2538 if (!empty($this->origin) && $this->origin_id > 0) {
2539 $this->fetch_origin();
2540 if ($this->origin_object->statut == 4) { // If order source of reception is "partially received"
2541 // Check if there is no more reception validated.
2542 $this->origin_object->fetchObjectLinked();
2543 $setStatut = 1;
2544 if (!empty($this->origin_object->linkedObjects['reception'])) {
2545 foreach ($this->origin_object->linkedObjects['reception'] as $rcption) {
2546 if ($rcption->statut > 0) {
2547 $setStatut = 0;
2548 break;
2549 }
2550 }
2551 //var_dump($this->$origin->receptions);exit;
2552 if ($setStatut) {
2553 $this->origin_object->setStatut(3); // CommandeFournisseur ordered
2554 }
2555 }
2556 }
2557 }
2558 }
2559
2560 if (!$error) {
2561 $this->statut = self::STATUS_DRAFT;
2562 $this->status = self::STATUS_DRAFT;
2563 $this->db->commit();
2564 return 1;
2565 } else {
2566 $this->db->rollback();
2567 return -1;
2568 }
2569 } else {
2570 $this->error = $this->db->error();
2571 $this->db->rollback();
2572 return -1;
2573 }
2574 }
2575
2586 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2587 {
2588 global $conf, $langs;
2589
2590 $langs->load("receptions");
2591
2592 if (!dol_strlen($modele)) {
2593 $modele = 'squille';
2594
2595 if ($this->model_pdf) {
2596 $modele = $this->model_pdf;
2597 } elseif (getDolGlobalString('RECEPTION_ADDON_PDF')) {
2598 $modele = getDolGlobalString('RECEPTION_ADDON_PDF');
2599 }
2600 }
2601
2602 $modelpath = "core/modules/reception/doc/";
2603
2604 if (!empty($this->origin) && $this->origin_id > 0) {
2605 $this->fetch_origin();
2606 }
2607
2608 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2609 }
2610
2619 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
2620 {
2621 $tables = array('reception');
2622
2623 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
2624 }
2625
2634 public static function replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
2635 {
2636 $tables = array(
2637 'receptiondet_batch'
2638 );
2639
2640 return CommonObject::commonReplaceProduct($dbs, $origin_id, $dest_id, $tables);
2641 }
2642}
$object ref
Definition info.php:90
Class to manage table ReceptionLineBatch.
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_RECEIVED_COMPLETELY
Received completely.
Class to manage line orders.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='')
Set status of an object.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
updateRangOfLine($rowid, $rang)
Update position of line (rang)
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage Dolibarr database access.
Class to manage standard extra fields.
Class to manage stock movements.
Class to manage products or services.
static checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName='', $alreadyCheckConf=false)
Check sell or eat by date is mandatory from product and sell-by and eat-by dates.
Class to manage receptions.
setBilled()
Classify the reception as invoiced (used for example by trigger when WORKFLOW_RECEPTION_CLASSIFY_BILL...
fetch_delivery_methods()
Fetch deliveries method and return an array.
getLibStatut($mode=0)
Return status label.
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $notrigger, $array_options=array())
Update a simple reception line.
getUrlTrackingStatus($value='')
Forge an set tracking url.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getLinesArray()
Create an array of reception lines.
fetch_lines_free()
Load lines of simple reception.
update($user=null, $notrigger=0)
Update database.
deleteLine($user, $lineid)
Delete a line of the reception.
setClosed()
Classify the reception as closed (this records also the stock movement)
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
LibStatut($status, $mode)
Return label of a status.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $notooltip=0)
Return clickable link of object (with eventually picto)
create_line($entrepot_id, $origin_line_id, $qty, $rang=0, $array_options=[], $parent_line_id=0, $product_id=0)
Create a reception line.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
list_delivery_methods($id=0)
Fetch all deliveries method and return an array.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
__construct($db)
Constructor.
addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $array_options=[])
Add a simple reception line.
initAsSpecimen()
Initialise an instance with random values.
setReceptionDate($user, $reception_date)
Set the reception date.
fetch_lines()
Load lines.
create($user, $notrigger=0)
Create reception.
fetch($id, $ref='', $ref_ext='')
Get object and lines from database.
reOpen()
Classify the reception as validated/opened.
getStatusDispatch()
Get status from all dispatched lines.
addline($entrepot_id, $id, $qty, $array_options=[], $comment='', $eatby=null, $sellby=null, $batch='', $cost_price=0)
Add an reception line.
setDraft($user)
Set draft status.
Class to manage table commandefournisseurdispatch.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_now($mode='gmt')
Return date for now.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:492
$conf db user
Active Directory does not allow anonymous connections.
Definition repair.php:141