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