2006-05-05 17:12:48 +02:00
< ? php
2008-01-31 14:40:45 +01:00
/* Copyright ( C ) 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2014 Regis Houssin < regis . houssin @ inodbox . com >
2008-01-31 14:40:45 +01:00
* Copyright ( C ) 2006 - 2007 Laurent Destailleur < eldy @ users . sourceforge . net >
2007-01-05 14:23:08 +01:00
* Copyright ( C ) 2007 Franky Van Liedekerke < franky . van . liedekerke @ telenet . be >
2023-02-04 10:25:35 +01:00
* Copyright ( C ) 2011 - 2023 Philippe Grand < philippe . grand @ atoo - net . com >
2018-09-02 11:08:41 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2015-04-18 20:50:03 +02:00
* Copyright ( C ) 2014 - 2015 Marcos GarcÃa < marcosgdf @ gmail . com >
2024-06-30 21:04:19 +02:00
* Copyright ( C ) 2023 - 2024 Frédéric France < frederic . france @ free . fr >
2025-01-18 23:15:39 +01:00
* Copyright ( C ) 2024 - 2025 MDW < mdeweerd @ users . noreply . github . com >
2006-05-05 17:12:48 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2006-05-05 17:12:48 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2006-05-05 17:12:48 +02:00
*/
/**
2020-10-05 15:32:29 +02:00
* \file htdocs / delivery / class / delivery . class . php
2010-03-13 16:52:30 +01:00
* \ingroup delivery
2018-09-01 14:28:30 +02:00
* \brief Delivery Order Management Class File
2009-12-17 16:52:37 +01:00
*/
2006-05-05 17:12:48 +02:00
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php' ;
2020-10-25 17:19:15 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonincoterm.class.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php' ;
2022-08-23 20:01:34 +02:00
if ( isModEnabled ( " propal " )) {
2021-02-25 22:15:04 +01:00
require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php' ;
}
2024-02-27 15:30:37 +01:00
if ( isModEnabled ( 'order' )) {
2021-02-25 22:15:04 +01:00
require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
}
2006-06-18 16:35:35 +02:00
2006-05-05 17:12:48 +02:00
2006-06-24 19:10:32 +02:00
/**
2015-09-06 12:30:41 +02:00
* Class to manage receptions
2009-12-17 16:52:37 +01:00
*/
2020-10-05 13:59:06 +02:00
class Delivery extends CommonObject
2006-05-05 17:12:48 +02:00
{
2020-10-25 17:19:15 +01:00
use CommonIncoterm ;
2018-08-23 18:35:45 +02:00
/**
* @ var string ID to identify managed object
*/
2020-04-10 10:59:32 +02:00
public $element = " delivery " ;
2018-09-02 23:25:10 +02:00
2018-09-01 15:27:55 +02:00
/**
2020-12-05 23:53:55 +01:00
* @ var string Field with ID of parent key if this field has a parent
2018-09-01 15:27:55 +02:00
*/
2020-10-06 11:04:31 +02:00
public $fk_element = " fk_delivery " ;
2018-09-02 23:25:10 +02:00
2018-08-22 18:48:53 +02:00
/**
* @ var string Name of table without prefix where object is stored
*/
2020-10-06 11:04:31 +02:00
public $table_element = " delivery " ;
2018-09-02 23:25:10 +02:00
2018-09-02 11:08:41 +02:00
/**
2020-12-05 23:53:55 +01:00
* @ var string Name of subtable line
2018-09-02 11:08:41 +02:00
*/
2020-10-06 11:04:31 +02:00
public $table_element_line = " deliverydet " ;
2006-06-24 19:10:32 +02:00
2020-09-14 04:11:12 +02:00
/**
* @ var string String with name of icon for myobject . Must be the part after the 'object_' into object_myobject . png
*/
public $picto = 'sending' ;
2020-10-31 14:32:18 +01:00
/**
* @ var int draft status
*/
public $draft ;
/**
* @ var int thirdparty id
*/
public $socid ;
/**
2024-01-13 19:48:41 +01:00
* @ var string ref customer
2020-10-31 14:32:18 +01:00
*/
2018-09-01 15:27:55 +02:00
public $ref_customer ;
2019-11-10 12:06:12 +01:00
2019-11-10 12:05:45 +01:00
/**
2024-06-30 21:04:19 +02:00
* @ var int | '' Date really received
2019-11-10 12:05:45 +01:00
*/
2019-11-10 12:06:12 +01:00
public $date_delivery ;
2019-11-01 10:56:46 +01:00
2019-11-10 12:05:45 +01:00
/**
2024-06-30 21:04:19 +02:00
* @ var int | '' date_valid
2019-11-10 12:05:45 +01:00
*/
2018-09-01 15:27:55 +02:00
public $date_valid ;
2019-11-10 12:06:12 +01:00
2020-10-31 14:32:18 +01:00
/**
* @ var string model pdf
*/
2018-09-01 15:27:55 +02:00
public $model_pdf ;
2009-02-04 23:12:23 +01:00
2024-06-30 21:04:19 +02:00
/**
* @ var int ID of order
*/
2022-06-17 07:53:07 +02:00
public $commande_id ;
2023-02-23 21:16:25 +01:00
/**
* @ var DeliveryLine [] lines
*/
2020-11-28 14:47:39 +01:00
public $lines = array ();
2023-11-18 12:47:42 +01:00
/**
* @ var int user_author_id
*/
public $user_author_id ;
2019-11-02 12:00:43 +01:00
2024-08-22 14:06:29 +02:00
const STATUS_DRAFT = 0 ;
const STATUS_VALIDATED = 1 ;
const STATUS_CANCELED = - 1 ;
2006-06-18 16:35:35 +02:00
/**
2012-01-28 17:34:42 +01:00
* Constructor
*
* @ param DoliDB $db Database handler
2009-12-17 16:52:37 +01:00
*/
2020-10-28 17:49:52 +01:00
public function __construct ( $db )
2009-12-17 16:52:37 +01:00
{
2012-01-28 17:34:42 +01:00
$this -> db = $db ;
2010-01-05 21:03:37 +01:00
2009-12-17 16:52:37 +01:00
// List of short language codes for status
2023-11-24 10:10:24 +01:00
$this -> labelStatus [ - 1 ] = 'StatusDeliveryCanceled' ;
$this -> labelStatus [ 0 ] = 'StatusDeliveryDraft' ;
$this -> labelStatus [ 1 ] = 'StatusDeliveryValidated' ;
2009-12-17 16:52:37 +01:00
}
2006-05-05 17:12:48 +02:00
2006-11-11 01:46:15 +01:00
/**
2012-01-28 17:34:42 +01:00
* Create delivery receipt in database
*
2024-01-13 19:48:41 +01:00
* @ param User $user Object du user qui cree
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 si erreur , id delivery cree si ok
2009-12-17 16:52:37 +01:00
*/
2020-10-28 17:49:52 +01:00
public function create ( $user )
2006-11-11 01:46:15 +01:00
{
global $conf ;
2009-02-04 23:12:23 +01:00
2020-10-05 13:59:06 +02:00
dol_syslog ( " Delivery::create " );
2013-08-07 15:08:30 +02:00
2021-02-25 22:15:04 +01:00
if ( empty ( $this -> model_pdf )) {
2024-01-05 04:18:53 +01:00
$this -> model_pdf = getDolGlobalString ( 'DELIVERY_ADDON_PDF' );
2021-02-25 22:15:04 +01:00
}
2009-02-04 23:12:23 +01:00
2006-11-11 01:46:15 +01:00
$error = 0 ;
2009-02-04 23:12:23 +01:00
2020-10-28 17:49:52 +01:00
$now = dol_now ();
2010-07-23 00:51:00 +02:00
2020-10-06 11:04:31 +02:00
/* Delivery note as draft On positionne en mode draft le bon de livraison */
$this -> draft = 1 ;
2009-02-04 23:12:23 +01:00
2006-11-11 01:46:15 +01:00
$this -> user = $user ;
2009-02-04 23:12:23 +01:00
2006-11-11 01:46:15 +01:00
$this -> db -> begin ();
2009-02-04 23:12:23 +01:00
2020-10-06 11:04:31 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " delivery ( " ;
2020-04-10 10:59:32 +02:00
$sql .= " ref " ;
$sql .= " , entity " ;
$sql .= " , fk_soc " ;
$sql .= " , ref_customer " ;
$sql .= " , date_creation " ;
$sql .= " , fk_user_author " ;
$sql .= " , date_delivery " ;
$sql .= " , fk_address " ;
$sql .= " , note_private " ;
$sql .= " , note_public " ;
$sql .= " , model_pdf " ;
$sql .= " , fk_incoterms, location_incoterms " ;
$sql .= " ) VALUES ( " ;
$sql .= " '(PROV)' " ;
2021-09-03 21:25:17 +02:00
$sql .= " , " . (( int ) $conf -> entity );
$sql .= " , " . (( int ) $this -> socid );
2020-04-10 10:59:32 +02:00
$sql .= " , ' " . $this -> db -> escape ( $this -> ref_customer ) . " ' " ;
$sql .= " , ' " . $this -> db -> idate ( $now ) . " ' " ;
2021-09-03 21:25:17 +02:00
$sql .= " , " . (( int ) $user -> id );
2020-04-10 10:59:32 +02:00
$sql .= " , " . ( $this -> date_delivery ? " ' " . $this -> db -> idate ( $this -> date_delivery ) . " ' " : " null " );
$sql .= " , " . ( $this -> fk_delivery_address > 0 ? $this -> fk_delivery_address : " null " );
$sql .= " , " . ( ! empty ( $this -> note_private ) ? " ' " . $this -> db -> escape ( $this -> note_private ) . " ' " : " null " );
$sql .= " , " . ( ! empty ( $this -> note_public ) ? " ' " . $this -> db -> escape ( $this -> note_public ) . " ' " : " null " );
$sql .= " , " . ( ! empty ( $this -> model_pdf ) ? " ' " . $this -> db -> escape ( $this -> model_pdf ) . " ' " : " null " );
2020-10-28 17:49:52 +01:00
$sql .= " , " . ( int ) $this -> fk_incoterms ;
$sql .= " , ' " . $this -> db -> escape ( $this -> location_incoterms ) . " ' " ;
2020-04-10 10:59:32 +02:00
$sql .= " ) " ;
2009-02-04 23:12:23 +01:00
2020-10-05 13:59:06 +02:00
dol_syslog ( " Delivery::create " , LOG_DEBUG );
2020-04-10 10:59:32 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-25 22:15:04 +01:00
if ( $resql ) {
2020-10-06 11:04:31 +02:00
$this -> id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " delivery " );
2009-02-04 23:12:23 +01:00
2009-04-30 18:44:31 +02:00
$numref = " (PROV " . $this -> id . " ) " ;
2009-06-04 22:29:45 +02:00
2020-10-06 11:04:31 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " delivery " ;
2020-04-10 10:59:32 +02:00
$sql .= " SET ref = ' " . $this -> db -> escape ( $numref ) . " ' " ;
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2009-02-04 23:12:23 +01:00
2020-10-05 13:59:06 +02:00
dol_syslog ( " Delivery::create " , LOG_DEBUG );
2020-04-10 10:59:32 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-25 22:15:04 +01:00
if ( $resql ) {
2023-04-18 14:04:27 +02:00
if ( ! getDolGlobalInt ( 'MAIN_SUBMODULE_EXPEDITION' )) {
2006-11-11 01:46:15 +01:00
$commande = new Commande ( $this -> db );
$commande -> id = $this -> commande_id ;
2014-09-04 18:58:33 +02:00
$commande -> fetch_lines ();
2006-11-11 01:46:15 +01:00
}
2009-02-04 23:12:23 +01:00
2006-11-11 01:46:15 +01:00
/*
2018-09-01 14:28:30 +02:00
* Inserting products into the database
2009-12-17 16:52:37 +01:00
*/
2020-04-10 10:59:32 +02:00
$num = count ( $this -> lines );
2021-02-25 22:15:04 +01:00
for ( $i = 0 ; $i < $num ; $i ++ ) {
2020-04-10 10:59:32 +02:00
$origin_id = $this -> lines [ $i ] -> origin_line_id ;
2021-02-25 22:15:04 +01:00
if ( ! $origin_id ) {
$origin_id = $this -> lines [ $i ] -> commande_ligne_id ; // For backward compatibility
}
2009-02-04 23:12:23 +01:00
2021-10-23 22:21:50 +02:00
if ( ! $this -> create_line ( $origin_id , $this -> lines [ $i ] -> qty , $this -> lines [ $i ] -> fk_product , $this -> lines [ $i ] -> description , $this -> lines [ $i ] -> array_options )) {
2008-08-05 16:22:11 +02:00
$error ++ ;
}
}
2008-09-02 12:11:40 +02:00
2021-02-25 22:15:04 +01:00
if ( ! $error && $this -> id && $this -> origin_id ) {
2009-12-12 10:13:41 +01:00
$ret = $this -> add_object_linked ();
2021-02-25 22:15:04 +01:00
if ( ! $ret ) {
2006-11-11 01:46:15 +01:00
$error ++ ;
}
2010-01-05 21:03:37 +01:00
2023-04-18 14:04:27 +02:00
if ( ! getDolGlobalInt ( 'MAIN_SUBMODULE_EXPEDITION' )) {
2019-01-27 11:55:16 +01:00
$ret = $this -> setStatut ( 2 , $this -> origin_id , $this -> origin );
2021-02-25 22:15:04 +01:00
if ( ! $ret ) {
2009-12-15 09:15:11 +01:00
$error ++ ;
2009-12-12 10:13:41 +01:00
}
}
2006-11-11 01:46:15 +01:00
}
2009-02-04 23:12:23 +01:00
2021-02-25 22:15:04 +01:00
if ( ! $error ) {
2006-11-11 01:46:15 +01:00
$this -> db -> commit ();
return $this -> id ;
2020-05-21 15:05:19 +02:00
} else {
2006-11-11 01:46:15 +01:00
$error ++ ;
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> lasterror () . " - sql= " . $this -> db -> lastqueryerror ;
2006-11-11 01:46:15 +01:00
$this -> db -> rollback ();
return - 3 ;
}
2020-05-21 15:05:19 +02:00
} else {
2006-11-11 01:46:15 +01:00
$error ++ ;
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> lasterror () . " - sql= " . $this -> db -> lastqueryerror ;
2006-11-11 01:46:15 +01:00
$this -> db -> rollback ();
return - 2 ;
}
2020-05-21 15:05:19 +02:00
} else {
2006-11-11 01:46:15 +01:00
$error ++ ;
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> lasterror () . " - sql= " . $this -> db -> lastqueryerror ;
2006-11-11 01:46:15 +01:00
$this -> db -> rollback ();
return - 1 ;
}
}
2009-02-04 23:12:23 +01:00
2020-10-28 17:49:52 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2006-11-11 01:46:15 +01:00
/**
2012-01-28 17:34:42 +01:00
* Create a line
2009-12-17 16:52:37 +01:00
*
2024-08-20 23:56:24 +02:00
* @ param int $origin_id Id of order
2024-10-24 00:26:36 +02:00
* @ param float $qty Quantity
2024-08-20 23:56:24 +02:00
* @ param int $fk_product Id of predefined product
2012-01-28 17:34:42 +01:00
* @ param string $description Description
2024-09-12 21:16:42 +02:00
* @ param array < string , ? mixed > $array_options Array options
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2009-12-17 16:52:37 +01:00
*/
2024-03-10 01:44:08 +01:00
public function create_line ( $origin_id , $qty , $fk_product , $description , $array_options = [])
2020-10-28 17:49:52 +01:00
{
// phpcs:enable
2006-11-11 01:46:15 +01:00
$error = 0 ;
2009-02-04 23:12:23 +01:00
2020-10-06 11:04:31 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " deliverydet (fk_delivery, fk_origin_line, " ;
2020-04-10 10:59:32 +02:00
$sql .= " fk_product, description, qty) " ;
2021-08-23 18:56:46 +02:00
$sql .= " VALUES ( " . $this -> id . " , " . (( int ) $origin_id ) . " , " ;
2024-08-20 23:56:24 +02:00
$sql .= " " . ( $fk_product > 0 ? (( int ) $fk_product ) : " null " ) . " , " ;
2020-04-10 10:59:32 +02:00
$sql .= " " . ( $description ? " ' " . $this -> db -> escape ( $description ) . " ' " : " null " ) . " , " ;
2021-08-23 18:56:46 +02:00
$sql .= ( price2num ( $qty , 'MS' )) . " ) " ;
2009-02-04 23:12:23 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::create_line " , LOG_DEBUG );
2021-02-25 22:15:04 +01:00
if ( ! $this -> db -> query ( $sql )) {
2010-09-07 00:31:36 +02:00
$error ++ ;
2006-11-11 01:46:15 +01:00
}
2010-09-07 00:31:36 +02:00
2021-10-23 22:21:50 +02:00
$id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " deliverydet " );
2021-10-23 22:37:07 +02:00
2021-10-23 22:21:50 +02:00
if ( is_array ( $array_options ) && count ( $array_options ) > 0 ) {
2021-10-23 22:37:07 +02:00
$line = new DeliveryLine ( $this -> db );
$line -> id = $id ;
$line -> array_options = $array_options ;
$result = $line -> insertExtraFields ();
2021-10-23 22:21:50 +02:00
}
2010-09-07 00:31:36 +02:00
2023-03-19 10:38:38 +01:00
if ( ! $error ) {
2010-09-07 00:31:36 +02:00
return 1 ;
2010-09-06 18:31:28 +02:00
}
2023-03-19 10:38:38 +01:00
return - 1 ;
2006-11-11 01:46:15 +01:00
}
2009-02-04 23:12:23 +01:00
2009-12-17 16:52:37 +01:00
/**
2012-01-28 17:34:42 +01:00
* Load a delivery receipt
*
* @ param int $id Id of object to load
2016-04-09 19:32:05 +02:00
* @ return integer
2009-12-17 16:52:37 +01:00
*/
2020-10-28 17:49:52 +01:00
public function fetch ( $id )
2006-11-11 01:46:15 +01:00
{
2010-03-13 16:52:30 +01:00
$sql = " SELECT l.rowid, l.fk_soc, l.date_creation, l.date_valid, l.ref, l.ref_customer, l.fk_user_author, " ;
2020-04-10 10:59:32 +02:00
$sql .= " l.total_ht, l.fk_statut, l.fk_user_valid, l.note_private, l.note_public " ;
$sql .= " , l.date_delivery, l.fk_address, l.model_pdf " ;
$sql .= " , el.fk_source as origin_id, el.sourcetype as origin " ;
2020-10-28 17:49:52 +01:00
$sql .= ', l.fk_incoterms, l.location_incoterms' ;
$sql .= " , i.libelle as label_incoterms " ;
2020-10-06 11:04:31 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " delivery as l " ;
2020-04-10 10:59:32 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " element_element as el ON el.fk_target = l.rowid AND el.targettype = ' " . $this -> db -> escape ( $this -> element ) . " ' " ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_incoterms as i ON l.fk_incoterms = i.rowid' ;
2021-03-14 11:48:39 +01:00
$sql .= " WHERE l.rowid = " . (( int ) $id );
2008-05-20 02:09:11 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch " , LOG_DEBUG );
2011-09-20 15:32:16 +02:00
$result = $this -> db -> query ( $sql );
2021-02-25 22:15:04 +01:00
if ( $result ) {
if ( $this -> db -> num_rows ( $result )) {
2008-01-31 15:23:57 +01:00
$obj = $this -> db -> fetch_object ( $result );
2009-02-04 23:12:23 +01:00
2008-01-31 15:23:57 +01:00
$this -> id = $obj -> rowid ;
2010-03-13 16:52:30 +01:00
$this -> date_delivery = $this -> db -> jdate ( $obj -> date_delivery );
2010-01-13 19:51:19 +01:00
$this -> date_creation = $this -> db -> jdate ( $obj -> date_creation );
$this -> date_valid = $this -> db -> jdate ( $obj -> date_valid );
2008-01-31 15:23:57 +01:00
$this -> ref = $obj -> ref ;
2010-03-13 16:52:30 +01:00
$this -> ref_customer = $obj -> ref_customer ;
2008-01-31 15:23:57 +01:00
$this -> socid = $obj -> fk_soc ;
$this -> statut = $obj -> fk_statut ;
2023-10-17 11:10:25 +02:00
$this -> status = $obj -> fk_statut ;
2008-01-31 15:23:57 +01:00
$this -> user_author_id = $obj -> fk_user_author ;
2023-10-17 11:10:25 +02:00
$this -> user_validation_id = $obj -> fk_user_valid ;
2010-07-29 14:37:09 +02:00
$this -> fk_delivery_address = $obj -> fk_address ;
2013-04-09 17:18:07 +02:00
$this -> note = $obj -> note_private ; //TODO deprecated
$this -> note_private = $obj -> note_private ;
2008-01-31 15:23:57 +01:00
$this -> note_public = $obj -> note_public ;
2020-08-18 14:48:38 +02:00
$this -> model_pdf = $obj -> model_pdf ;
2020-04-10 10:59:32 +02:00
$this -> origin = $obj -> origin ; // May be 'shipping'
$this -> origin_id = $obj -> origin_id ; // May be id of shipping
2009-02-04 23:12:23 +01:00
2015-02-23 09:16:14 +01:00
//Incoterms
$this -> fk_incoterms = $obj -> fk_incoterms ;
2017-10-03 16:00:52 +02:00
$this -> location_incoterms = $obj -> location_incoterms ;
2019-06-25 13:00:02 +02:00
$this -> label_incoterms = $obj -> label_incoterms ;
2008-01-31 15:23:57 +01:00
$this -> db -> free ( $result );
2009-02-04 23:12:23 +01:00
2024-06-30 21:04:19 +02:00
if ( $this -> status == 0 ) {
2021-02-25 22:15:04 +01:00
$this -> draft = 1 ;
}
2017-10-03 16:00:52 +02:00
2020-10-23 20:08:35 +02:00
// Retrieve all extrafields
2015-12-16 16:18:29 +01:00
// fetch optionals attributes and labels
2018-02-20 19:38:18 +01:00
$this -> fetch_optionals ();
2009-02-04 23:12:23 +01:00
2019-07-05 21:50:35 +02:00
// Load lines
2020-04-10 10:59:32 +02:00
$result = $this -> fetch_lines ();
2021-02-25 22:15:04 +01:00
if ( $result < 0 ) {
2009-12-17 16:52:37 +01:00
return - 3 ;
}
2009-02-04 23:12:23 +01:00
2009-12-17 16:52:37 +01:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$this -> error = 'Delivery with id ' . $id . ' not found sql=' . $sql ;
2012-01-28 17:34:42 +01:00
dol_syslog ( get_class ( $this ) . '::fetch Error ' . $this -> error , LOG_ERR );
2008-01-31 15:23:57 +01:00
return - 2 ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> error ();
2006-11-11 01:46:15 +01:00
return - 1 ;
}
}
2009-02-04 23:12:23 +01:00
2006-11-11 01:46:15 +01:00
/**
2019-11-28 23:11:37 +01:00
* Validate object and update stock if option enabled
2012-01-28 17:34:42 +01:00
*
2020-10-28 17:49:52 +01:00
* @ param User $user Object user that validate
* @ param int $notrigger 1 = Does not execute triggers , 0 = execute triggers
* @ return int
2009-12-17 16:52:37 +01:00
*/
2020-10-28 17:49:52 +01:00
public function valid ( $user , $notrigger = 0 )
2006-11-11 01:46:15 +01:00
{
2023-03-19 10:19:35 +01:00
global $conf ;
2020-10-28 17:49:52 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2009-02-04 23:12:23 +01:00
2012-01-28 17:34:42 +01:00
dol_syslog ( get_class ( $this ) . " ::valid begin " );
2009-02-04 23:12:23 +01:00
2006-11-11 01:46:15 +01:00
$this -> db -> begin ();
2009-02-04 23:12:23 +01:00
2006-11-11 01:46:15 +01:00
$error = 0 ;
2009-02-04 23:12:23 +01:00
2023-11-27 11:41:05 +01:00
if (( ! getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ) && $user -> hasRight ( 'expedition' , 'delivery' , 'creer' ))
|| ( getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ) && $user -> hasRight ( 'expedition' , 'delivery_advance' , 'validate' ))) {
if ( getDolGlobalString ( 'DELIVERY_ADDON_NUMBER' )) {
2018-09-01 14:28:30 +02:00
// Setting the command numbering module name
2024-01-05 04:18:53 +01:00
$modName = getDolGlobalString ( 'DELIVERY_ADDON_NUMBER' );
2010-05-08 21:21:57 +02:00
2021-02-25 22:15:04 +01:00
if ( is_readable ( DOL_DOCUMENT_ROOT . '/core/modules/delivery/' . $modName . '.php' )) {
2020-10-06 13:32:02 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/modules/delivery/' . $modName . '.php' ;
2012-07-02 17:07:37 +02:00
2020-04-10 10:59:32 +02:00
$now = dol_now ();
2009-02-04 23:12:23 +01:00
2018-09-01 14:28:30 +02:00
// Retrieving the new reference
2006-11-11 01:46:15 +01:00
$objMod = new $modName ( $this -> db );
2024-09-12 21:16:42 +02:00
'@phan-var-force ModeleNumRefDeliveryOrder $objMod' ;
2006-11-11 01:46:15 +01:00
$soc = new Societe ( $this -> db );
$soc -> fetch ( $this -> socid );
2009-02-04 23:12:23 +01:00
2021-02-25 22:15:04 +01:00
if ( preg_match ( '/^[\(]?PROV/i' , $this -> ref ) || empty ( $this -> ref )) { // empty should not happened, but when it occurs, the test save life
2024-07-08 21:46:07 +02:00
$numref = $objMod -> getNextValue ( $soc , $this );
2020-10-28 17:49:52 +01:00
} else {
$numref = $this -> ref ;
}
$this -> newref = dol_sanitizeFileName ( $numref );
2009-02-04 23:12:23 +01:00
2018-09-01 14:28:30 +02:00
// Test if is not already in valid status. If so, we stop to avoid decrementing the stock twice.
2010-03-13 16:52:30 +01:00
$sql = " SELECT ref " ;
2020-10-06 11:04:31 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " delivery " ;
2020-04-10 10:59:32 +02:00
$sql .= " WHERE ref = ' " . $this -> db -> escape ( $numref ) . " ' " ;
$sql .= " AND fk_statut <> 0 " ;
2021-08-23 18:56:46 +02:00
$sql .= " AND entity = " . (( int ) $conf -> entity );
2010-05-08 21:21:57 +02:00
2020-04-10 10:59:32 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-25 22:15:04 +01:00
if ( $resql ) {
2009-12-17 16:52:37 +01:00
$num = $this -> db -> num_rows ( $resql );
2021-02-25 22:15:04 +01:00
if ( $num > 0 ) {
2009-12-17 16:52:37 +01:00
return 0 ;
}
}
2007-05-16 15:38:28 +02:00
2020-10-06 11:04:31 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " delivery SET " ;
2020-04-10 10:59:32 +02:00
$sql .= " ref=' " . $this -> db -> escape ( $numref ) . " ' " ;
$sql .= " , fk_statut = 1 " ;
$sql .= " , date_valid = ' " . $this -> db -> idate ( $now ) . " ' " ;
2024-10-29 02:18:17 +01:00
$sql .= " , fk_user_valid = " . (( int ) $user -> id );
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2020-04-10 10:59:32 +02:00
$sql .= " AND fk_statut = 0 " ;
$resql = $this -> db -> query ( $sql );
2021-02-25 22:15:04 +01:00
if ( ! $resql ) {
2020-10-28 17:49:52 +01:00
dol_print_error ( $this -> db );
$this -> error = $this -> db -> lasterror ();
$error ++ ;
}
2021-02-25 22:15:04 +01:00
if ( ! $error && ! $notrigger ) {
2020-10-28 17:49:52 +01:00
// Call trigger
$result = $this -> call_trigger ( 'DELIVERY_VALIDATE' , $user );
2021-02-25 22:15:04 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2020-10-28 17:49:52 +01:00
// End call triggers
}
2014-10-27 03:24:45 +01:00
2021-02-25 22:15:04 +01:00
if ( ! $error ) {
2020-10-28 17:49:52 +01:00
$this -> oldref = $this -> ref ;
2012-08-22 23:11:24 +02:00
// Rename directory if dir was a temporary ref
2021-02-25 22:15:04 +01:00
if ( preg_match ( '/^[\(]?PROV/i' , $this -> ref )) {
2019-07-28 22:26:55 +02:00
// Now we rename also files into index
2020-04-10 10:59:32 +02:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . " ecm_files set filename = CONCAT(' " . $this -> db -> escape ( $this -> newref ) . " ', SUBSTR(filename, " . ( strlen ( $this -> ref ) + 1 ) . " )), filepath = 'expedition/receipt/ " . $this -> db -> escape ( $this -> newref ) . " ' " ;
2021-08-23 18:56:46 +02:00
$sql .= " WHERE filename LIKE ' " . $this -> db -> escape ( $this -> ref ) . " %' AND filepath = 'expedition/receipt/ " . $this -> db -> escape ( $this -> ref ) . " ' and entity = " . (( int ) $conf -> entity );
2019-07-28 22:26:55 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-25 22:15:04 +01:00
if ( ! $resql ) {
2023-12-04 12:12:12 +01:00
$error ++ ;
$this -> error = $this -> db -> lasterror ();
2021-02-25 22:15:04 +01:00
}
2023-10-31 19:28:11 +01:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . " ecm_files set filepath = 'expedition/receipt/ " . $this -> db -> escape ( $this -> newref ) . " ' " ;
$sql .= " WHERE filepath = 'expedition/receipt/ " . $this -> db -> escape ( $this -> ref ) . " ' and entity = " . $conf -> entity ;
$resql = $this -> db -> query ( $sql );
if ( ! $resql ) {
2023-12-04 12:12:12 +01:00
$error ++ ;
$this -> error = $this -> db -> lasterror ();
2023-10-31 19:28:11 +01:00
}
2019-07-28 22:26:55 +02:00
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
2012-08-22 23:11:24 +02:00
$oldref = dol_sanitizeFileName ( $this -> ref );
$newref = dol_sanitizeFileName ( $numref );
$dirsource = $conf -> expedition -> dir_output . '/receipt/' . $oldref ;
$dirdest = $conf -> expedition -> dir_output . '/receipt/' . $newref ;
2021-02-25 22:15:04 +01:00
if ( ! $error && file_exists ( $dirsource )) {
2012-08-22 23:11:24 +02:00
dol_syslog ( get_class ( $this ) . " ::valid rename dir " . $dirsource . " into " . $dirdest );
2021-02-25 22:15:04 +01:00
if ( @ rename ( $dirsource , $dirdest )) {
2020-10-28 17:49:52 +01:00
dol_syslog ( " Rename ok " );
// Rename docs starting with $oldref with $newref
$listoffiles = dol_dir_list ( $conf -> expedition -> dir_output . '/receipt/' . $newref , 'files' , 1 , '^' . preg_quote ( $oldref , '/' ));
2021-02-25 22:15:04 +01:00
foreach ( $listoffiles as $fileentry ) {
2020-10-28 17:49:52 +01:00
$dirsource = $fileentry [ 'name' ];
$dirdest = preg_replace ( '/^' . preg_quote ( $oldref , '/' ) . '/' , $newref , $dirsource );
$dirsource = $fileentry [ 'path' ] . '/' . $dirsource ;
$dirdest = $fileentry [ 'path' ] . '/' . $dirdest ;
@ rename ( $dirsource , $dirdest );
}
2012-08-22 23:11:24 +02:00
}
}
2006-11-11 01:46:15 +01:00
}
2011-08-31 16:42:47 +02:00
2011-06-17 15:39:38 +02:00
// Set new ref and current status
2021-02-25 22:15:04 +01:00
if ( ! $error ) {
2011-06-17 15:39:38 +02:00
$this -> ref = $numref ;
2024-06-30 21:04:19 +02:00
$this -> status = 1 ;
2011-06-17 15:39:38 +02:00
}
2009-02-04 23:12:23 +01:00
2012-01-28 17:34:42 +01:00
dol_syslog ( get_class ( $this ) . " ::valid ok " );
2006-06-24 19:10:32 +02:00
}
2014-10-27 03:24:45 +01:00
2021-02-25 22:15:04 +01:00
if ( ! $error ) {
2020-10-28 17:49:52 +01:00
$this -> db -> commit ();
return 1 ;
} else {
$this -> db -> rollback ();
return - 1 ;
}
2006-06-24 19:10:32 +02:00
}
}
2023-03-19 10:38:38 +01:00
return - 1 ;
2020-05-21 15:05:19 +02:00
} else {
2023-03-19 10:38:38 +01:00
$this -> error = " NotAllowed " ;
2012-01-28 17:34:42 +01:00
dol_syslog ( get_class ( $this ) . " ::valid " . $this -> error , LOG_ERR );
2006-11-11 01:46:15 +01:00
return - 1 ;
}
}
2009-02-04 23:12:23 +01:00
2020-10-28 17:49:52 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2012-01-28 17:34:42 +01:00
/**
2018-09-01 14:28:30 +02:00
* Creating the delivery slip from an existing shipment
2012-01-28 17:34:42 +01:00
*
2023-03-19 10:19:35 +01:00
* @ param User $user User who creates
* @ param int $sending_id Id of the expedition that serves as a model
2024-09-12 21:16:42 +02:00
* @ return int Return integer <= 0 if KO , > 0 if OK
2009-12-17 16:52:37 +01:00
*/
2020-10-28 17:49:52 +01:00
public function create_from_sending ( $user , $sending_id )
2006-05-30 15:49:03 +02:00
{
2020-10-28 17:49:52 +01:00
// phpcs:enable
2022-05-18 13:37:49 +02:00
global $conf ;
2006-05-30 15:49:03 +02:00
$expedition = new Expedition ( $this -> db );
2020-04-10 10:59:32 +02:00
$result = $expedition -> fetch ( $sending_id );
2023-03-19 10:19:35 +01:00
if ( $result <= 0 ) {
return $result ;
}
2009-02-04 23:12:23 +01:00
2010-12-15 08:49:05 +01:00
$this -> lines = array ();
2009-02-04 23:12:23 +01:00
2020-04-10 10:59:32 +02:00
$num = count ( $expedition -> lines );
2021-02-25 22:15:04 +01:00
for ( $i = 0 ; $i < $num ; $i ++ ) {
2020-10-27 18:38:13 +01:00
$line = new DeliveryLine ( $this -> db );
2010-12-15 08:49:05 +01:00
$line -> origin_line_id = $expedition -> lines [ $i ] -> origin_line_id ;
2020-10-27 18:38:13 +01:00
$line -> label = $expedition -> lines [ $i ] -> label ;
2010-12-15 08:49:05 +01:00
$line -> description = $expedition -> lines [ $i ] -> description ;
$line -> qty = $expedition -> lines [ $i ] -> qty_shipped ;
$line -> fk_product = $expedition -> lines [ $i ] -> fk_product ;
2023-11-27 11:41:05 +01:00
if ( ! getDolGlobalString ( 'MAIN_EXTRAFIELDS_DISABLED' ) && is_array ( $expedition -> lines [ $i ] -> array_options ) && count ( $expedition -> lines [ $i ] -> array_options ) > 0 ) { // For avoid conflicts if trigger used
2021-10-23 22:37:07 +02:00
$line -> array_options = $expedition -> lines [ $i ] -> array_options ;
2021-10-23 22:21:50 +02:00
}
2010-12-15 08:49:05 +01:00
$this -> lines [ $i ] = $line ;
2006-05-30 15:49:03 +02:00
}
2009-02-04 23:12:23 +01:00
2010-03-13 16:52:30 +01:00
$this -> origin = $expedition -> element ;
$this -> origin_id = $expedition -> id ;
2013-04-09 17:18:07 +02:00
$this -> note_private = $expedition -> note_private ;
$this -> note_public = $expedition -> note_public ;
2010-03-11 15:31:16 +01:00
$this -> fk_project = $expedition -> fk_project ;
2010-03-13 16:52:30 +01:00
$this -> date_delivery = $expedition -> date_delivery ;
2010-05-08 21:21:57 +02:00
$this -> fk_delivery_address = $expedition -> fk_delivery_address ;
2008-05-20 02:09:11 +02:00
$this -> socid = $expedition -> socid ;
2020-10-27 18:38:13 +01:00
$this -> ref_customer = $expedition -> ref_customer ;
2017-10-03 16:00:52 +02:00
2015-02-23 09:16:14 +01:00
//Incoterms
2020-04-10 10:59:32 +02:00
$this -> fk_incoterms = $expedition -> fk_incoterms ;
2015-02-23 09:16:14 +01:00
$this -> location_incoterms = $expedition -> location_incoterms ;
2009-02-04 23:12:23 +01:00
2006-05-30 15:49:03 +02:00
return $this -> create ( $user );
}
2009-02-04 23:12:23 +01:00
2020-10-28 17:49:52 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2015-12-16 16:18:29 +01:00
/**
* Update a livraison line ( only extrafields )
*
2024-09-12 21:16:42 +02:00
* @ param int $id Id of line ( livraison line )
* @ param array < string , mixed > $array_options extrafields array
* @ return int Return integer < 0 if KO , > 0 if OK
2015-12-16 16:18:29 +01:00
*/
2024-02-25 22:11:44 +01:00
public function update_line ( $id , $array_options = [])
2015-12-16 16:18:29 +01:00
{
2020-10-28 17:49:52 +01:00
// phpcs:enable
2015-12-16 16:18:29 +01:00
global $conf ;
$error = 0 ;
2017-10-03 16:00:52 +02:00
2023-11-27 11:41:05 +01:00
if ( $id > 0 && ! $error && ! getDolGlobalString ( 'MAIN_EXTRAFIELDS_DISABLED' ) && is_array ( $array_options ) && count ( $array_options ) > 0 ) { // For avoid conflicts if trigger used
2020-10-27 18:38:13 +01:00
$line = new DeliveryLine ( $this -> db );
2020-10-06 11:04:31 +02:00
$line -> array_options = $array_options ;
$line -> id = $id ;
$result = $line -> insertExtraFields ();
2017-10-03 16:00:52 +02:00
2021-02-25 22:15:04 +01:00
if ( $result < 0 ) {
2024-03-13 20:02:25 +01:00
$this -> errors [] = $line -> error ;
2015-12-16 16:18:29 +01:00
$error ++ ;
}
}
2017-10-03 16:00:52 +02:00
2021-02-25 22:15:04 +01:00
if ( ! $error ) {
return 1 ;
} else {
return - 1 ;
}
2015-12-16 16:18:29 +01:00
}
2017-10-03 16:00:52 +02:00
2006-11-11 01:46:15 +01:00
/**
2012-01-28 17:34:42 +01:00
* Add line
2009-12-17 16:52:37 +01:00
*
2021-10-25 11:52:24 +02:00
* @ param int $origin_id Origin id
2024-03-19 15:55:46 +01:00
* @ param float $qty Qty
2024-09-12 21:16:42 +02:00
* @ param array < string , mixed > $array_options Array options
2012-01-28 17:34:42 +01:00
* @ return void
2009-12-17 16:52:37 +01:00
*/
2024-03-10 01:44:08 +01:00
public function addline ( $origin_id , $qty , $array_options = [])
2006-05-05 17:12:48 +02:00
{
2021-10-26 13:52:00 +02:00
$num = count ( $this -> lines );
2020-10-27 18:38:13 +01:00
$line = new DeliveryLine ( $this -> db );
2009-02-04 23:12:23 +01:00
2012-01-28 17:34:42 +01:00
$line -> origin_id = $origin_id ;
2010-12-15 08:49:05 +01:00
$line -> qty = $qty ;
2023-11-27 11:41:05 +01:00
if ( ! getDolGlobalString ( 'MAIN_EXTRAFIELDS_DISABLED' ) && is_array ( $array_options ) && count ( $array_options ) > 0 ) { // For avoid conflicts if trigger used
2021-10-23 22:37:07 +02:00
$line -> array_options = $array_options ;
2021-10-23 22:21:50 +02:00
}
2010-12-15 08:49:05 +01:00
$this -> lines [ $num ] = $line ;
2006-05-05 17:12:48 +02:00
}
2009-02-04 23:12:23 +01:00
2006-11-11 01:46:15 +01:00
/**
2012-01-28 17:34:42 +01:00
* Delete line
2009-12-17 16:52:37 +01:00
*
2012-01-28 17:34:42 +01:00
* @ param int $lineid Line id
2023-12-06 15:46:39 +01:00
* @ return integer Return integer < 0 if KO , 0 if nothing done , > 0 if OK
2009-12-17 16:52:37 +01:00
*/
2024-02-02 23:46:12 +01:00
public function deleteLine ( $lineid )
2006-11-11 01:46:15 +01:00
{
2024-06-30 21:04:19 +02:00
if ( $this -> status == 0 ) {
2009-04-30 18:11:33 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " commandedet " ;
2021-03-30 17:53:25 +02:00
$sql .= " WHERE rowid = " . (( int ) $lineid );
2009-02-04 23:12:23 +01:00
2021-02-25 22:15:04 +01:00
if ( $this -> db -> query ( $sql )) {
2022-11-26 16:28:58 +01:00
$this -> update_price ( 1 );
2010-09-06 23:10:45 +02:00
2006-11-11 01:46:15 +01:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2023-03-19 10:38:38 +01:00
return - 1 ;
2006-11-11 01:46:15 +01:00
}
}
2023-03-19 10:38:38 +01:00
return 0 ;
2006-11-11 01:46:15 +01:00
}
2009-02-04 23:12:23 +01:00
2006-11-11 01:46:15 +01:00
/**
2012-01-28 17:34:42 +01:00
* Delete object
*
2023-11-28 15:33:42 +01:00
* @ param User $user User making the deletion
2016-04-09 19:32:05 +02:00
* @ return integer
2009-12-17 16:52:37 +01:00
*/
2023-11-28 15:33:42 +01:00
public function delete ( $user = null )
2006-11-11 01:46:15 +01:00
{
2023-11-28 15:33:42 +01:00
global $conf , $langs ;
2012-08-05 20:34:51 +02:00
2020-10-28 17:49:52 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2023-11-28 15:33:42 +01:00
2006-11-11 01:46:15 +01:00
$this -> db -> begin ();
2012-07-02 17:07:37 +02:00
2020-04-10 10:59:32 +02:00
$error = 0 ;
2009-02-04 23:12:23 +01:00
2020-10-06 11:04:31 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " deliverydet " ;
2021-08-23 18:56:46 +02:00
$sql .= " WHERE fk_delivery = " . (( int ) $this -> id );
2021-02-25 22:15:04 +01:00
if ( $this -> db -> query ( $sql )) {
2012-02-07 16:47:46 +01:00
// Delete linked object
$res = $this -> deleteObjectLinked ();
2021-02-25 22:15:04 +01:00
if ( $res < 0 ) {
$error ++ ;
}
2012-07-02 17:07:37 +02:00
2021-02-25 22:15:04 +01:00
if ( ! $error ) {
2020-10-06 11:04:31 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " delivery " ;
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2021-02-25 22:15:04 +01:00
if ( $this -> db -> query ( $sql )) {
2010-03-13 16:52:30 +01:00
$this -> db -> commit ();
2010-05-08 21:21:57 +02:00
2020-10-06 11:04:31 +02:00
// Deleting pdf folder's draft On efface le repertoire de pdf provisoire
2012-08-05 20:34:51 +02:00
$ref = dol_sanitizeFileName ( $this -> ref );
2021-02-25 22:15:04 +01:00
if ( ! empty ( $conf -> expedition -> dir_output )) {
2020-04-10 10:59:32 +02:00
$dir = $conf -> expedition -> dir_output . '/receipt/' . $ref ;
$file = $dir . '/' . $ref . '.pdf' ;
2021-02-25 22:15:04 +01:00
if ( file_exists ( $file )) {
if ( ! dol_delete_file ( $file )) {
2010-03-13 16:52:30 +01:00
return 0 ;
}
2006-11-11 01:46:15 +01:00
}
2021-02-25 22:15:04 +01:00
if ( file_exists ( $dir )) {
if ( ! dol_delete_dir ( $dir )) {
2020-04-10 10:59:32 +02:00
$this -> error = $langs -> trans ( " ErrorCanNotDeleteDir " , $dir );
2010-03-13 16:52:30 +01:00
return 0 ;
}
2006-11-11 01:46:15 +01:00
}
}
2010-05-08 21:21:57 +02:00
2020-10-28 17:49:52 +01:00
// Call trigger
$result = $this -> call_trigger ( 'DELIVERY_DELETE' , $user );
2021-02-25 22:15:04 +01:00
if ( $result < 0 ) {
2020-10-28 17:49:52 +01:00
$this -> db -> rollback ();
return - 4 ;
}
// End call triggers
2012-08-05 20:34:51 +02:00
2010-03-13 16:52:30 +01:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> lasterror () . " - sql= $sql " ;
2010-03-13 16:52:30 +01:00
$this -> db -> rollback ();
return - 3 ;
2006-11-11 01:46:15 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> lasterror () . " - sql= $sql " ;
2006-11-11 01:46:15 +01:00
$this -> db -> rollback ();
return - 2 ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> lasterror () . " - sql= $sql " ;
2006-11-11 01:46:15 +01:00
$this -> db -> rollback ();
return - 1 ;
}
}
2009-02-04 23:12:23 +01:00
2023-02-02 23:12:54 +01:00
/**
* getTooltipContentArray
2024-09-12 21:16:42 +02:00
* @ param array < string , mixed > $params params to construct tooltip data
2023-02-02 23:12:54 +01:00
* @ since v18
2024-09-23 03:24:19 +02:00
* @ return array { picto ? : string , ref ? : string , refsupplier ? : string , label ? : string , date ? : string , date_echeance ? : string , amountht ? : string , total_ht ? : string , totaltva ? : string , amountlt1 ? : string , amountlt2 ? : string , amountrevenustamp ? : string , totalttc ? : string } | array { optimize : string }
2023-02-02 23:12:54 +01:00
*/
public function getTooltipContentArray ( $params )
{
2023-03-19 10:19:35 +01:00
global $langs ;
2023-02-02 23:12:54 +01:00
2023-11-22 09:32:08 +01:00
$langs -> load ( 'deliveries' );
2023-02-02 23:12:54 +01:00
$datas = [];
2024-10-24 00:26:36 +02:00
$datas [ 'picto' ] = img_picto ( '' , $this -> picto , '' , 0 , 0 , 0 , '' , 'paddingrightonly' ) . ' <u>' . $langs -> trans ( " ShowReceiving " ) . '</u>:<br>' ;
$datas [ 'ref' ] = '<b>' . $langs -> trans ( " Ref " ) . '</b>: ' . $this -> ref ;
2023-02-02 23:12:54 +01:00
return $datas ;
}
2010-05-27 00:54:48 +02:00
/**
2024-08-07 01:20:43 +02:00
* Return clickable name ( with picto eventually )
2012-01-28 17:34:42 +01:00
*
2025-01-18 23:15:39 +01:00
* @ param int < 0 , 2 > $withpicto 0 = No picto , 1 = Include picto into link , 2 = Only picto
* @ param int <- 1 , 1 > $save_lastsearch_value - 1 = Auto , 0 = No save of lastsearch_values when clicking , 1 = Save lastsearch_values whenclicking
2017-10-03 16:00:52 +02:00
* @ return string Chaine avec URL
2010-05-27 00:54:48 +02:00
*/
2020-10-28 17:49:52 +01:00
public function getNomUrl ( $withpicto = 0 , $save_lastsearch_value = - 1 )
2010-05-27 00:54:48 +02:00
{
2021-11-22 19:57:26 +01:00
global $langs , $hookmanager ;
2010-05-27 00:54:48 +02:00
2020-04-10 10:59:32 +02:00
$result = '' ;
2010-05-27 00:54:48 +02:00
2023-02-06 21:59:32 +01:00
$params = [
'id' => $this -> id ,
'objecttype' => $this -> element ,
];
$classfortooltip = 'classfortooltip' ;
$dataparams = '' ;
if ( getDolGlobalInt ( 'MAIN_ENABLE_AJAX_TOOLTIP' )) {
$classfortooltip = 'classforajaxtooltip' ;
2023-04-03 19:51:40 +02:00
$dataparams = ' data-params="' . dol_escape_htmltag ( json_encode ( $params )) . '"' ;
$label = '' ;
} else {
$label = implode ( $this -> getTooltipContentArray ( $params ));
2023-02-06 21:59:32 +01:00
}
2010-05-27 00:54:48 +02:00
2020-10-05 15:32:29 +02:00
$url = DOL_URL_ROOT . '/delivery/card.php?id=' . $this -> id ;
2017-10-03 16:00:52 +02:00
2020-10-28 17:49:52 +01:00
//if ($option !== 'nolink')
//{
2021-10-26 13:52:00 +02:00
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ( $save_lastsearch_value == 1 ? 1 : 0 );
2023-09-10 17:41:22 +02:00
if ( $save_lastsearch_value == - 1 && isset ( $_SERVER [ " PHP_SELF " ]) && preg_match ( '/list\.php/' , $_SERVER [ " PHP_SELF " ])) {
2021-02-25 22:15:04 +01:00
$add_save_lastsearch_values = 1 ;
}
if ( $add_save_lastsearch_values ) {
$url .= '&save_lastsearch_values=1' ;
}
2020-10-28 17:49:52 +01:00
//}
2010-05-27 00:54:48 +02:00
2023-04-03 19:51:40 +02:00
$linkstart = '<a href="' . $url . '"' ;
2025-01-09 02:01:49 +01:00
$linkstart .= ( $label ? ' title="' . dolPrintHTMLForAttribute ( $label ) . '"' : ' title="tocomplete"' );
2023-04-03 19:51:40 +02:00
$linkstart .= $dataparams . ' class="' . $classfortooltip . '">' ;
2020-04-10 10:59:32 +02:00
$linkend = '</a>' ;
2017-10-03 16:00:52 +02:00
2021-02-25 22:15:04 +01:00
if ( $withpicto ) {
2023-02-05 20:54:18 +01:00
$result .= ( $linkstart . img_object ( $label , $this -> picto , $dataparams . ' class="' . $classfortooltip . '"' ) . $linkend );
2021-02-25 22:15:04 +01:00
}
if ( $withpicto && $withpicto != 2 ) {
$result .= ' ' ;
}
2020-04-10 10:59:32 +02:00
$result .= $linkstart . $this -> ref . $linkend ;
2021-11-22 19:57:26 +01:00
global $action ;
2022-02-15 19:04:18 +01:00
$hookmanager -> initHooks ( array ( $this -> element . 'dao' ));
2024-03-13 20:02:25 +01:00
$parameters = array ( 'id' => $this -> id , 'getnomurl' => & $result );
2021-11-22 19:57:26 +01:00
$reshook = $hookmanager -> executeHooks ( 'getNomUrl' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook > 0 ) {
$result = $hookmanager -> resPrint ;
} else {
$result .= $hookmanager -> resPrint ;
}
2010-05-27 00:54:48 +02:00
return $result ;
}
2020-10-28 17:49:52 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2009-12-17 16:52:37 +01:00
/**
2022-05-18 13:37:49 +02:00
* Load lines insto $this -> lines .
2009-12-17 16:52:37 +01:00
*
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2009-12-17 16:52:37 +01:00
*/
2020-10-28 17:49:52 +01:00
public function fetch_lines ()
2006-11-11 01:46:15 +01:00
{
2020-10-28 17:49:52 +01:00
// phpcs:enable
2010-12-15 08:49:05 +01:00
$this -> lines = array ();
2009-02-04 23:12:23 +01:00
2014-06-28 22:48:20 +02:00
$sql = " SELECT ld.rowid, ld.fk_product, ld.description, ld.subprice, ld.total_ht, ld.qty as qty_shipped, ld.fk_origin_line, " ;
2020-04-10 10:59:32 +02:00
$sql .= " cd.qty as qty_asked, cd.label as custom_label, cd.fk_unit, " ;
$sql .= " p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc, " ;
$sql .= " p.weight, p.weight_units, p.width, p.width_units, p.length, p.length_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tobatch as product_tobatch " ;
2020-10-06 11:04:31 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " commandedet as cd, " . MAIN_DB_PREFIX . " deliverydet as ld " ;
2020-04-10 10:59:32 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product as p on p.rowid = ld.fk_product " ;
$sql .= " WHERE ld.fk_origin_line = cd.rowid " ;
2021-08-23 18:56:46 +02:00
$sql .= " AND ld.fk_delivery = " . (( int ) $this -> id );
2008-08-05 16:22:11 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch_lines " , LOG_DEBUG );
2006-11-11 01:46:15 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-25 22:15:04 +01:00
if ( $resql ) {
2006-11-11 01:46:15 +01:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-25 22:15:04 +01:00
while ( $i < $num ) {
2006-11-11 01:46:15 +01:00
$obj = $this -> db -> fetch_object ( $resql );
2008-08-05 16:22:11 +02:00
2022-03-28 13:50:47 +02:00
$line = new DeliveryLine ( $this -> db );
2020-04-10 10:59:32 +02:00
$line -> id = $obj -> rowid ;
$line -> label = $obj -> custom_label ;
2023-08-06 01:14:36 +02:00
$line -> description = $obj -> description ;
$line -> fk_product = $obj -> fk_product ;
$line -> qty_asked = $obj -> qty_asked ;
$line -> qty_shipped = $obj -> qty_shipped ;
2012-08-25 15:21:34 +02:00
2020-04-10 10:59:32 +02:00
$line -> product_label = $obj -> product_label ; // Product label
2023-08-06 01:14:36 +02:00
$line -> product_ref = $obj -> product_ref ; // Product ref
2020-04-10 10:59:32 +02:00
$line -> product_desc = $obj -> product_desc ; // Product description
2012-08-25 15:21:34 +02:00
$line -> product_type = $obj -> fk_product_type ;
2023-08-06 01:14:36 +02:00
2020-04-10 10:59:32 +02:00
$line -> fk_origin_line = $obj -> fk_origin_line ;
2012-08-25 15:21:34 +02:00
2023-02-04 10:25:35 +01:00
$line -> price = $obj -> subprice ;
2020-04-10 10:59:32 +02:00
$line -> total_ht = $obj -> total_ht ;
2009-02-04 23:12:23 +01:00
2020-04-02 12:55:06 +02:00
// units
2020-03-31 09:20:48 +02:00
$line -> weight = $obj -> weight ;
$line -> weight_units = $obj -> weight_units ;
$line -> width = $obj -> width ;
$line -> width_units = $obj -> width_units ;
$line -> height = $obj -> height ;
$line -> height_units = $obj -> height_units ;
$line -> length = $obj -> length ;
$line -> length_units = $obj -> length_units ;
$line -> surface = $obj -> surface ;
2020-04-10 10:59:32 +02:00
$line -> surface_units = $obj -> surface_units ;
2020-03-31 09:20:48 +02:00
$line -> volume = $obj -> volume ;
$line -> volume_units = $obj -> volume_units ;
2020-03-31 09:23:36 +02:00
2020-04-10 10:59:32 +02:00
$line -> fk_unit = $obj -> fk_unit ;
2020-10-27 23:01:28 +01:00
$line -> fetch_optionals ();
2020-03-31 09:23:36 +02:00
2010-09-09 16:06:15 +02:00
$this -> lines [ $i ] = $line ;
2010-09-19 18:25:24 +02:00
2006-11-11 01:46:15 +01:00
$i ++ ;
}
$this -> db -> free ( $resql );
2009-02-04 23:12:23 +01:00
2022-05-18 13:37:49 +02:00
return 1 ;
} else {
return - 1 ;
}
2006-11-11 01:46:15 +01:00
}
2006-06-24 19:10:32 +02:00
2009-12-17 16:52:37 +01:00
/**
2023-04-08 15:08:55 +02:00
* Return the label of the status
2012-01-28 17:34:42 +01:00
*
2023-04-08 15:08:55 +02:00
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto , 6 = Long label + Picto
* @ return string Label of status
2009-12-17 16:52:37 +01:00
*/
2020-10-28 17:49:52 +01:00
public function getLibStatut ( $mode = 0 )
2009-12-17 16:52:37 +01:00
{
2024-06-30 21:04:19 +02:00
return $this -> LibStatut ( $this -> status , $mode );
2009-12-17 16:52:37 +01:00
}
2009-02-04 23:12:23 +01:00
2020-10-28 17:49:52 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2008-08-05 16:22:11 +02:00
/**
2023-04-08 15:08:55 +02:00
* Return the label of a given status
2012-01-28 17:34:42 +01:00
*
2023-04-08 15:08:55 +02:00
* @ param int $status Id status
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto , 6 = Long label + Picto
* @ return string Label of status
2006-11-11 01:46:15 +01:00
*/
2020-10-28 17:49:52 +01:00
public function LibStatut ( $status , $mode )
2009-12-17 16:52:37 +01:00
{
2020-10-28 17:49:52 +01:00
// phpcs:enable
2006-11-11 01:46:15 +01:00
global $langs ;
2021-02-25 22:15:04 +01:00
if ( empty ( $this -> labelStatus ) || empty ( $this -> labelStatusShort )) {
2020-01-28 02:21:39 +01:00
global $langs ;
//$langs->load("mymodule");
2021-10-16 19:37:57 +02:00
$this -> labelStatus [ - 1 ] = $langs -> transnoentitiesnoconv ( 'StatusDeliveryCanceled' );
$this -> labelStatus [ 0 ] = $langs -> transnoentitiesnoconv ( 'StatusDeliveryDraft' );
$this -> labelStatus [ 1 ] = $langs -> transnoentitiesnoconv ( 'StatusDeliveryValidated' );
$this -> labelStatusShort [ - 1 ] = $langs -> transnoentitiesnoconv ( 'StatusDeliveryCanceled' );
$this -> labelStatusShort [ 0 ] = $langs -> transnoentitiesnoconv ( 'StatusDeliveryDraft' );
$this -> labelStatusShort [ 1 ] = $langs -> transnoentitiesnoconv ( 'StatusDeliveryValidated' );
2016-10-29 16:18:39 +02:00
}
2020-01-28 02:21:39 +01:00
$statusType = 'status0' ;
2021-02-25 22:15:04 +01:00
if ( $status == - 1 ) {
$statusType = 'status5' ;
}
if ( $status == 1 ) {
$statusType = 'status4' ;
}
2020-01-28 02:21:39 +01:00
return dolGetStatus ( $this -> labelStatus [ $status ], $this -> labelStatusShort [ $status ], '' , $statusType , $mode );
2009-12-17 16:52:37 +01:00
}
2008-09-02 12:11:40 +02:00
2009-02-04 23:12:23 +01:00
2008-07-05 16:20:03 +02:00
/**
2020-10-28 17:49:52 +01:00
* Initialise an instance with random values .
* Used to build previews or test instances .
* id must be 0 if object instance is a specimen .
*
2024-03-02 16:38:35 +01:00
* @ return int
2008-07-05 16:20:03 +02:00
*/
2020-10-28 17:49:52 +01:00
public function initAsSpecimen ()
2008-07-05 16:20:03 +02:00
{
2020-04-10 10:59:32 +02:00
$now = dol_now ();
2011-08-31 16:42:47 +02:00
2020-10-28 17:49:52 +01:00
// Load array of products prodids
2016-06-28 02:36:40 +02:00
$num_prods = 0 ;
2008-07-05 16:20:03 +02:00
$prodids = array ();
2009-04-30 18:11:33 +02:00
$sql = " SELECT rowid " ;
2020-04-10 10:59:32 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " product " ;
$sql .= " WHERE entity IN ( " . getEntity ( 'product' ) . " ) " ;
$sql .= " AND tosell = 1 " ;
2020-08-19 01:43:48 +02:00
$sql .= $this -> db -> plimit ( 100 );
2008-07-05 16:20:03 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-25 22:15:04 +01:00
if ( $resql ) {
2008-07-05 16:20:03 +02:00
$num_prods = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-25 22:15:04 +01:00
while ( $i < $num_prods ) {
2008-07-05 16:20:03 +02:00
$i ++ ;
$row = $this -> db -> fetch_row ( $resql );
$prodids [ $i ] = $row [ 0 ];
}
}
2024-01-13 19:48:41 +01:00
// Initialise parameters
2020-04-10 10:59:32 +02:00
$this -> id = 0 ;
2012-04-21 18:40:37 +02:00
$this -> ref = 'SPECIMEN' ;
2020-04-10 10:59:32 +02:00
$this -> specimen = 1 ;
2010-09-19 18:25:24 +02:00
$this -> socid = 1 ;
2011-08-31 16:42:47 +02:00
$this -> date_delivery = $now ;
2020-04-10 10:59:32 +02:00
$this -> note_public = 'Public note' ;
$this -> note_private = 'Private note' ;
2008-09-02 14:19:00 +02:00
2020-04-10 10:59:32 +02:00
$i = 0 ;
2020-10-27 18:38:13 +01:00
$line = new DeliveryLine ( $this -> db );
2023-05-05 12:43:09 +02:00
$line -> fk_product = reset ( $prodids );
2010-12-15 08:49:05 +01:00
$line -> qty_asked = 10 ;
$line -> qty_shipped = 9 ;
2024-06-30 21:04:19 +02:00
$line -> product_ref = 'REFPROD' ;
2010-12-15 08:49:05 +01:00
$line -> label = 'Specimen' ;
$line -> description = 'Description' ;
$line -> price = 100 ;
$line -> total_ht = 100 ;
2011-03-09 16:34:57 +01:00
2010-12-15 08:49:05 +01:00
$this -> lines [ $i ] = $line ;
2024-03-02 16:38:35 +01:00
return 1 ;
2008-07-05 16:20:03 +02:00
}
2010-05-08 21:21:57 +02:00
2010-01-15 11:07:20 +01:00
/**
2024-09-12 21:16:42 +02:00
* Get data list of Products remaining to be delivered for an order ( with qty )
2012-01-28 17:34:42 +01:00
*
2024-09-12 21:16:42 +02:00
* @ return array < int , array { qty : float | int , ref : string , label : string } >| int < min , - 1 > Product remaining to be delivered or < 0 if KO
2012-01-28 17:34:42 +01:00
* TODO use new function
2010-01-15 11:07:20 +01:00
*/
2020-10-28 17:49:52 +01:00
public function getRemainingDelivered ()
2010-01-15 11:07:20 +01:00
{
2010-01-18 10:50:33 +01:00
// Get the linked object
2024-09-12 21:16:42 +02:00
$this -> fetchObjectLinked ( null , '' , $this -> id , $this -> element );
2020-10-27 18:40:44 +01:00
//var_dump($this->linkedObjectsIds);
2010-01-15 11:07:20 +01:00
// Get the product ref and qty in source
2010-01-18 10:50:33 +01:00
$sqlSourceLine = " SELECT st.rowid, st.description, st.qty " ;
2020-04-10 10:59:32 +02:00
$sqlSourceLine .= " , p.ref, p.label " ;
2020-10-27 18:40:44 +01:00
$sqlSourceLine .= " FROM " . MAIN_DB_PREFIX . $this -> linkedObjectsIds [ 0 ][ 'type' ] . " det as st " ;
2020-04-10 10:59:32 +02:00
$sqlSourceLine .= " LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON st.fk_product = p.rowid " ;
2022-09-12 16:51:25 +02:00
$sqlSourceLine .= " WHERE fk_ " . $this -> linked_objects [ 0 ][ 'type' ] . " = " . (( int ) $this -> linked_objects [ 0 ][ 'linkid' ]);
2010-01-18 10:50:33 +01:00
2010-01-15 11:07:20 +01:00
$resultSourceLine = $this -> db -> query ( $sqlSourceLine );
2021-02-25 22:15:04 +01:00
if ( $resultSourceLine ) {
2010-01-15 11:07:20 +01:00
$num_lines = $this -> db -> num_rows ( $resultSourceLine );
$i = 0 ;
2022-05-18 13:37:49 +02:00
$array = array ();
2021-02-25 22:15:04 +01:00
while ( $i < $num_lines ) {
2010-01-15 11:07:20 +01:00
$objSourceLine = $this -> db -> fetch_object ( $resultSourceLine );
2010-05-08 21:21:57 +02:00
2024-01-13 19:48:41 +01:00
// Get lines of sources already delivered
2010-01-18 10:50:33 +01:00
$sql = " SELECT ld.fk_origin_line, sum(ld.qty) as qty " ;
2020-10-06 11:04:31 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " deliverydet as ld, " . MAIN_DB_PREFIX . " delivery as l, " ;
2022-09-12 16:51:25 +02:00
$sql .= " " . MAIN_DB_PREFIX . $this -> linked_objects [ 0 ][ 'type' ] . " as c " ;
$sql .= " , " . MAIN_DB_PREFIX . $this -> linked_objects [ 0 ][ 'type' ] . " det as cd " ;
2020-10-06 11:04:31 +02:00
$sql .= " WHERE ld.fk_delivery = l.rowid " ;
2020-04-10 10:59:32 +02:00
$sql .= " AND ld.fk_origin_line = cd.rowid " ;
2022-09-12 16:51:25 +02:00
$sql .= " AND cd.fk_ " . $this -> linked_objects [ 0 ][ 'type' ] . " = c.rowid " ;
$sql .= " AND cd.fk_ " . $this -> linked_objects [ 0 ][ 'type' ] . " = " . (( int ) $this -> linked_objects [ 0 ][ 'linkid' ]);
2021-08-23 18:56:46 +02:00
$sql .= " AND ld.fk_origin_line = " . (( int ) $objSourceLine -> rowid );
2020-04-10 10:59:32 +02:00
$sql .= " GROUP BY ld.fk_origin_line " ;
2010-05-08 21:21:57 +02:00
2010-01-18 10:50:33 +01:00
$result = $this -> db -> query ( $sql );
2010-01-15 11:07:20 +01:00
$row = $this -> db -> fetch_row ( $result );
2010-05-08 21:21:57 +02:00
2021-02-25 22:15:04 +01:00
if ( $objSourceLine -> qty - $row [ 1 ] > 0 ) {
if ( $row [ 0 ] == $objSourceLine -> rowid ) {
2010-01-18 10:50:33 +01:00
$array [ $i ][ 'qty' ] = $objSourceLine -> qty - $row [ 1 ];
2020-05-21 15:05:19 +02:00
} else {
2010-01-18 10:50:33 +01:00
$array [ $i ][ 'qty' ] = $objSourceLine -> qty ;
2010-01-15 11:07:20 +01:00
}
2010-05-08 21:21:57 +02:00
2010-01-18 10:50:33 +01:00
$array [ $i ][ 'ref' ] = $objSourceLine -> ref ;
2020-04-10 10:59:32 +02:00
$array [ $i ][ 'label' ] = $objSourceLine -> label ? $objSourceLine -> label : $objSourceLine -> description ;
2021-02-25 22:15:04 +01:00
} elseif ( $objSourceLine -> qty - $row [ 1 ] < 0 ) {
2020-04-10 10:59:32 +02:00
$array [ $i ][ 'qty' ] = $objSourceLine -> qty - $row [ 1 ] . " Erreur livraison ! " ;
2010-01-18 10:50:33 +01:00
$array [ $i ][ 'ref' ] = $objSourceLine -> ref ;
2020-04-10 10:59:32 +02:00
$array [ $i ][ 'label' ] = $objSourceLine -> label ? $objSourceLine -> label : $objSourceLine -> description ;
2010-01-15 11:07:20 +01:00
}
2010-05-08 21:21:57 +02:00
2021-10-26 13:52:00 +02:00
$i ++ ;
2010-01-15 11:07:20 +01:00
}
2010-01-18 10:50:33 +01:00
return $array ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> error () . " - sql= $sqlSourceLine " ;
2010-01-18 10:50:33 +01:00
return - 1 ;
}
2010-01-15 11:07:20 +01:00
}
2010-05-08 21:21:57 +02:00
2020-10-31 14:32:18 +01:00
/**
2013-08-07 15:08:30 +02:00
* Set the planned delivery date
*
2024-01-13 19:48:41 +01:00
* @ param User $user Object utilisateur qui modifie
2020-10-06 11:37:55 +02:00
* @ param integer $delivery_date Delivery date
2023-12-01 19:51:32 +01:00
* @ return int Return integer < 0 if KO , > 0 if OK
2013-08-07 15:08:30 +02:00
*/
2020-10-31 14:32:18 +01:00
public function setDeliveryDate ( $user , $delivery_date )
2013-08-07 15:08:30 +02:00
{
2023-10-15 18:12:03 +02:00
if ( $user -> hasRight ( 'expedition' , 'creer' )) {
2020-10-06 11:04:31 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " delivery " ;
2020-10-06 11:37:55 +02:00
$sql .= " SET date_delivery = " . ( $delivery_date ? " ' " . $this -> db -> idate ( $delivery_date ) . " ' " : 'null' );
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2013-08-07 15:08:30 +02:00
2020-10-26 16:50:52 +01:00
dol_syslog ( get_class ( $this ) . " ::setDeliveryDate " , LOG_DEBUG );
2020-04-10 10:59:32 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-25 22:15:04 +01:00
if ( $resql ) {
2020-10-06 11:37:55 +02:00
$this -> date_delivery = $delivery_date ;
2013-08-07 15:08:30 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> error ();
2013-08-07 15:08:30 +02:00
return - 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2013-08-07 15:08:30 +02:00
return - 2 ;
}
}
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
/**
* Create object on disk
*
2015-09-06 12:30:41 +02:00
* @ param string $modele force le modele a utiliser ( '' to not force )
* @ param Translate $outputlangs Object langs to use for output
* @ param int $hidedetails Hide details of lines
* @ param int $hidedesc Hide description
* @ param int $hideref Hide ref
* @ return int 0 if KO , 1 if OK
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
*/
2024-02-12 17:55:32 +01:00
public function generateDocument ( $modele , $outputlangs , $hidedetails = 0 , $hidedesc = 0 , $hideref = 0 )
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
{
2023-03-19 10:19:35 +01:00
global $conf , $langs ;
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
$langs -> load ( " deliveries " );
2020-08-04 11:02:16 +02:00
$outputlangs -> load ( " products " );
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
2020-04-10 10:59:32 +02:00
if ( ! dol_strlen ( $modele )) {
2017-01-16 21:16:05 +01:00
$modele = 'typhon' ;
2020-09-10 01:49:09 +02:00
if ( $this -> model_pdf ) {
$modele = $this -> model_pdf ;
2023-11-27 11:41:05 +01:00
} elseif ( getDolGlobalString ( 'DELIVERY_ADDON_PDF' )) {
2024-01-05 04:18:53 +01:00
$modele = getDolGlobalString ( 'DELIVERY_ADDON_PDF' );
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
}
}
2020-10-06 13:32:02 +02:00
$modelpath = " core/modules/delivery/doc/ " ;
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
2015-09-06 12:30:41 +02:00
return $this -> commonGenerateDocument ( $modelpath , $modele , $outputlangs , $hidedetails , $hidedesc , $hideref );
Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create
2014-09-16 12:30:37 +02:00
}
2015-04-18 18:11:01 +02:00
/**
* Function used to replace a thirdparty id with another one .
*
2022-12-28 13:27:13 +01:00
* @ param DoliDB $dbs Database handler , because function is static we name it $dbs not $db to avoid breaking coding test
* @ param int $origin_id Old thirdparty id
* @ param int $dest_id New thirdparty id
* @ return bool
2015-04-18 18:11:01 +02:00
*/
2022-12-28 13:27:13 +01:00
public static function replaceThirdparty ( DoliDB $dbs , $origin_id , $dest_id )
2015-04-18 18:11:01 +02:00
{
$tables = array (
2020-10-06 13:32:02 +02:00
'delivery'
2015-04-18 18:11:01 +02:00
);
2022-12-28 13:27:13 +01:00
return CommonObject :: commonReplaceThirdparty ( $dbs , $origin_id , $dest_id , $tables );
2021-11-23 21:38:29 +01:00
}
/**
* Function used to replace a product id with another one .
*
* @ param DoliDB $db Database handler
* @ param int $origin_id Old product id
* @ param int $dest_id New product id
* @ return bool
*/
public static function replaceProduct ( DoliDB $db , $origin_id , $dest_id )
{
$tables = array (
'deliverydet'
);
return CommonObject :: commonReplaceProduct ( $db , $origin_id , $dest_id , $tables );
2015-04-18 18:11:01 +02:00
}
2006-05-05 17:12:48 +02:00
}
2006-11-11 01:46:15 +01:00
/**
2018-09-01 14:13:05 +02:00
* Management class of delivery note lines
2009-12-17 16:52:37 +01:00
*/
2020-10-27 18:38:13 +01:00
class DeliveryLine extends CommonObjectLine
2006-05-05 17:12:48 +02:00
{
2020-10-31 14:32:18 +01:00
/**
* @ var DoliDB Database handler .
*/
public $db ;
/**
* @ var string ID to identify managed object
*/
public $element = 'deliverydet' ;
/**
* @ var string Name of table without prefix where object is stored
*/
public $table_element = 'deliverydet' ;
/**
* @ var string delivery note lines label
*/
public $label ;
2018-09-02 23:25:10 +02:00
2018-08-31 19:26:08 +02:00
/**
2018-09-01 14:28:30 +02:00
* @ var string product description
2018-08-31 19:26:08 +02:00
*/
public $description ;
2015-04-23 23:21:06 +02:00
/**
* @ deprecated
2019-04-08 16:04:15 +02:00
* @ see $product_ref
2024-09-12 21:16:42 +02:00
* @ var string
2015-04-23 23:21:06 +02:00
*/
2018-09-04 21:16:17 +02:00
public $ref ;
2015-04-23 23:21:06 +02:00
/**
* @ deprecated
* @ see product_label ;
2024-09-12 21:16:42 +02:00
* @ var string
2015-04-23 23:21:06 +02:00
*/
2018-09-04 21:16:17 +02:00
public $libelle ;
2015-04-23 23:21:06 +02:00
2022-05-18 13:37:49 +02:00
// From llx_expeditiondet
2024-06-04 14:46:54 +02:00
/**
* @ var float Quantity
*/
2022-05-18 13:37:49 +02:00
public $qty ;
2024-06-04 14:46:54 +02:00
/**
* @ var float Quantity asked
*/
2022-05-18 13:37:49 +02:00
public $qty_asked ;
2024-06-04 14:46:54 +02:00
/**
2024-09-12 21:16:42 +02:00
* @ var float Quantity shipped
2024-06-04 14:46:54 +02:00
*/
2022-05-18 13:37:49 +02:00
public $qty_shipped ;
2020-10-27 18:38:13 +01:00
2024-09-12 21:16:42 +02:00
/**
* @ var int
*/
2022-05-18 13:37:49 +02:00
public $fk_product ;
2024-09-12 21:16:42 +02:00
/**
* @ var string
*/
2022-05-18 13:37:49 +02:00
public $product_desc ;
2024-09-12 21:16:42 +02:00
/**
* @ var int
*/
2022-05-18 13:37:49 +02:00
public $product_type ;
2024-09-12 21:16:42 +02:00
/**
* @ var string
*/
2015-04-23 23:21:06 +02:00
public $product_ref ;
2024-09-12 21:16:42 +02:00
/**
* @ var string
*/
2015-04-23 23:21:06 +02:00
public $product_label ;
2017-10-03 16:00:52 +02:00
2024-09-12 21:16:42 +02:00
/**
* @ var int | float | string
*/
2023-02-23 21:16:25 +01:00
public $price ;
2024-09-12 21:16:42 +02:00
/**
* @ var int
*/
2022-05-18 13:37:49 +02:00
public $fk_origin_line ;
2024-09-12 21:16:42 +02:00
/**
* @ var int
*/
2022-05-18 13:37:49 +02:00
public $origin_id ;
2023-02-23 21:16:25 +01:00
/**
* @ var int origin line ID
*/
2022-05-18 13:37:49 +02:00
public $origin_line_id ;
2023-02-23 21:16:25 +01:00
/**
* @ var int origin line ID
* @ deprecated
* @ see $origin_line_id
*/
public $commande_ligne_id ;
2022-05-18 13:37:49 +02:00
2020-10-28 17:49:52 +01:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
public function __construct ( $db )
{
$this -> db = $db ;
}
2006-05-05 17:12:48 +02:00
}