Completed
Branch develop (420c52)
by
unknown
27:28
created

Inventory::initAsSpecimen()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) 2007-2017  Laurent Destailleur <[email protected]>
3
 * Copyright (C) 2014-2016  Juanjo Menent       <[email protected]>
4
 * Copyright (C) 2015       Florian Henry       <[email protected]>
5
 * Copyright (C) 2015       Raphaël Doursenaud  <[email protected]>
6
 * Copyright (C) ---Put here your own copyright and developer email---
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        product/inventory/class/inventory.class.php
24
 * \ingroup     inventory
25
 * \brief       This file is a CRUD class file for Inventory (Create/Read/Update/Delete)
26
 */
27
28
// Put here all includes required by your class file
29
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
30
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
31
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
32
33
/**
34
 * Class for Inventory
35
 */
36
class Inventory extends CommonObject
37
{
38
	/**
39
	 * @var string ID to identify managed object
40
	 */
41
	public $element = 'inventory';
42
	/**
43
	 * @var string Name of table without prefix where object is stored
44
	 */
45
	public $table_element = 'inventory';
46
47
	/**
48
	 * @var array  Does this field is linked to a thirdparty ?
49
	 */
50
	protected $isnolinkedbythird = 1;
51
	/**
52
	 * @var array  Does inventory support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
53
	 */
54
	protected $ismultientitymanaged = 1;
55
	/**
56
	 * @var string String with name of icon for inventory
57
	 */
58
	public $picto = 'inventory';
59
60
61
	/**
62
	 *             'type' if the field format, 'label' the translation key, 'enabled' is a condition when the filed must be managed,
63
	 *             'visible' says if field is visible in list (-1 means not shown by default but can be aded into list to be viewed)
64
	 *             'notnull' if not null in database
65
	 *             'index' if we want an index in database
66
	 *             'position' is the sort order of field
67
	 *             'searchall' is 1 if we want to search in this field when making a search from the quick search button
68
	 *             'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
69
	 *             'comment' is not used. You can store here any text of your choice.
70
	 */
71
72
	// BEGIN MODULEBUILDER PROPERTIES
73
	/**
74
	 * @var array  Array with all fields and their property
75
	 */
76
	public $fields=array(
77
		'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-1, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
78
		'ref' => array('type'=>'varchar(64)', 'label'=>'Ref', 'visible'=>1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Reference of object',),
79
		'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,),
80
		'fk_warehouse' => array('type'=>'integer', 'label'=>'', 'visible'=>1, 'enabled'=>1, 'index'=>1,),
81
		'date_inventory' => array('type'=>'date', 'label'=>'', 'visible'=>1, 'enabled'=>1,),
82
		'title' => array('type'=>'varchar(255)', 'label'=>'', 'visible'=>1, 'enabled'=>1,),
83
		'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'index'=>1,),
84
		'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-1, 'enabled'=>1, 'position'=>500,),
85
		'date_validation' => array('type'=>'datetime', 'label'=>'DateValidation', 'visible'=>-1, 'enabled'=>1, 'position'=>500,),
86
		'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
87
		'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-1, 'enabled'=>1, 'position'=>500,),
88
		'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-1, 'enabled'=>1, 'position'=>500,),
89
		'fk_user_valid' => array('type'=>'integer', 'label'=>'UserValid', 'visible'=>-1, 'enabled'=>1, 'position'=>500,),
90
		'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'visible'=>-1, 'enabled'=>1, 'position'=>1000, 'index'=>1,),
91
	);
92
93
	public $rowid;
94
	public $ref;
95
	public $entity;
96
	public $fk_warehouse;
97
	public $date_inventory;
98
	public $title;
99
	public $status;
100
	public $date_creation;
101
	public $date_validation;
102
	public $tms;
103
	public $fk_user_creat;
104
	public $fk_user_modif;
105
	public $fk_user_valid;
106
	public $import_key;
107
	// END MODULEBUILDER PROPERTIES
108
109
110
111
	// If this object has a subtable with lines
112
113
	/**
114
	 * @var int    Name of subtable line
115
	 */
116
	//public $table_element_line = 'inventorydet';
117
	/**
118
	 * @var int    Field with ID of parent key if this field has a parent
119
	 */
120
	//public $fk_element = 'fk_inventory';
121
	/**
122
	 * @var int    Name of subtable class that manage subtable lines
123
	 */
124
	//public $class_element_line = 'Inventoryline';
125
	/**
126
	 * @var array  Array of child tables (child tables to delete before deleting a record)
127
	 */
128
	//protected $childtables=array('inventorydet');
129
	/**
130
	 * @var InventoryLine[]     Array of subtable lines
131
	 */
132
	//public $lines = array();
133
134
135
136
	/**
137
	 * Constructor
138
	 *
139
	 * @param DoliDb $db Database handler
140
	 */
141
	public function __construct(DoliDB $db)
142
	{
143
		$this->db = $db;
144
	}
145
146
147
	/**
148
	 *  Return a link to the object card (with optionaly the picto)
149
	 *
150
	 *	@param	int		$withpicto			Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
151
	 *	@param	string	$option				On what the link point to
152
     *  @param	int  	$notooltip			1=Disable tooltip
153
     *  @param  string  $morecss            Add more css on link
154
	 *	@return	string						String with URL
155
	 */
156
	function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='')
157
	{
158
		global $db, $conf, $langs;
159
        global $dolibarr_main_authentication, $dolibarr_main_demo;
160
        global $menumanager;
161
162
        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
163
164
        $result = '';
165
        $companylink = '';
166
167
        $label = '<u>' . $langs->trans("Inventory") . '</u>';
168
        $label.= '<br>';
169
        $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
170
171
        $url = $url = dol_buildpath('/inventory/m_card.php',1).'?id='.$this->id;
172
173
        $linkclose='';
174
        if (empty($notooltip))
175
        {
176
            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
177
            {
178
                $label=$langs->trans("ShowInventory");
179
                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
180
            }
181
            $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
182
            $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
183
        }
184
        else $linkclose = ($morecss?' class="'.$morecss.'"':'');
185
186
		$linkstart = '<a href="'.$url.'"';
187
		$linkstart.=$linkclose.'>';
188
		$linkend='</a>';
189
190
        if ($withpicto)
191
        {
192
            $result.=($linkstart.img_object(($notooltip?'':$label), 'label', ($notooltip?'':'class="classfortooltip"')).$linkend);
193
            if ($withpicto != 2) $result.=' ';
194
		}
195
		$result.= $linkstart . $this->ref . $linkend;
196
		return $result;
197
	}
198
199
	/**
200
	 *  Retourne le libelle du status d'un user (actif, inactif)
201
	 *
202
	 *  @param	int		$mode          0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
203
	 *  @return	string 			       Label of status
204
	 */
205
	function getLibStatut($mode=0)
206
	{
207
		return $this->LibStatut($this->status,$mode);
208
	}
209
210
	/**
211
	 *  Return the status
212
	 *
213
	 *  @param	int		$status        	Id status
214
	 *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 5=Long label + Picto
215
	 *  @return string 			       	Label of status
216
	 */
217
	static function LibStatut($status,$mode=0)
218
	{
219
		global $langs;
220
221
		if ($mode == 0)
222
		{
223
			$prefix='';
224
			if ($status == 1) return $langs->trans('Enabled');
225
			if ($status == 0) return $langs->trans('Disabled');
226
		}
227
		if ($mode == 1)
228
		{
229
			if ($status == 1) return $langs->trans('Enabled');
230
			if ($status == 0) return $langs->trans('Disabled');
231
		}
232
		if ($mode == 2)
233
		{
234
			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
235
			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
236
		}
237
		if ($mode == 3)
238
		{
239
			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
240
			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
241
		}
242
		if ($mode == 4)
243
		{
244
			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
245
			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
246
		}
247
		if ($mode == 5)
248
		{
249
			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
250
			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
251
		}
252
		if ($mode == 6)
253
		{
254
			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
255
			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
256
		}
257
	}
258
259
260
	/**
261
	 * Initialise object with example values
262
	 * Id must be 0 if object instance is a specimen
263
	 *
264
	 * @return void
265
	 */
266
	public function initAsSpecimen()
267
	{
268
		$this->initAsSpecimenCommon();
269
	}
270
271
}
272
273
/**
274
 * Class InventoryObjectLine
275
 */
276
class InventoryObjectLine
277
{
278
	/**
279
	 * @var int ID
280
	 */
281
	public $id;
282
	/**
283
	 * @var mixed Sample line property 1
284
	 */
285
	public $prop1;
286
	/**
287
	 * @var mixed Sample line property 2
288
	 */
289
	public $prop2;
290
}
291