PageRenderTime 115ms CodeModel.GetById 45ms app.highlight 60ms RepoModel.GetById 1ms app.codeStats 1ms

/htdocs/expedition/class/expedition.class.php

https://bitbucket.org/speedealing/speedealing
PHP | 1283 lines | 910 code | 161 blank | 212 comment | 138 complexity | ac1ba68ef6f0526210ef37ff55c440e6 MD5 | raw file
   1<?php
   2/* Copyright (C) 2003-2008 Rodolphe Quiedeville  <rodolphe@quiedeville.org>
   3 * Copyright (C) 2005-2011 Regis Houssin         <regis.houssin@capnetworks.com>
   4 * Copyright (C) 2007      Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
   5 * Copyright (C) 2006-2008 Laurent Destailleur   <eldy@users.sourceforge.net>
   6 * Copyright (C) 2011-2012 Juanjo Menent		 <jmenent@2byte.es>
   7 *
   8 * This program is free software; you can redistribute it and/or modify
   9 * it under the terms of the GNU General Public License as published by
  10 * the Free Software Foundation; either version 3 of the License, or
  11 * (at your option) any later version.
  12 *
  13 * This program is distributed in the hope that it will be useful,
  14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16 * GNU General Public License for more details.
  17 *
  18 * You should have received a copy of the GNU General Public License
  19 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20 */
  21
  22/**
  23 *  \file       htdocs/expedition/class/expedition.class.php
  24 *  \ingroup    expedition
  25 *  \brief      Fichier de la classe de gestion des expeditions
  26 */
  27
  28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  29if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  30if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  31
  32
  33/**
  34 *	Class to manage shipments
  35 */
  36class Expedition extends CommonObject
  37{
  38	public $element="shipping";
  39	public $fk_element="fk_expedition";
  40	public $table_element="expedition";
  41
  42	var $id;
  43	var $socid;
  44	var $ref_customer;
  45	var $ref_ext;
  46	var $ref_int;
  47	var $brouillon;
  48	var $entrepot_id;
  49	var $modelpdf;
  50	var $origin;
  51	var $origin_id;
  52	var $lines=array();
  53	var $expedition_method_id; // deprecated
  54	var $shipping_method_id;
  55	var $tracking_number;
  56	var $tracking_url;
  57	var $statut;
  58	var $billed;
  59
  60	var $trueWeight;
  61	var $weight_units;
  62	var $trueWidth;
  63	var $width_units;
  64	var $trueHeight;
  65	var $height_units;
  66	var $trueDepth;
  67	var $depth_units;
  68	// A denormalized value
  69	var $trueSize;
  70
  71	var $date_delivery;		// Date delivery planed
  72	var $date_expedition;	// Date delivery real
  73	var $date_creation;
  74	var $date_valid;
  75
  76	// For Invoicing
  77	var $total_ht;			// Total net of tax
  78	var $total_ttc;			// Total with tax
  79	var $total_tva;			// Total VAT
  80	var $total_localtax1;   // Total Local tax 1
  81	var $total_localtax2;   // Total Local tax 2
  82
  83
  84	/**
  85	 *	Constructor
  86	 *
  87	 *  @param		DoliDB		$db      Database handler
  88	 */
  89	function __construct($db = '')
  90	{
  91		$this->db = $db;
  92		$this->lines = array();
  93		$this->products = array();
  94
  95		// List of long language codes for status
  96		$this->statuts[-1] = 'StatusSendingCanceled';
  97		$this->statuts[0]  = 'StatusSendingDraft';
  98		$this->statuts[1]  = 'StatusSendingValidated';
  99		$this->statuts[2]  = 'StatusSendingProcessed';
 100	}
 101
 102	/**
 103	 *	Return next contract ref
 104	 *
 105	 *	@param	Societe		$soc	Objet society
 106	 *	@return string				Free reference for contract
 107	 */
 108	function getNextNumRef($soc)
 109	{
 110		global $db, $langs, $conf;
 111		$langs->load("sendings");
 112
 113		$dir = DOL_DOCUMENT_ROOT . "/core/modules/expedition";
 114
 115	    if (empty($conf->global->EXPEDITION_ADDON_NUMBER))
 116        {
 117            $conf->global->EXPEDITION_ADDON_NUMBER='mod_expedition_safor';
 118        }
 119
 120		$file = $conf->global->EXPEDITION_ADDON_NUMBER.".php";
 121
 122		// Chargement de la classe de numerotation
 123		$classname = $conf->global->EXPEDITION_ADDON_NUMBER;
 124
 125		$result=include_once $dir.'/'.$file;
 126		if ($result)
 127		{
 128			$obj = new $classname();
 129			$numref = "";
 130			$numref = $obj->getNextValue($soc,$this);
 131
 132			if ( $numref != "")
 133			{
 134				return $numref;
 135			}
 136			else
 137			{
 138				dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error);
 139				return "";
 140			}
 141		}
 142		else
 143		{
 144			print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_NUMBER_NotDefined");
 145			return "";
 146		}
 147	}
 148
 149	/**
 150	 *  Create expedition en base
 151	 *
 152	 *  @param	User	$user       Objet du user qui cree
 153	 *  @return int 				<0 si erreur, id expedition creee si ok
 154	 */
 155	function create($user)
 156	{
 157		global $conf, $langs;
 158
 159		$now=dol_now();
 160
 161		require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
 162		$error = 0;
 163
 164		// Clean parameters
 165		$this->brouillon = 1;
 166		$this->tracking_number = dol_sanitizeFileName($this->tracking_number);
 167
 168		$this->user = $user;
 169
 170
 171		$this->db->begin();
 172
 173		$sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition (";
 174		$sql.= "ref";
 175		$sql.= ", entity";
 176		$sql.= ", ref_customer";
 177		$sql.= ", ref_int";
 178		$sql.= ", date_creation";
 179		$sql.= ", fk_user_author";
 180		$sql.= ", date_expedition";
 181		$sql.= ", date_delivery";
 182		$sql.= ", fk_soc";
 183		$sql.= ", fk_address";
 184		$sql.= ", fk_expedition_methode";
 185		$sql.= ", tracking_number";
 186		$sql.= ", weight";
 187		$sql.= ", size";
 188		$sql.= ", width";
 189		$sql.= ", height";
 190		$sql.= ", weight_units";
 191		$sql.= ", size_units";
 192		$sql.= ") VALUES (";
 193		$sql.= "'(PROV)'";
 194		$sql.= ", ".$conf->entity;
 195		$sql.= ", ".($this->ref_customer?"'".$this->ref_customer."'":"null");
 196		$sql.= ", ".($this->ref_int?"'".$this->ref_int."'":"null");
 197		$sql.= ", '".$this->db->idate($now)."'";
 198		$sql.= ", ".$user->id;
 199		$sql.= ", ".($this->date_expedition>0?"'".$this->db->idate($this->date_expedition)."'":"null");
 200		$sql.= ", ".($this->date_delivery>0?"'".$this->db->idate($this->date_delivery)."'":"null");
 201		$sql.= ", ".$this->socid;
 202		$sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:"null");
 203		$sql.= ", ".($this->expedition_method_id>0?$this->expedition_method_id:"null");
 204		$sql.= ", '".$this->db->escape($this->tracking_number)."'";
 205		$sql.= ", ".$this->weight;
 206		$sql.= ", ".$this->sizeS;	// TODO Should use this->trueDepth
 207		$sql.= ", ".$this->sizeW;	// TODO Should use this->trueWidth
 208		$sql.= ", ".$this->sizeH;	// TODO Should use this->trueHeight
 209		$sql.= ", ".$this->weight_units;
 210		$sql.= ", ".$this->size_units;
 211		$sql.= ")";
 212
 213		$resql=$this->db->query($sql);
 214		if ($resql)
 215		{
 216			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."expedition");
 217
 218			$sql = "UPDATE ".MAIN_DB_PREFIX."expedition";
 219			$sql.= " SET ref = '(PROV".$this->id.")'";
 220			$sql.= " WHERE rowid = ".$this->id;
 221
 222			dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
 223			if ($this->db->query($sql))
 224			{
 225				// Insertion des lignes
 226				$num=count($this->lines);
 227				for ($i = 0; $i < $num; $i++)
 228				{
 229					if (! $this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty) > 0)
 230					{
 231						$error++;
 232					}
 233				}
 234
 235				if (! $error && $this->id && $this->origin_id)
 236				{
 237					$ret = $this->add_object_linked();
 238					if (!$ret)
 239					{
 240						$error++;
 241					}
 242
 243					// TODO uniformiser les statuts
 244					$ret = $this->setStatut(2,$this->origin_id,$this->origin);
 245					if (! $ret)
 246					{
 247						$error++;
 248					}
 249				}
 250
 251				if (! $error)
 252				{
 253					// Appel des triggers
 254					include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
 255					$interface=new Interfaces($this->db);
 256					$result=$interface->run_triggers('SHIPPING_CREATE',$this,$user,$langs,$conf);
 257					if ($result < 0) { $error++; $this->errors=$interface->errors; }
 258					// Fin appel triggers
 259
 260					$this->db->commit();
 261					return $this->id;
 262				}
 263				else
 264				{
 265					$error++;
 266					$this->error=$this->db->lasterror()." - sql=$sql";
 267					$this->db->rollback();
 268					return -3;
 269				}
 270			}
 271			else
 272			{
 273				$error++;
 274				$this->error=$this->db->lasterror()." - sql=$sql";
 275				$this->db->rollback();
 276				return -2;
 277			}
 278		}
 279		else
 280		{
 281			$error++;
 282			$this->error=$this->db->error()." - sql=$sql";
 283			$this->db->rollback();
 284			return -1;
 285		}
 286	}
 287
 288	/**
 289	 * Create a expedition line
 290	 *
 291	 * @param 	int		$entrepot_id		Id of warehouse
 292	 * @param 	int		$origin_line_id		Id of source line
 293	 * @param 	int		$qty				Quantity
 294	 * @return	int							<0 if KO, >0 if OK
 295	 */
 296	function create_line($entrepot_id, $origin_line_id, $qty)
 297	{
 298		$error = 0;
 299
 300		$sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet (";
 301		$sql.= "fk_expedition";
 302		$sql.= ", fk_entrepot";
 303		$sql.= ", fk_origin_line";
 304		$sql.= ", qty";
 305		$sql.= ") VALUES (";
 306		$sql.= $this->id;
 307		$sql.= ", ".($entrepot_id?$entrepot_id:'null');
 308		$sql.= ", ".$origin_line_id;
 309		$sql.= ", ".$qty;
 310		$sql.= ")";
 311
 312		if (! $this->db->query($sql))
 313		{
 314			$error++;
 315		}
 316
 317		if (! $error) return 1;
 318		else return -1;
 319	}
 320
 321	/**
 322	 *	Get object and lines from database
 323	 *
 324	 *	@param	int		$id       	Id of object to load
 325	 * 	@param	string	$ref		Ref of object
 326	 * 	@param	string	$ref_ext	External reference of object
 327     * 	@param	string	$ref_int	Internal reference of other object
 328	 *	@return int			        >0 if OK, <0 if KO
 329	 */
 330	function fetch($id, $ref='', $ref_ext='', $ref_int='')
 331	{
 332		global $conf;
 333
 334		// Check parameters
 335		if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1;
 336
 337		$sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_customer, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut";
 338		$sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
 339		$sql.= ", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
 340		$sql.= ", e.fk_expedition_methode, e.tracking_number";
 341		$sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
 342		$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
 343		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->element."'";
 344		$sql.= " WHERE e.entity = ".$conf->entity;
 345		if ($id)   	  $sql.= " AND e.rowid=".$id;
 346        if ($ref)     $sql.= " AND e.ref='".$this->db->escape($ref)."'";
 347        if ($ref_ext) $sql.= " AND e.ref_ext='".$this->db->escape($ref_ext)."'";
 348        if ($ref_int) $sql.= " AND e.ref_int='".$this->db->escape($ref_int)."'";
 349
 350		dol_syslog(get_class($this)."::fetch sql=".$sql);
 351		$result = $this->db->query($sql);
 352		if ($result)
 353		{
 354			if ($this->db->num_rows($result))
 355			{
 356				$obj = $this->db->fetch_object($result);
 357
 358				$this->id                   = $obj->rowid;
 359				$this->ref                  = $obj->ref;
 360				$this->socid                = $obj->socid;
 361				$this->ref_customer			= $obj->ref_customer;
 362				$this->ref_ext				= $obj->ref_ext;
 363				$this->ref_int				= $obj->ref_int;
 364				$this->statut               = $obj->fk_statut;
 365				$this->user_author_id       = $obj->fk_user_author;
 366				$this->date_creation        = $this->db->jdate($obj->date_creation);
 367				$this->date                 = $this->db->jdate($obj->date_expedition);	// TODO obsolete
 368				$this->date_expedition      = $this->db->jdate($obj->date_expedition);	// TODO obsolete
 369				$this->date_shipping        = $this->db->jdate($obj->date_expedition);	// Date real
 370				$this->date_delivery        = $this->db->jdate($obj->date_delivery);	// Date planed
 371				$this->fk_delivery_address  = $obj->fk_address;
 372				$this->modelpdf             = $obj->model_pdf;
 373				$this->expedition_method_id = $obj->fk_expedition_methode; // TODO deprecated
 374				$this->shipping_method_id	= $obj->fk_expedition_methode;
 375				$this->tracking_number      = $obj->tracking_number;
 376				$this->origin               = ($obj->origin?$obj->origin:'commande'); // For compatibility
 377				$this->origin_id            = $obj->origin_id;
 378				$this->billed				= ($obj->fk_statut==2?1:0);
 379
 380				$this->trueWeight           = $obj->weight;
 381				$this->weight_units         = $obj->weight_units;
 382
 383				$this->trueWidth            = $obj->width;
 384				$this->width_units          = $obj->size_units;
 385				$this->trueHeight           = $obj->height;
 386				$this->height_units         = $obj->size_units;
 387				$this->trueDepth            = $obj->size;
 388				$this->depth_units          = $obj->size_units;
 389
 390				// A denormalized value
 391				$this->trueSize           	= $obj->size."x".$obj->width."x".$obj->height;
 392				$this->size_units           = $obj->size_units;
 393
 394				$this->db->free($result);
 395
 396				if ($this->statut == 0) $this->brouillon = 1;
 397
 398				$file = $conf->expedition->dir_output . "/" .get_exdir($expedition->id,2) . "/" . $this->id.".pdf";
 399				$this->pdf_filename = $file;
 400
 401				// Tracking url
 402				$this->GetUrlTrackingStatus($obj->tracking_number);
 403
 404				/*
 405				 * Lines
 406				 */
 407				$result=$this->fetch_lines();
 408				if ($result < 0)
 409				{
 410					return -3;
 411				}
 412
 413				return 1;
 414			}
 415			else
 416			{
 417				dol_syslog(get_class($this).'::Fetch Error -2');
 418				$this->error='Delivery with id '.$id.' not found sql='.$sql;
 419				return -2;
 420			}
 421		}
 422		else
 423		{
 424			dol_syslog(get_class($this).'::Fetch Error -1');
 425			$this->error=$this->db->error();
 426			return -1;
 427		}
 428	}
 429
 430	/**
 431	 *  Validate object and update stock if option enabled
 432	 *
 433	 *  @param      User		$user       Object user that validate
 434	 *  @return     int						<0 if OK, >0 if KO
 435	 */
 436	function valid($user)
 437	{
 438		global $conf, $langs;
 439
 440        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 441
 442		dol_syslog(get_class($this)."::valid");
 443
 444		// Protection
 445		if ($this->statut)
 446		{
 447			dol_syslog(get_class($this)."::valid no draft status", LOG_WARNING);
 448			return 0;
 449		}
 450
 451		if (! $user->rights->expedition->valider)
 452		{
 453			$this->error='Permission denied';
 454			dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
 455			return -1;
 456		}
 457
 458		$this->db->begin();
 459
 460		$error = 0;
 461
 462		// Define new ref
 463		$soc = new Societe($this->db);
 464		$soc->fetch($this->socid);
 465
 466		// Class of company linked to order
 467		$result=$soc->set_as_client();
 468
 469		// Define new ref
 470		if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref)))
 471		{
 472			$numref = $this->getNextNumRef($soc);
 473		}
 474		else
 475		{
 476			$numref = "EXP".$this->id;
 477		}
 478
 479		$now=dol_now();
 480
 481		// Validate
 482		$sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
 483		$sql.= " ref='".$numref."'";
 484		$sql.= ", fk_statut = 1";
 485		$sql.= ", date_valid = '".$this->db->idate($now)."'";
 486		$sql.= ", fk_user_valid = ".$user->id;
 487		$sql.= " WHERE rowid = ".$this->id;
 488
 489		dol_syslog(get_class($this)."::valid update expedition sql=".$sql);
 490		$resql=$this->db->query($sql);
 491		if (! $resql)
 492		{
 493			dol_syslog(get_class($this)."::valid Echec update - 10 - sql=".$sql, LOG_ERR);
 494			$this->error=$this->db->lasterror();
 495			$error++;
 496		}
 497
 498		// If stock increment is done on sending (recommanded choice)
 499		if (! $error && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
 500		{
 501			require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
 502
 503			$langs->load("agenda");
 504
 505			// Loop on each product line to add a stock movement
 506			// TODO possibilite d'expedier a partir d'une propale ou autre origine
 507			$sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot";
 508			$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
 509			$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
 510			$sql.= " WHERE ed.fk_expedition = ".$this->id;
 511			$sql.= " AND cd.rowid = ed.fk_origin_line";
 512
 513			dol_syslog(get_class($this)."::valid select details sql=".$sql);
 514			$resql=$this->db->query($sql);
 515			if ($resql)
 516			{
 517			    $cpt = $this->db->num_rows($resql);
 518                for ($i = 0; $i < $cpt; $i++)
 519				{
 520					dol_syslog(get_class($this)."::valid movement index ".$i);
 521					$obj = $this->db->fetch_object($resql);
 522
 523					//var_dump($this->lines[$i]);
 524					$mouvS = new MouvementStock($this->db);
 525					// We decrement stock of product (and sub-products)
 526					// We use warehouse selected for each line
 527					$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice, $langs->trans("ShipmentValidatedInSpeedealing",$numref));
 528					if ($result < 0) { $error++; break; }
 529				}
 530			}
 531			else
 532			{
 533				$this->db->rollback();
 534				$this->error=$this->db->error();
 535				dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
 536				return -2;
 537			}
 538		}
 539
 540		if (! $error)
 541		{
 542			$this->oldref='';
 543
 544			// Rename directory if dir was a temporary ref
 545			if (preg_match('/^[\(]?PROV/i', $this->ref))
 546			{
 547				// On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref)
 548				// afin de ne pas perdre les fichiers attaches
 549				$oldref = dol_sanitizeFileName($this->ref);
 550				$newref = dol_sanitizeFileName($numref);
 551				$dirsource = $conf->expedition->dir_output.'/sending/'.$oldref;
 552				$dirdest = $conf->expedition->dir_output.'/sending/'.$newref;
 553				if (file_exists($dirsource))
 554				{
 555					dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest);
 556
 557					if (@rename($dirsource, $dirdest))
 558					{
 559						$this->oldref = $oldref;
 560
 561						dol_syslog("Rename ok");
 562						// Suppression ancien fichier PDF dans nouveau rep
 563						dol_delete_file($dirdest.'/'.$oldref.'*.*');
 564					}
 565				}
 566			}
 567		}
 568
 569		// Set new ref and current status
 570		if (! $error)
 571		{
 572			$this->ref = $numref;
 573			$this->statut = 1;
 574		}
 575
 576		if (! $error)
 577		{
 578			// Appel des triggers
 579			include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
 580			$interface=new Interfaces($this->db);
 581			$result=$interface->run_triggers('SHIPPING_VALIDATE',$this,$user,$langs,$conf);
 582			if ($result < 0) { $error++; $this->errors=$interface->errors; }
 583			// Fin appel triggers
 584		}
 585
 586		if (! $error)
 587		{
 588			$this->db->commit();
 589			return 1;
 590		}
 591		else
 592		{
 593			foreach($this->errors as $errmsg)
 594			{
 595	            dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR);
 596	            $this->error.=($this->error?', '.$errmsg:$errmsg);
 597			}
 598			$this->db->rollback();
 599			return -1*$error;
 600		}
 601	}
 602
 603
 604	/**
 605	 *	Cree un bon de livraison a partir de l'expedition
 606	 *
 607	 *	@param	User	$user       Utilisateur
 608	 *  @return int  				<0 if KO, >=0 if OK
 609	 */
 610	function create_delivery($user)
 611	{
 612		global $conf;
 613
 614		if ($conf->livraison_bon->enabled)
 615		{
 616			if ($this->statut == 1)
 617			{
 618				// Expedition validee
 619				include_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php';
 620				$delivery = new Livraison($this->db);
 621				$result=$delivery->create_from_sending($user, $this->id);
 622				if ($result > 0)
 623				{
 624					return $result;
 625				}
 626				else
 627				{
 628					$this->error=$delivery->error;
 629					return $result;
 630				}
 631			}
 632			else return 0;
 633		}
 634		else return 0;
 635	}
 636
 637	/**
 638	 * Add a expedition line
 639	 *
 640	 * @param 	int		$entrepot_id		Id of warehouse
 641	 * @param 	int		$id					Id of source line
 642	 * @param 	int		$qty				Quantity
 643	 * @return	int							<0 if KO, >0 if OK
 644	 */
 645	function addline($entrepot_id, $id, $qty)
 646	{
 647		$num = count($this->lines);
 648		$line = new ExpeditionLigne($this->db);
 649
 650		$line->entrepot_id = $entrepot_id;
 651		$line->origin_line_id = $id;
 652		$line->qty = $qty;
 653
 654		$this->lines[$num] = $line;
 655	}
 656
 657    /**
 658     *  Update database
 659     *
 660     *  @param	User	$user        	User that modify
 661     *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
 662     *  @return int 			       	<0 if KO, >0 if OK
 663     */
 664    function update($user=0, $notrigger=0)
 665    {
 666    	global $conf, $langs;
 667		$error=0;
 668
 669		// Clean parameters
 670
 671		if (isset($this->ref)) $this->ref=trim($this->ref);
 672		if (isset($this->entity)) $this->entity=trim($this->entity);
 673		if (isset($this->ref_customer)) $this->ref_customer=trim($this->ref_customer);
 674		if (isset($this->socid)) $this->socid=trim($this->socid);
 675		if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
 676		if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid);
 677		if (isset($this->fk_adresse_livraison)) $this->fk_adresse_livraison=trim($this->fk_adresse_livraison);
 678		if (isset($this->expedition_method_id)) $this->expedition_method_id=trim($this->expedition_method_id);
 679		if (isset($this->tracking_number)) $this->tracking_number=trim($this->tracking_number);
 680		if (isset($this->statut)) $this->statut=trim($this->statut);
 681		if (isset($this->trueDepth)) $this->trueDepth=trim($this->trueDepth);
 682		if (isset($this->trueWidth)) $this->trueWidth=trim($this->trueWidth);
 683		if (isset($this->trueHeight)) $this->trueHeight=trim($this->trueHeight);
 684		if (isset($this->size_units)) $this->size_units=trim($this->size_units);
 685		if (isset($this->weight_units)) $this->weight_units=trim($this->weight_units);
 686		if (isset($this->trueWeight)) $this->weight=trim($this->trueWeight);
 687		if (isset($this->note)) $this->note=trim($this->note);
 688		if (isset($this->model_pdf)) $this->model_pdf=trim($this->model_pdf);
 689
 690
 691
 692		// Check parameters
 693		// Put here code to add control on parameters values
 694
 695        // Update request
 696        $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
 697
 698		$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
 699		$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
 700		$sql.= " ref_customer=".(isset($this->ref_customer)?"'".$this->db->escape($this->ref_customer)."'":"null").",";
 701		$sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").",";
 702		$sql.= " date_creation=".(dol_strlen($this->date_creation)!=0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').",";
 703		$sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").",";
 704		$sql.= " date_valid=".(dol_strlen($this->date_valid)!=0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').",";
 705		$sql.= " fk_user_valid=".(isset($this->fk_user_valid)?$this->fk_user_valid:"null").",";
 706		$sql.= " date_expedition=".(dol_strlen($this->date_expedition)!=0 ? "'".$this->db->idate($this->date_expedition)."'" : 'null').",";
 707		$sql.= " date_delivery=".(dol_strlen($this->date_delivery)!=0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
 708		$sql.= " fk_address=".(isset($this->fk_adresse_livraison)?$this->fk_adresse_livraison:"null").",";
 709		$sql.= " fk_expedition_methode=".((isset($this->expedition_method_id) && $this->expedition_method_id > 0)?$this->expedition_method_id:"null").",";
 710		$sql.= " tracking_number=".(isset($this->tracking_number)?"'".$this->db->escape($this->tracking_number)."'":"null").",";
 711		$sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").",";
 712		$sql.= " height=".(isset($this->trueHeight)?$this->trueHeight:"null").",";
 713		$sql.= " width=".(isset($this->trueWidth)?$this->trueWidth:"null").",";
 714		$sql.= " size_units=".(isset($this->size_units)?$this->size_units:"null").",";
 715		$sql.= " size=".(isset($this->trueDepth)?$this->trueDepth:"null").",";
 716		$sql.= " weight_units=".(isset($this->weight_units)?$this->weight_units:"null").",";
 717		$sql.= " weight=".(isset($this->trueWeight)?$this->trueWeight:"null").",";
 718		$sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").",";
 719		$sql.= " model_pdf=".(isset($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null").",";
 720		$sql.= " entity=".$conf->entity;
 721
 722        $sql.= " WHERE rowid=".$this->id;
 723
 724		$this->db->begin();
 725
 726		dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
 727        $resql = $this->db->query($sql);
 728    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
 729
 730		if (! $error)
 731		{
 732			if (! $notrigger)
 733			{
 734	            // Call triggers
 735	            include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
 736	            $interface=new Interfaces($this->db);
 737	            $result=$interface->run_triggers('SHIPPING_MODIFY',$this,$user,$langs,$conf);
 738	            if ($result < 0) { $error++; $this->errors=$interface->errors; }
 739	            // End call triggers
 740	    	}
 741		}
 742
 743        // Commit or rollback
 744		if ($error)
 745		{
 746			foreach($this->errors as $errmsg)
 747			{
 748	            dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
 749	            $this->error.=($this->error?', '.$errmsg:$errmsg);
 750			}
 751			$this->db->rollback();
 752			return -1*$error;
 753		}
 754		else
 755		{
 756			$this->db->commit();
 757			return 1;
 758		}
 759    }
 760
 761    /**
 762	 * 	Delete shipment
 763	 *
 764	 * 	@return	int		>0 if OK otherwise if KO
 765	 */
 766	function delete()
 767	{
 768		global $conf, $langs, $user;
 769        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 770
 771		$error=0;
 772
 773		$this->db->begin();
 774
 775		$sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet";
 776		$sql.= " WHERE fk_expedition = ".$this->id;
 777
 778		if ( $this->db->query($sql) )
 779		{
 780			// Delete linked object
 781			$res = $this->deleteObjectLinked();
 782			if ($res < 0) $error++;
 783
 784			if (! $error)
 785			{
 786				$sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition";
 787				$sql.= " WHERE rowid = ".$this->id;
 788
 789				if ($this->db->query($sql))
 790				{
 791					$this->db->commit();
 792
 793					// On efface le repertoire de pdf provisoire
 794					$ref = dol_sanitizeFileName($this->ref);
 795					if (! empty($conf->expedition->dir_output))
 796					{
 797						$dir = $conf->expedition->dir_output . '/sending/' . $ref ;
 798						$file = $dir . '/' . $ref . '.pdf';
 799						if (file_exists($file))
 800						{
 801							if (! dol_delete_file($file))
 802							{
 803								return 0;
 804							}
 805						}
 806						if (file_exists($dir))
 807						{
 808							if (!dol_delete_dir($dir))
 809							{
 810								$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
 811								return 0;
 812							}
 813						}
 814					}
 815
 816					// Call triggers
 817		            include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
 818		            $interface=new Interfaces($this->db);
 819		            $result=$interface->run_triggers('SHIPPING_DELETE',$this,$user,$langs,$conf);
 820		            if ($result < 0) { $error++; $this->errors=$interface->errors; }
 821		            // End call triggers
 822
 823					// TODO il faut incrementer le stock si on supprime une expedition validee
 824					return 1;
 825				}
 826				else
 827				{
 828					$this->error=$this->db->lasterror()." - sql=$sql";
 829					$this->db->rollback();
 830					return -3;
 831				}
 832			}
 833			else
 834			{
 835				$this->error=$this->db->lasterror()." - sql=$sql";
 836				$this->db->rollback();
 837				return -2;
 838			}
 839		}
 840		else
 841		{
 842			$this->error=$this->db->lasterror()." - sql=$sql";
 843			$this->db->rollback();
 844			return -1;
 845		}
 846	}
 847
 848	/**
 849	 *	Load lines
 850	 *
 851	 *	@return	int		>0 if OK, Otherwise if KO
 852	 */
 853	function fetch_lines()
 854	{
 855		// TODO: recuperer les champs du document associe a part
 856
 857		$sql = "SELECT cd.rowid, cd.fk_product, cd.label as custom_label, cd.description, cd.qty as qty_asked";
 858		$sql.= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
 859		$sql.= ", cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.price, cd.subprice";
 860		$sql.= ", ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
 861		$sql.= ", p.ref as product_ref, p.label as product_label, p.fk_product_type, p.weight, p.weight_units, p.volume, p.volume_units";
 862		$sql.= " FROM (".MAIN_DB_PREFIX."expeditiondet as ed,";
 863		$sql.= " ".MAIN_DB_PREFIX."commandedet as cd)";
 864		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product";
 865		$sql.= " WHERE ed.fk_expedition = ".$this->id;
 866		$sql.= " AND ed.fk_origin_line = cd.rowid";
 867
 868		dol_syslog(get_class($this)."::fetch_lines sql=".$sql);
 869		$resql = $this->db->query($sql);
 870		if ($resql)
 871		{
 872			include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
 873
 874			$num = $this->db->num_rows($resql);
 875			$i = 0;
 876
 877			$this->total_ht = 0;
 878			$this->total_tva = 0;
 879			$this->total_ttc = 0;
 880			$this->total_localtax1 = 0;
 881			$this->total_localtax2 = 0;
 882
 883			while ($i < $num)
 884			{
 885				$line = new ExpeditionLigne($this->db);
 886				$obj = $this->db->fetch_object($resql);
 887
 888				$line->fk_origin_line 	= $obj->fk_origin_line;
 889				$line->origin_line_id 	= $obj->fk_origin_line;	    // TODO deprecated
 890				$line->entrepot_id    	= $obj->fk_entrepot;
 891				$line->fk_product     	= $obj->fk_product;
 892				$line->fk_product_type	= $obj->fk_product_type;
 893				$line->ref				= $obj->product_ref;		// TODO deprecated
 894                $line->product_ref		= $obj->product_ref;
 895                $line->product_label	= $obj->product_label;
 896				$line->libelle        	= $obj->product_label;		// TODO deprecated
 897				$line->label			= $obj->custom_label;
 898				$line->description    	= $obj->description;
 899				$line->qty_asked      	= $obj->qty_asked;
 900				$line->qty_shipped    	= $obj->qty_shipped;
 901				$line->weight         	= $obj->weight;
 902				$line->weight_units   	= $obj->weight_units;
 903				$line->volume         	= $obj->volume;
 904				$line->volume_units   	= $obj->volume_units;
 905
 906				//Invoicing
 907				$line->desc				= $obj->product_label;
 908				$line->qty 				= $obj->qty_shipped;
 909				$line->total_ht			= $obj->total_ht;
 910				$line->total_localtax1 	= $obj->total_localtax1;
 911				$line->total_localtax2 	= $obj->total_localtax2;
 912				$line->total_ttc	 	= $obj->total_ttc;
 913				$line->total_tva	 	= $obj->total_tva;
 914				$line->tva_tx 		 	= $obj->tva_tx;
 915				$line->localtax1_tx 	= $obj->localtax1_tx;
 916				$line->localtax2_tx 	= $obj->localtax2_tx;
 917				$line->price			= $obj->price;
 918				$line->subprice			= $obj->subprice;
 919				$line->remise_percent	= $obj->remise_percent;
 920
 921				$tabprice = calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $info_bits);
 922				$this->total_ht+= $tabprice[0];
 923				$this->total_tva+= $tabprice[1];
 924				$this->total_ttc+= $tabprice[2];
 925				$this->total_localtax1+= $tabprice[9];
 926				$this->total_localtax2+= $tabprice[10];
 927
 928				$this->lines[$i] = $line;
 929
 930				$i++;
 931			}
 932			$this->db->free($resql);
 933			return 1;
 934		}
 935		else
 936		{
 937			$this->error=$this->db->error();
 938			dol_syslog(get_class($this).'::fetch_lines: Error '.$this->error, LOG_ERR);
 939			return -3;
 940		}
 941	}
 942
 943	/**
 944     *	Return clicable link of object (with eventually picto)
 945     *
 946     *	@param      int			$withpicto      Add picto into link
 947     *	@param      int			$option         Where point the link
 948     *	@param      int			$max          	Max length to show
 949     *	@param      int			$short			Use short labels
 950     *	@return     string          			String with URL
 951     */
 952	function getNomUrl($withpicto=0,$option=0,$max=0,$short=0)
 953	{
 954		global $langs;
 955
 956		$result='';
 957
 958		$url = DOL_URL_ROOT.'/expedition/fiche.php?id='.$this->id;
 959
 960		if ($short) return $url;
 961
 962		$linkstart = '<a href="'.$url.'">';
 963		$linkend='</a>';
 964
 965		$picto='sending';
 966		$label=$langs->trans("ShowSending").': '.$this->ref;
 967
 968		if ($withpicto) $result.=($linkstart.img_object($label,$picto).$linkend);
 969		if ($withpicto && $withpicto != 2) $result.=' ';
 970		$result.=$linkstart.$this->ref.$linkend;
 971		return $result;
 972	}
 973
 974	/**
 975     *	Return status label
 976     *
 977     *	@param      int		$mode      	0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
 978     *	@return     string      		Libelle
 979     */
 980	function getLibStatut($mode=0)
 981	{
 982		return $this->LibStatut($this->statut,$mode);
 983	}
 984
 985	/**
 986	 * Return label of a status
 987	 *
 988	 * @param      int		$statut		Id statut
 989	 * @param      int		$mode       0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto
 990	 * @return     string				Label of status
 991	 */
 992	function LibStatut($statut,$mode)
 993	{
 994		global $langs;
 995
 996		if ($mode==0)
 997		{
 998			if ($statut==0) return $langs->trans($this->statuts[$statut]);
 999			if ($statut==1)  return $langs->trans($this->statuts[$statut]);
1000			if ($statut==2)  return $langs->trans($this->statuts[$statut]);
1001		}
1002		if ($mode==1)
1003		{
1004			if ($statut==0) return $langs->trans('StatusSendingDraftShort');
1005			if ($statut==1) return $langs->trans('StatusSendingValidatedShort');
1006			if ($statut==2) return $langs->trans('StatusSendingProcessedShort');
1007		}
1008		if ($mode == 3)
1009		{
1010			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
1011			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4');
1012			if ($statut==2) return img_picto($langs->trans('StatusSendingProcessed'),'statut6');
1013		}
1014		if ($mode == 4)
1015		{
1016			if ($statut==0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
1017			if ($statut==1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
1018			if ($statut==2) return img_picto($langs->trans('StatusSendingProcessed'),'statut6').' '.$langs->trans('StatusSendingProcessed');
1019		}
1020		if ($mode == 5)
1021		{
1022			if ($statut==0) return $langs->trans('StatusSendingDraftShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
1023			if ($statut==1) return $langs->trans('StatusSendingValidatedShort').' '.img_picto($langs->trans($this->statuts[$statut]),'statut4');
1024			if ($statut==2) return $langs->trans('StatusSendingProcessedShort').' '.img_picto($langs->trans('StatusSendingProcessedShort'),'statut6');
1025		}
1026	}
1027
1028	/**
1029     *  Initialise an instance with random values.
1030     *  Used to build previews or test instances.
1031     *	id must be 0 if object instance is a specimen.
1032     *
1033     *  @return	void
1034	 */
1035	function initAsSpecimen()
1036	{
1037		global $user,$langs,$conf;
1038
1039		$now=dol_now();
1040
1041		dol_syslog(get_class($this)."::initAsSpecimen");
1042
1043		// Charge tableau des produits prodids
1044		$prodids = array();
1045		$sql = "SELECT rowid";
1046		$sql.= " FROM ".MAIN_DB_PREFIX."product";
1047		$sql.= " WHERE entity IN (".getEntity('product', 1).")";
1048		$resql = $this->db->query($sql);
1049		if ($resql)
1050		{
1051			$num_prods = $this->db->num_rows($resql);
1052			$i = 0;
1053			while ($i < $num_prods)
1054			{
1055				$i++;
1056				$row = $this->db->fetch_row($resql);
1057				$prodids[$i] = $row[0];
1058			}
1059		}
1060
1061		$order=new Commande($this->db);
1062		$order->initAsSpecimen();
1063
1064		// Initialise parametres
1065		$this->id=0;
1066		$this->ref = 'SPECIMEN';
1067		$this->specimen=1;
1068		$this->statut               = 1;
1069		$this->livraison_id         = 0;
1070		$this->date                 = $now;
1071		$this->date_creation        = $now;
1072		$this->date_valid           = $now;
1073		$this->date_delivery        = $now;
1074		$this->date_expedition      = $now + 24*3600;
1075
1076		$this->entrepot_id          = 0;
1077		$this->fk_delivery_address  = 0;
1078		$this->socid                = 1;
1079
1080		$this->commande_id          = 0;
1081		$this->commande             = $order;
1082
1083        $this->origin_id            = 1;
1084        $this->origin               = 'commande';
1085
1086		$nbp = 5;
1087		$xnbp = 0;
1088		while ($xnbp < $nbp)
1089		{
1090			$line=new ExpeditionLigne($this->db);
1091			$line->desc=$langs->trans("Description")." ".$xnbp;
1092			$line->libelle=$langs->trans("Description")." ".$xnbp;
1093			$line->qty=10;
1094			$line->qty_asked=5;
1095			$line->qty_shipped=4;
1096			$line->fk_product=$this->commande->lines[$xnbp]->fk_product;
1097
1098			$this->lines[]=$line;
1099			$xnbp++;
1100		}
1101
1102	}
1103
1104	/**
1105	 *	Set the planned delivery date
1106	 *
1107	 *	@param      User			$user        		Objet utilisateur qui modifie
1108	 *	@param      timestamp		$date_livraison     Date de livraison
1109	 *	@return     int         						<0 if KO, >0 if OK
1110	 */
1111	function set_date_livraison($user, $date_livraison)
1112	{
1113		if ($user->rights->expedition->creer)
1114		{
1115			$sql = "UPDATE ".MAIN_DB_PREFIX."expedition";
1116			$sql.= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
1117			$sql.= " WHERE rowid = ".$this->id;
1118
1119			dol_syslog(get_class($this)."::set_date_livraison sql=".$sql,LOG_DEBUG);
1120			$resql=$this->db->query($sql);
1121			if ($resql)
1122			{
1123				$this->date_delivery = $date_livraison;
1124				return 1;
1125			}
1126			else
1127			{
1128				$this->error=$this->db->error();
1129				dol_syslog("Commande::set_date_livraison ".$this->error,LOG_ERR);
1130				return -1;
1131			}
1132		}
1133		else
1134		{
1135			return -2;
1136		}
1137	}
1138
1139	/**
1140	 *	Fetch deliveries method and return an array. Load array this->meths(rowid=>label).
1141	 *
1142	 * 	@return	void
1143	 */
1144	function fetch_delivery_methods()
1145	{
1146		global $langs;
1147		$meths = array();
1148
1149		$sql = "SELECT em.rowid, em.code, em.libelle";
1150		$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1151		$sql.= " WHERE em.active = 1";
1152		$sql.= " ORDER BY em.libelle ASC";
1153
1154		$resql = $this->db->query($sql);
1155		if ($resql)
1156		{
1157			while ($obj = $this->db->fetch_object($resql))
1158			{
1159				$label=$langs->trans('SendingMethod'.$obj->code);
1160				$this->meths[$obj->rowid] = ($label != 'SendingMethod'.$obj->code?$label:$obj->libelle);
1161			}
1162		}
1163	}
1164
1165	/**
1166	 * Get tracking url status
1167	 *
1168	 * @param	string	$value		Value
1169	 * @return	void
1170	 */
1171	function GetUrlTrackingStatus($value='')
1172	{
1173		$code='';
1174
1175		if (! empty($this->expedition_method_id))
1176		{
1177			$sql = "SELECT em.code";
1178			$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
1179			$sql.= " WHERE em.rowid = ".$this->expedition_method_id;
1180
1181			$resql = $this->db->query($sql);
1182			if ($resql)
1183			{
1184				if ($obj = $this->db->fetch_object($resql))
1185				{
1186					$code = $obj->code;
1187				}
1188			}
1189		}
1190
1191		if ($code)
1192		{
1193			$classname = "methode_expedition_".strtolower($code);
1194
1195			$url='';
1196			if (file_exists(DOL_DOCUMENT_ROOT."/core/modules/expedition/methode_expedition_".strtolower($code).".modules.php") && ! empty($this->tracking_number))
1197			{
1198				require_once DOL_DOCUMENT_ROOT."/core/modules/expedition/methode_expedition_".strtolower($code).'.modules.php';
1199				$shipmethod = new $classname();
1200				$url = $shipmethod->provider_url_status($this->tracking_number);
1201			}
1202
1203			if ($url)
1204			{
1205				$this->tracking_url = sprintf('<a target="_blank" href="%s">'.($value?$value:'url').'</a>',$url,$url);
1206			}
1207			else
1208			{
1209				$this->tracking_url = $value;
1210			}
1211		}
1212		else
1213		{
1214			$this->tracking_url = $value;
1215		}
1216	}
1217
1218	/**
1219	 *	Classify the shipping as invoiced
1220	 *
1221	 *	@return     int     <0 if ko, >0 if ok
1222	 */
1223	function set_billed()
1224	{
1225		global $conf;
1226
1227		$sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2';
1228		$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 ;';
1229		if ($this->db->query($sql) )
1230		{
1231			//TODO: Option to set order billed if 100% of order is shipped
1232			return 1;
1233		}
1234		else
1235		{
1236			dol_print_error($this->db);
1237			return -1;
1238		}
1239	}
1240
1241}
1242
1243
1244/**
1245 * Classe de gestion des lignes de bons d'expedition
1246 */
1247class ExpeditionLigne
1248{
1249	var $db;
1250
1251	// From llx_expeditiondet
1252	var $qty;
1253	var $qty_shipped;
1254	var $fk_product;
1255
1256	// From llx_commandedet or llx_propaldet
1257	var $qty_asked;
1258	var $libelle;       // Label produit
1259	var $product_desc;  // Description produit
1260	var $ref;
1261
1262	// Invoicing
1263	var $remise_percent;
1264	var $total_ht;			// Total net of tax
1265	var $total_ttc;			// Total with tax
1266	var $total_tva;			// Total VAT
1267	var $total_localtax1;   // Total Local tax 1
1268	var $total_localtax2;   // Total Local tax 2
1269
1270
1271    /**
1272     *	Constructor
1273     *
1274     *  @param		DoliDB		$db      Database handler
1275     */
1276	function __construct($db = '')
1277	{
1278		$this->db=$db;
1279	}
1280
1281}
1282
1283?>