1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Copyright (C) 2017 Laurent Destailleur <[email protected]> |
4
|
|
|
* Copyright (C) 2021 Gauthier VERDOL <[email protected]> |
5
|
|
|
* Copyright (C) 2022-2024 Frédéric France <[email protected]> |
6
|
|
|
* Copyright (C) 2024 MDW <[email protected]> |
7
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU General Public License as published by |
11
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
12
|
|
|
* (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace Dolibarr\Code\Product\Classes; |
24
|
|
|
|
25
|
|
|
use Dolibarr\Code\Core\Traits\CommonIncoterm; |
26
|
|
|
use Dolibarr\Code\User\Classes\User; |
27
|
|
|
use Dolibarr\Core\Base\CommonObject; |
28
|
|
|
use DoliDB; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* \file htdocs/product/stock/stocktransfer/class/stocktransfer.class.php |
32
|
|
|
* \ingroup stocktransfer |
33
|
|
|
* \brief This file is a CRUD class file for StockTransfer (Create/Read/Update/Delete) |
34
|
|
|
*/ |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Class for StockTransfer |
38
|
|
|
*/ |
39
|
|
|
class StockTransfer extends CommonObject |
40
|
|
|
{ |
41
|
|
|
use CommonIncoterm; |
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string ID to identify managed object. |
45
|
|
|
*/ |
46
|
|
|
public $element = 'stocktransfer'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string Name of table without prefix where object is stored. This is also the key used for extrafields management. |
50
|
|
|
*/ |
51
|
|
|
public $table_element = 'stocktransfer_stocktransfer'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string Name of subtable line |
55
|
|
|
*/ |
56
|
|
|
public $table_element_line = 'stocktransfer_stocktransferline'; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var string[] List of child tables. To know object to delete on cascade. |
60
|
|
|
* If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will |
61
|
|
|
* call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object |
62
|
|
|
*/ |
63
|
|
|
protected $childtablesoncascade = array('stocktransfer_stocktransferline'); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var string Customer ref |
67
|
|
|
* @deprecated |
68
|
|
|
* @see $ref_customer |
69
|
|
|
*/ |
70
|
|
|
public $ref_client; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var string Customer ref |
74
|
|
|
*/ |
75
|
|
|
public $ref_customer; |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var string String with name of icon for stocktransfer. Must be the part after the 'object_' into object_stocktransfer.png |
80
|
|
|
*/ |
81
|
|
|
public $picto = 'stock'; |
82
|
|
|
|
83
|
|
|
public $date_prevue_depart; |
84
|
|
|
public $date_prevue_arrivee; |
85
|
|
|
public $date_reelle_depart; |
86
|
|
|
public $date_reelle_arrivee; |
87
|
|
|
public $origin_type; |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
const STATUS_DRAFT = 0; |
91
|
|
|
const STATUS_VALIDATED = 1; |
92
|
|
|
const STATUS_TRANSFERED = 2; |
93
|
|
|
const STATUS_CLOSED = 3; |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') |
98
|
|
|
* Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" |
99
|
|
|
* 'label' the translation key. |
100
|
|
|
* 'enabled' is a condition when the field must be managed (Example: 1 or 'getDolGlobalString("MY_SETUP_PARAM")' |
101
|
|
|
* 'position' is the sort order of field. |
102
|
|
|
* 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). |
103
|
|
|
* 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing) |
104
|
|
|
* 'noteditable' says if field is not editable (1 or 0) |
105
|
|
|
* 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created. |
106
|
|
|
* 'index' if we want an index in database. |
107
|
|
|
* 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...). |
108
|
|
|
* 'searchall' is 1 if we want to search in this field when making a search from the quick search button. |
109
|
|
|
* '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). |
110
|
|
|
* 'css' is the CSS style to use on field. For example: 'maxwidth200' |
111
|
|
|
* 'help' is a string visible as a tooltip on field |
112
|
|
|
* 'showoncombobox' if value of the field must be visible into the label of the combobox that list record |
113
|
|
|
* 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code. |
114
|
|
|
* 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") |
115
|
|
|
* 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1. |
116
|
|
|
* 'comment' is not used. You can store here any text of your choice. It is not used by application. |
117
|
|
|
* |
118
|
|
|
* Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor. |
119
|
|
|
*/ |
120
|
|
|
|
121
|
|
|
// BEGIN MODULEBUILDER PROPERTIES |
122
|
|
|
/** |
123
|
|
|
* @var array<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}> Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. |
|
|
|
|
124
|
|
|
*/ |
125
|
|
|
public $fields = array( |
126
|
|
|
'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => "Id"), |
127
|
|
|
'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'position' => 1, 'default' => '1', 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => "Id"), |
128
|
|
|
'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => 1, 'comment' => "Reference of object"), |
129
|
|
|
'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 30, 'notnull' => 0, 'visible' => 1, 'searchall' => 1, 'showoncombobox' => 1, 'css' => 'minwidth100', 'csslist' => 'tdoverflowmax125', 'autofocusoncreate' => 1), |
130
|
|
|
'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 31, 'notnull' => 0, 'visible' => 3,), |
131
|
|
|
'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1', 'label' => 'Project', 'enabled' => '$conf->project->enabled', 'position' => 32, 'notnull' => -1, 'visible' => -1, 'index' => 1, 'picto' => 'project', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax125'), |
132
|
|
|
'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label' => 'ThirdParty', 'enabled' => 1, 'position' => 50, 'notnull' => -1, 'visible' => 1, 'index' => 1/*, 'help'=>"LinkToThirdparty"*/, 'picto' => 'company', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax125'), |
133
|
|
|
'fk_warehouse_source' => array('type' => 'integer:Entrepot:product/stock/class/entrepot.class.php', 'label' => 'Entrepôt source', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 1, 'help' => 'HelpWarehouseStockTransferSource', 'picto' => 'stock', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'), |
134
|
|
|
'fk_warehouse_destination' => array('type' => 'integer:Entrepot:product/stock/class/entrepot.class.php', 'label' => 'Entrepôt de destination', 'enabled' => 1, 'position' => 51, 'notnull' => 0, 'visible' => 1, 'help' => 'HelpWarehouseStockTransferDestination', 'picto' => 'stock', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'), |
135
|
|
|
'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0,), |
136
|
|
|
'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0,), |
137
|
|
|
'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,), |
138
|
|
|
'date_prevue_depart' => array('type' => 'date', 'label' => 'DatePrevueDepart', 'enabled' => 1, 'position' => 100, 'notnull' => 0, 'visible' => 1,), |
139
|
|
|
'date_reelle_depart' => array('type' => 'date', 'label' => 'DateReelleDepart', 'enabled' => 1, 'position' => 101, 'notnull' => 0, 'visible' => 5,), |
140
|
|
|
'date_prevue_arrivee' => array('type' => 'date', 'label' => 'DatePrevueArrivee', 'enabled' => 1, 'position' => 102, 'notnull' => 0, 'visible' => 1,), |
141
|
|
|
'date_reelle_arrivee' => array('type' => 'date', 'label' => 'DateReelleArrivee', 'enabled' => 1, 'position' => 103, 'notnull' => 0, 'visible' => 5,), |
142
|
|
|
'lead_time_for_warning' => array('type' => 'integer', 'label' => 'LeadTimeForWarning', 'enabled' => 1, 'position' => 200, 'default' => '0', 'notnull' => 0, 'visible' => 1), |
143
|
|
|
'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,), |
144
|
|
|
'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid',), |
145
|
|
|
'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'ChangedBy', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,), |
146
|
|
|
'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,), |
147
|
|
|
'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'position' => 1010, 'notnull' => -1, 'visible' => 0,), |
148
|
|
|
'fk_incoterms' => array('type' => 'integer', 'label' => 'IncotermCode', 'enabled' => '$conf->incoterm->enabled', 'visible' => -2, 'position' => 220), |
149
|
|
|
'location_incoterms' => array('type' => 'varchar(255)', 'label' => 'IncotermLabel', 'enabled' => '$conf->incoterm->enabled', 'visible' => -2, 'position' => 225), |
150
|
|
|
'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 1000, 'notnull' => 1, 'visible' => 5, 'index' => 1, 'arrayofkeyval' => array('0' => 'Draft', '1' => 'Validated', '2' => 'StockStransferDecremented', '3' => 'StockStransferIncremented'),), |
151
|
|
|
); |
152
|
|
|
public $rowid; |
153
|
|
|
public $ref; |
154
|
|
|
public $label; |
155
|
|
|
public $socid; |
156
|
|
|
public $fk_soc; // deprecated |
157
|
|
|
public $fk_project; |
158
|
|
|
public $description; |
159
|
|
|
public $note_public; |
160
|
|
|
public $note_private; |
161
|
|
|
public $date_creation; |
162
|
|
|
public $lead_time_for_warning; |
163
|
|
|
public $fk_user_creat; |
164
|
|
|
public $fk_user_modif; |
165
|
|
|
public $import_key; |
166
|
|
|
public $model_pdf; |
167
|
|
|
public $status; |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @var StockTransferLine[] stock transfer line |
171
|
|
|
*/ |
172
|
|
|
public $lines; |
173
|
|
|
|
174
|
|
|
public $fk_warehouse_source; |
175
|
|
|
public $fk_warehouse_destination; |
176
|
|
|
// END MODULEBUILDER PROPERTIES |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Constructor |
181
|
|
|
* |
182
|
|
|
* @param DoliDB $db Database handler |
183
|
|
|
*/ |
184
|
|
|
public function __construct(DoliDB $db) |
185
|
|
|
{ |
186
|
|
|
global $conf, $langs; |
187
|
|
|
|
188
|
|
|
$this->db = $db; |
189
|
|
|
|
190
|
|
|
$this->ismultientitymanaged = 0; |
191
|
|
|
$this->isextrafieldmanaged = 1; |
192
|
|
|
|
193
|
|
|
$this->origin_type = 'StockTransfer@product/stock/stocktransfer'; |
194
|
|
|
|
195
|
|
|
if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) { |
196
|
|
|
$this->fields['rowid']['visible'] = 0; |
197
|
|
|
} |
198
|
|
|
if (!isModEnabled('multicompany') && isset($this->fields['entity'])) { |
199
|
|
|
$this->fields['entity']['enabled'] = 0; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
// Example to show how to set values of fields definition dynamically |
203
|
|
|
/*if ($user->rights->stocktransfer->stocktransfer->read) { |
204
|
|
|
$this->fields['myfield']['visible'] = 1; |
205
|
|
|
$this->fields['myfield']['noteditable'] = 0; |
206
|
|
|
}*/ |
207
|
|
|
|
208
|
|
|
// Unset fields that are disabled |
209
|
|
|
foreach ($this->fields as $key => $val) { |
210
|
|
|
if (isset($val['enabled']) && empty($val['enabled'])) { |
211
|
|
|
unset($this->fields[$key]); |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
// Translate some data of arrayofkeyval |
216
|
|
|
if (is_object($langs)) { |
217
|
|
|
foreach ($this->fields as $key => $val) { |
218
|
|
|
if (isset($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { |
219
|
|
|
foreach ($val['arrayofkeyval'] as $key2 => $val2) { |
220
|
|
|
$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2); |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Create object into database |
229
|
|
|
* |
230
|
|
|
* @param User $user User that creates |
231
|
|
|
* @param int $notrigger 0=launch triggers after, 1=disable triggers |
232
|
|
|
* @return int Return integer <0 if KO, Id of created object if OK |
233
|
|
|
*/ |
234
|
|
|
public function create(User $user, $notrigger = 0) |
235
|
|
|
{ |
236
|
|
|
$this->status = (int)$this->status; |
237
|
|
|
if ($this->fk_warehouse_source <= 0) { |
238
|
|
|
$this->fk_warehouse_source = 0; |
239
|
|
|
} |
240
|
|
|
if ($this->fk_warehouse_destination <= 0) { |
241
|
|
|
$this->fk_warehouse_destination = 0; |
242
|
|
|
} |
243
|
|
|
return $this->createCommon($user, $notrigger); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Clone an object into another one |
248
|
|
|
* |
249
|
|
|
* @param User $user User that creates |
250
|
|
|
* @param int $fromid Id of object to clone |
251
|
|
|
* @return mixed New object created, <0 if KO |
252
|
|
|
*/ |
253
|
|
|
public function createFromClone(User $user, $fromid) |
254
|
|
|
{ |
255
|
|
|
global $langs, $extrafields; |
256
|
|
|
$error = 0; |
257
|
|
|
|
258
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG); |
259
|
|
|
|
260
|
|
|
$object = new self($this->db); |
261
|
|
|
|
262
|
|
|
$this->db->begin(); |
263
|
|
|
|
264
|
|
|
// Load source object |
265
|
|
|
$result = $object->fetchCommon($fromid); |
266
|
|
|
if ($result > 0 && !empty($object->table_element_line)) { |
267
|
|
|
$object->fetchLines(); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
// get lines so they will be clone |
271
|
|
|
//foreach($this->lines as $line) |
272
|
|
|
// $line->fetch_optionals(); |
273
|
|
|
|
274
|
|
|
// Reset some properties |
275
|
|
|
unset($object->id); |
276
|
|
|
unset($object->fk_user_creat); |
277
|
|
|
unset($object->import_key); |
278
|
|
|
unset($object->date_prevue_depart); |
279
|
|
|
unset($object->date_prevue_arrivee); |
280
|
|
|
unset($object->date_reelle_depart); |
281
|
|
|
unset($object->date_reelle_arrivee); |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
// Clear fields |
285
|
|
|
$object->ref = empty($this->fields['ref']['default']) ? "copy_of_" . $object->ref : $this->fields['ref']['default']; |
286
|
|
|
$object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf") . " " . $object->label : $this->fields['label']['default']; |
287
|
|
|
$object->status = self::STATUS_DRAFT; |
288
|
|
|
// ... |
289
|
|
|
// Clear extrafields that are unique |
290
|
|
|
if (is_array($object->array_options) && count($object->array_options) > 0) { |
291
|
|
|
$extrafields->fetch_name_optionals_label($this->table_element); |
292
|
|
|
foreach ($object->array_options as $key => $option) { |
293
|
|
|
$shortkey = preg_replace('/options_/', '', $key); |
294
|
|
|
if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) { |
295
|
|
|
//var_dump($key); var_dump($clonedObj->array_options[$key]); exit; |
296
|
|
|
unset($object->array_options[$key]); |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
// Create clone |
302
|
|
|
$object->context['createfromclone'] = 'createfromclone'; |
303
|
|
|
$result = $object->createCommon($user); |
304
|
|
|
if ($result < 0) { |
305
|
|
|
$error++; |
306
|
|
|
$this->error = $object->error; |
307
|
|
|
$this->errors = $object->errors; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
if (!$error) { |
311
|
|
|
// copy internal contacts |
312
|
|
|
if ($this->copy_linked_contact($object, 'internal') < 0) { |
313
|
|
|
$error++; |
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
if (!$error) { |
318
|
|
|
// copy external contacts if same company |
319
|
|
|
if (property_exists($this, 'socid') && $this->socid == $object->socid) { |
320
|
|
|
if ($this->copy_linked_contact($object, 'external') < 0) { |
321
|
|
|
$error++; |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
unset($object->context['createfromclone']); |
327
|
|
|
|
328
|
|
|
// End |
329
|
|
|
if (!$error) { |
330
|
|
|
$this->db->commit(); |
331
|
|
|
return $object; |
332
|
|
|
} else { |
333
|
|
|
$this->db->rollback(); |
334
|
|
|
return -1; |
335
|
|
|
} |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Load object in memory from the database |
340
|
|
|
* |
341
|
|
|
* @param int $id Id object |
342
|
|
|
* @param string $ref Ref |
343
|
|
|
* @return int Return integer <0 if KO, 0 if not found, >0 if OK |
344
|
|
|
*/ |
345
|
|
|
public function fetch($id, $ref = null) |
346
|
|
|
{ |
347
|
|
|
$result = $this->fetchCommon($id, $ref); |
348
|
|
|
|
349
|
|
|
$this->socid = $this->fk_soc; |
350
|
|
|
|
351
|
|
|
if ($result > 0 && !empty($this->table_element_line)) { |
352
|
|
|
$this->fetchLines(); |
353
|
|
|
} |
354
|
|
|
return $result; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Load object lines in memory from the database |
359
|
|
|
* |
360
|
|
|
* @return int Return integer <0 if KO, 0 if not found, >0 if OK |
361
|
|
|
*/ |
362
|
|
|
public function fetchLines() |
363
|
|
|
{ |
364
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/product/stock/stocktransfer/class/stocktransferline.class.php'; |
365
|
|
|
$this->lines = array(); |
366
|
|
|
|
367
|
|
|
$result = $this->fetchLinesCommon(); |
368
|
|
|
usort($this->lines, array('Dolibarr\Code\Product\Classes\StockTransfer', 'stocktransferCmpRank')); |
369
|
|
|
return $result; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* Used to sort lines by rank |
374
|
|
|
* |
375
|
|
|
* @param Object $a 1st element to test |
376
|
|
|
* @param Object $b 2nd element to test |
377
|
|
|
* @return int |
378
|
|
|
*/ |
379
|
|
|
public static function stocktransferCmpRank($a, $b) |
380
|
|
|
{ |
381
|
|
|
if ($a->rang == $b->rang) { |
382
|
|
|
return 0; |
383
|
|
|
} |
384
|
|
|
return ($a->rang < $b->rang) ? -1 : 1; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* Used to get total PMP amount of all quantities of products of Stock Transfer |
389
|
|
|
* |
390
|
|
|
* @return float total amount of Stock Transfer |
391
|
|
|
*/ |
392
|
|
|
public function getValorisationTotale() |
393
|
|
|
{ |
394
|
|
|
$total_pmp = 0; |
395
|
|
|
|
396
|
|
|
if (empty($this->lines)) { |
397
|
|
|
$this->fetchLines(); |
398
|
|
|
} |
399
|
|
|
if (!empty($this->lines)) { |
400
|
|
|
foreach ($this->lines as $l) { |
401
|
|
|
$total_pmp += ($l->pmp * $l->qty); |
402
|
|
|
} |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
return $total_pmp; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* Load list of objects in memory from the database. |
410
|
|
|
* |
411
|
|
|
* @param string $sortorder Sort Order |
412
|
|
|
* @param string $sortfield Sort field |
413
|
|
|
* @param int $limit limit |
414
|
|
|
* @param int $offset Offset |
415
|
|
|
* @param string $filter Filter as an Universal Search string. |
416
|
|
|
* Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' |
417
|
|
|
* @param string $filtermode No more used |
418
|
|
|
* @return array|int int <0 if KO, array of pages if OK |
419
|
|
|
*/ |
420
|
|
|
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') |
421
|
|
|
{ |
422
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG); |
423
|
|
|
|
424
|
|
|
$records = array(); |
425
|
|
|
|
426
|
|
|
$sql = 'SELECT '; |
427
|
|
|
$sql .= $this->getFieldList(); |
428
|
|
|
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; |
429
|
|
|
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
430
|
|
|
$sql .= ' WHERE t.entity IN (' . getEntity($this->element) . ')'; |
431
|
|
|
} else { |
432
|
|
|
$sql .= ' WHERE 1 = 1'; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
// Manage filter |
436
|
|
|
$errormessage = ''; |
437
|
|
|
$sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage); |
438
|
|
|
if ($errormessage) { |
439
|
|
|
$this->errors[] = $errormessage; |
440
|
|
|
dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
441
|
|
|
return -1; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
if (!empty($sortfield)) { |
445
|
|
|
$sql .= $this->db->order($sortfield, $sortorder); |
446
|
|
|
} |
447
|
|
|
if (!empty($limit)) { |
448
|
|
|
$sql .= ' ' . $this->db->plimit($limit, $offset); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
$resql = $this->db->query($sql); |
452
|
|
|
if ($resql) { |
453
|
|
|
$num = $this->db->num_rows($resql); |
454
|
|
|
$i = 0; |
455
|
|
|
while ($i < ($limit ? min($limit, $num) : $num)) { |
456
|
|
|
$obj = $this->db->fetch_object($resql); |
457
|
|
|
|
458
|
|
|
$record = new self($this->db); |
459
|
|
|
$record->setVarsFromFetchObj($obj); |
460
|
|
|
|
461
|
|
|
$records[$record->id] = $record; |
462
|
|
|
|
463
|
|
|
$i++; |
464
|
|
|
} |
465
|
|
|
$this->db->free($resql); |
466
|
|
|
|
467
|
|
|
return $records; |
468
|
|
|
} else { |
469
|
|
|
$this->errors[] = 'Error ' . $this->db->lasterror(); |
470
|
|
|
dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
471
|
|
|
|
472
|
|
|
return -1; |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* Update object into database |
478
|
|
|
* |
479
|
|
|
* @param User $user User that modifies |
480
|
|
|
* @param int $notrigger 0=launch triggers after, 1=disable triggers |
481
|
|
|
* @return int Return integer <0 if KO, >0 if OK |
482
|
|
|
*/ |
483
|
|
|
public function update(User $user, $notrigger = 0) |
484
|
|
|
{ |
485
|
|
|
$this->tms = 0; // Will be done automatically because tms field is on update cascade |
|
|
|
|
486
|
|
|
$res = $this->updateCommon($user, $notrigger); |
487
|
|
|
if (($this->socid > 0 || $this->fk_soc > 0) && empty($this->thirdparty)) { |
488
|
|
|
$this->fetch_thirdparty(); |
489
|
|
|
} |
490
|
|
|
if (empty($this->socid) && empty($this->fk_soc)) { |
491
|
|
|
unset($this->thirdparty); |
492
|
|
|
} |
493
|
|
|
return $res; |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* Delete object in database |
498
|
|
|
* |
499
|
|
|
* @param User $user User that deletes |
500
|
|
|
* @param int $notrigger 0=launch triggers after, 1=disable triggers |
501
|
|
|
* @return int Return integer <0 if KO, >0 if OK |
502
|
|
|
*/ |
503
|
|
|
public function delete(User $user, $notrigger = 0) |
504
|
|
|
{ |
505
|
|
|
if ($this->status > self::STATUS_VALIDATED) { |
506
|
|
|
return 0; |
507
|
|
|
} else { |
508
|
|
|
return $this->deleteCommon($user, $notrigger); |
509
|
|
|
} |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Delete a line of object in database |
514
|
|
|
* |
515
|
|
|
* @param User $user User that delete |
516
|
|
|
* @param int $idline Id of line to delete |
517
|
|
|
* @param int $notrigger 0=launch triggers after, 1=disable triggers |
518
|
|
|
* @return int >0 if OK, <0 if KO |
519
|
|
|
*/ |
520
|
|
|
public function deleteLine(User $user, $idline, $notrigger = 0) |
521
|
|
|
{ |
522
|
|
|
if ($this->status < 0) { |
523
|
|
|
$this->error = 'ErrorDeleteLineNotAllowedByObjectStatus'; |
524
|
|
|
return -2; |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
$res = $this->deleteLineCommon($user, $idline, $notrigger); |
528
|
|
|
$this->line_order(true); |
529
|
|
|
return $res; |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Validate object |
535
|
|
|
* |
536
|
|
|
* @param User $user User making status change |
537
|
|
|
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers |
538
|
|
|
* @return int Return integer <=0 if OK, 0=Nothing done, >0 if KO |
539
|
|
|
*/ |
540
|
|
|
public function validate($user, $notrigger = 0) |
541
|
|
|
{ |
542
|
|
|
global $conf, $langs; |
543
|
|
|
|
544
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php'; |
545
|
|
|
|
546
|
|
|
$error = 0; |
547
|
|
|
|
548
|
|
|
// Protection |
549
|
|
|
if ($this->status == self::STATUS_VALIDATED) { |
550
|
|
|
dol_syslog(get_class($this) . "::validate action abandoned: already validated", LOG_WARNING); |
551
|
|
|
return 0; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer->write)) |
555
|
|
|
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer->stocktransfer_advance->validate)))) |
556
|
|
|
{ |
557
|
|
|
$this->error='NotEnoughPermissions'; |
558
|
|
|
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); |
559
|
|
|
return -1; |
560
|
|
|
}*/ |
561
|
|
|
|
562
|
|
|
$now = dol_now(); |
563
|
|
|
|
564
|
|
|
$this->db->begin(); |
565
|
|
|
|
566
|
|
|
// Define new ref |
567
|
|
|
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life |
568
|
|
|
$num = $this->getNextNumRef(); |
569
|
|
|
} else { |
570
|
|
|
$num = $this->ref; |
571
|
|
|
} |
572
|
|
|
$this->newref = $num; |
573
|
|
|
|
574
|
|
|
if (!empty($num)) { |
575
|
|
|
// Validate |
576
|
|
|
$sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element; |
577
|
|
|
$sql .= " SET ref = '" . $this->db->escape($num) . "',"; |
578
|
|
|
$sql .= " status = " . self::STATUS_VALIDATED; |
579
|
|
|
if (!empty($this->fields['date_validation'])) { |
580
|
|
|
$sql .= ", date_validation = '" . $this->db->idate($now) . "',"; |
581
|
|
|
} |
582
|
|
|
if (!empty($this->fields['fk_user_valid'])) { |
583
|
|
|
$sql .= ", fk_user_valid = " . ((int)$user->id); |
584
|
|
|
} |
585
|
|
|
$sql .= " WHERE rowid = " . ((int)$this->id); |
586
|
|
|
|
587
|
|
|
dol_syslog(get_class($this) . "::validate()", LOG_DEBUG); |
588
|
|
|
$resql = $this->db->query($sql); |
589
|
|
|
if (!$resql) { |
590
|
|
|
dol_print_error($this->db); |
591
|
|
|
$this->error = $this->db->lasterror(); |
592
|
|
|
$error++; |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
if (!$error && !$notrigger) { |
596
|
|
|
// Call trigger |
597
|
|
|
$result = $this->call_trigger('STOCKTRANSFER_VALIDATE', $user); |
598
|
|
|
if ($result < 0) { |
599
|
|
|
$error++; |
600
|
|
|
} |
601
|
|
|
// End call triggers |
602
|
|
|
} |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
if (!$error) { |
606
|
|
|
$this->oldref = $this->ref; |
607
|
|
|
|
608
|
|
|
// Rename directory if dir was a temporary ref |
609
|
|
|
if (preg_match('/^[\(]?PROV/i', $this->ref)) { |
610
|
|
|
// Now we rename also files into index |
611
|
|
|
$sql = 'UPDATE ' . MAIN_DB_PREFIX . "ecm_files set filename = CONCAT('" . $this->db->escape($this->newref) . "', SUBSTR(filename, " . (strlen($this->ref) + 1) . ")), filepath = 'stocktransfer/" . $this->db->escape($this->newref) . "'"; |
612
|
|
|
$sql .= " WHERE filename LIKE '" . $this->db->escape($this->ref) . "%' AND filepath = 'stocktransfer/" . $this->db->escape($this->ref) . "' and entity = " . ((int)$conf->entity); |
613
|
|
|
$resql = $this->db->query($sql); |
614
|
|
|
if (!$resql) { |
615
|
|
|
$error++; |
616
|
|
|
$this->error = $this->db->lasterror(); |
617
|
|
|
} |
618
|
|
|
$sql = 'UPDATE ' . MAIN_DB_PREFIX . "ecm_files set filepath = 'stocktransfer/" . $this->db->escape($this->newref) . "'"; |
619
|
|
|
$sql .= " WHERE filepath = 'stocktransfer/" . $this->db->escape($this->ref) . "' and entity = " . $conf->entity; |
620
|
|
|
$resql = $this->db->query($sql); |
621
|
|
|
if (!$resql) { |
622
|
|
|
$error++; |
623
|
|
|
$this->error = $this->db->lasterror(); |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments |
627
|
|
|
$oldref = dol_sanitizeFileName($this->ref); |
628
|
|
|
$newref = dol_sanitizeFileName($num); |
629
|
|
|
$dirsource = $conf->stocktransfer->dir_output . '/stocktransfer/' . $oldref; |
630
|
|
|
$dirdest = $conf->stocktransfer->dir_output . '/stocktransfer/' . $newref; |
631
|
|
|
if (!$error && file_exists($dirsource)) { |
632
|
|
|
dol_syslog(get_class($this) . "::validate() rename dir " . $dirsource . " into " . $dirdest); |
633
|
|
|
|
634
|
|
|
if (@rename($dirsource, $dirdest)) { |
635
|
|
|
dol_syslog("Rename ok"); |
636
|
|
|
// Rename docs starting with $oldref with $newref |
637
|
|
|
$listoffiles = dol_dir_list($conf->stocktransfer->dir_output . '/stocktransfer/' . $newref, 'files', 1, '^' . preg_quote($oldref, '/')); |
638
|
|
|
foreach ($listoffiles as $fileentry) { |
639
|
|
|
$dirsource = $fileentry['name']; |
640
|
|
|
$dirdest = preg_replace('/^' . preg_quote($oldref, '/') . '/', $newref, $dirsource); |
641
|
|
|
$dirsource = $fileentry['path'] . '/' . $dirsource; |
642
|
|
|
$dirdest = $fileentry['path'] . '/' . $dirdest; |
643
|
|
|
@rename($dirsource, $dirdest); |
|
|
|
|
644
|
|
|
} |
645
|
|
|
} |
646
|
|
|
} |
647
|
|
|
} |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
// Set new ref and current status |
651
|
|
|
if (!$error) { |
652
|
|
|
$this->ref = $num; |
653
|
|
|
$this->status = self::STATUS_VALIDATED; |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
if (!$error) { |
657
|
|
|
$this->db->commit(); |
658
|
|
|
return 1; |
659
|
|
|
} else { |
660
|
|
|
$this->db->rollback(); |
661
|
|
|
return -1; |
662
|
|
|
} |
663
|
|
|
} |
664
|
|
|
|
665
|
|
|
|
666
|
|
|
/** |
667
|
|
|
* Set draft status |
668
|
|
|
* |
669
|
|
|
* @param User $user Object user that modify |
670
|
|
|
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers |
671
|
|
|
* @return int Return integer <0 if KO, >0 if OK |
672
|
|
|
*/ |
673
|
|
|
public function setDraft($user, $notrigger = 0) |
674
|
|
|
{ |
675
|
|
|
// Protection |
676
|
|
|
if ($this->status <= self::STATUS_DRAFT) { |
677
|
|
|
return 0; |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write)) |
681
|
|
|
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate)))) |
682
|
|
|
{ |
683
|
|
|
$this->error='Permission denied'; |
684
|
|
|
return -1; |
685
|
|
|
}*/ |
686
|
|
|
|
687
|
|
|
return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'STOCKTRANSFER_UNVALIDATE'); |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
/** |
691
|
|
|
* Set cancel status |
692
|
|
|
* |
693
|
|
|
* @param User $user Object user that modify |
694
|
|
|
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers |
695
|
|
|
* @return int Return integer <0 if KO, 0=Nothing done, >0 if OK |
696
|
|
|
*/ |
697
|
|
|
public function cancel($user, $notrigger = 0) |
698
|
|
|
{ |
699
|
|
|
// Protection |
700
|
|
|
if ($this->status != self::STATUS_VALIDATED) { |
701
|
|
|
return 0; |
702
|
|
|
} |
703
|
|
|
|
704
|
|
|
/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write)) |
705
|
|
|
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate)))) |
706
|
|
|
{ |
707
|
|
|
$this->error='Permission denied'; |
708
|
|
|
return -1; |
709
|
|
|
}*/ |
710
|
|
|
|
711
|
|
|
return $this->setStatusCommon($user, self::STATUS_CLOSED, $notrigger, 'STOCKTRANSFER_CLOSE'); |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
/** |
715
|
|
|
* Set back to validated status |
716
|
|
|
* |
717
|
|
|
* @param User $user Object user that modify |
718
|
|
|
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers |
719
|
|
|
* @return int Return integer <0 if KO, 0=Nothing done, >0 if OK |
720
|
|
|
*/ |
721
|
|
|
public function reopen($user, $notrigger = 0) |
722
|
|
|
{ |
723
|
|
|
// Protection |
724
|
|
|
if ($this->status != self::STATUS_CLOSED) { |
725
|
|
|
return 0; |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write)) |
729
|
|
|
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate)))) |
730
|
|
|
{ |
731
|
|
|
$this->error='Permission denied'; |
732
|
|
|
return -1; |
733
|
|
|
}*/ |
734
|
|
|
|
735
|
|
|
return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'STOCKTRANSFER_REOPEN'); |
736
|
|
|
} |
737
|
|
|
|
738
|
|
|
/** |
739
|
|
|
* Return a link to the object card (with optionally the picto) |
740
|
|
|
* |
741
|
|
|
* @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) |
742
|
|
|
* @param string $option On what the link point to ('nolink', ...) |
743
|
|
|
* @param int $notooltip 1=Disable tooltip |
744
|
|
|
* @param string $morecss Add more css on link |
745
|
|
|
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
746
|
|
|
* @return string String with URL |
747
|
|
|
*/ |
748
|
|
|
public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) |
749
|
|
|
{ |
750
|
|
|
global $conf, $langs, $hookmanager; |
751
|
|
|
|
752
|
|
|
if (!empty($conf->dol_no_mouse_hover)) { |
753
|
|
|
$notooltip = 1; |
754
|
|
|
} // Force disable tooltips |
755
|
|
|
|
756
|
|
|
$result = ''; |
757
|
|
|
|
758
|
|
|
$label = '<u>' . $langs->trans("StockTransfer") . '</u>'; |
759
|
|
|
$label .= '<br>'; |
760
|
|
|
$label .= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref; |
761
|
|
|
if (isset($this->status)) { |
762
|
|
|
$label .= '<br><b>' . $langs->trans("Status") . ":</b> " . $this->getLibStatut(5); |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
$url = dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1) . '?id=' . $this->id; |
766
|
|
|
|
767
|
|
|
if ($option != 'nolink') { |
768
|
|
|
// Add param to save lastsearch_values or not |
769
|
|
|
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
770
|
|
|
if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { |
771
|
|
|
$add_save_lastsearch_values = 1; |
772
|
|
|
} |
773
|
|
|
if ($add_save_lastsearch_values) { |
774
|
|
|
$url .= '&save_lastsearch_values=1'; |
775
|
|
|
} |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
$linkclose = ''; |
779
|
|
|
if (empty($notooltip)) { |
780
|
|
|
if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { |
781
|
|
|
$label = $langs->trans("ShowStockTransfer"); |
782
|
|
|
$linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"'; |
783
|
|
|
} |
784
|
|
|
$linkclose .= ' title="' . dol_escape_htmltag($label, 1) . '"'; |
785
|
|
|
$linkclose .= ' class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"'; |
786
|
|
|
} else { |
787
|
|
|
$linkclose = ($morecss ? ' class="' . $morecss . '"' : ''); |
788
|
|
|
} |
789
|
|
|
|
790
|
|
|
$linkstart = '<a href="' . $url . '"'; |
791
|
|
|
$linkstart .= $linkclose . '>'; |
792
|
|
|
$linkend = '</a>'; |
793
|
|
|
|
794
|
|
|
$result .= $linkstart; |
795
|
|
|
|
796
|
|
|
if (empty($this->showphoto_on_popup)) { |
797
|
|
|
if ($withpicto) { |
798
|
|
|
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); |
799
|
|
|
} |
800
|
|
|
} else { |
801
|
|
|
if ($withpicto) { |
802
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php'; |
803
|
|
|
|
804
|
|
|
list($class, $module) = explode('@', $this->picto); |
805
|
|
|
$upload_dir = $conf->$module->multidir_output[$conf->entity] . "/$class/" . dol_sanitizeFileName($this->ref); |
806
|
|
|
$filearray = dol_dir_list($upload_dir, "files"); |
807
|
|
|
$filename = $filearray[0]['name']; |
808
|
|
|
if (!empty($filename)) { |
809
|
|
|
$pospoint = strpos($filearray[0]['name'], '.'); |
810
|
|
|
|
811
|
|
|
$pathtophoto = $class . '/' . $this->ref . '/thumbs/' . substr($filename, 0, $pospoint) . '_mini' . substr($filename, $pospoint); |
812
|
|
|
if (!getDolGlobalString(strtoupper($module . '_' . $class) . '_FORMATLISTPHOTOSASUSERS')) { |
813
|
|
|
$result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo' . $module . '" alt="No photo" border="0" src="' . constant('BASE_URL') . '/viewimage.php?modulepart=' . $module . '&entity=' . $conf->entity . '&file=' . urlencode($pathtophoto) . '"></div></div>'; |
814
|
|
|
} else { |
815
|
|
|
$result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="' . constant('BASE_URL') . '/viewimage.php?modulepart=' . $module . '&entity=' . $conf->entity . '&file=' . urlencode($pathtophoto) . '"></div>'; |
816
|
|
|
} |
817
|
|
|
|
818
|
|
|
$result .= '</div>'; |
819
|
|
|
} else { |
820
|
|
|
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); |
821
|
|
|
} |
822
|
|
|
} |
823
|
|
|
} |
824
|
|
|
|
825
|
|
|
if ($withpicto != 2) { |
826
|
|
|
$result .= $this->ref; |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
$result .= $linkend; |
830
|
|
|
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); |
831
|
|
|
|
832
|
|
|
global $action, $hookmanager; |
833
|
|
|
$hookmanager->initHooks(array('stocktransferdao')); |
834
|
|
|
$parameters = array('id' => $this->id, 'getnomurl' => $result); |
835
|
|
|
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
836
|
|
|
if ($reshook > 0) { |
837
|
|
|
$result = $hookmanager->resPrint; |
838
|
|
|
} else { |
839
|
|
|
$result .= $hookmanager->resPrint; |
840
|
|
|
} |
841
|
|
|
|
842
|
|
|
return $result; |
843
|
|
|
} |
844
|
|
|
|
845
|
|
|
/** |
846
|
|
|
* Return label of the status |
847
|
|
|
* |
848
|
|
|
* @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 |
849
|
|
|
* @return string Label of status |
850
|
|
|
*/ |
851
|
|
|
public function getLibStatut($mode = 0) |
852
|
|
|
{ |
853
|
|
|
return $this->LibStatut($this->status, $mode); |
854
|
|
|
} |
855
|
|
|
|
856
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
857
|
|
|
|
858
|
|
|
/** |
859
|
|
|
* Return the status |
860
|
|
|
* |
861
|
|
|
* @param int $status Id status |
862
|
|
|
* @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 |
863
|
|
|
* @return string Label of status |
864
|
|
|
*/ |
865
|
|
|
public function LibStatut($status, $mode = 0) |
866
|
|
|
{ |
867
|
|
|
// phpcs:enable |
868
|
|
|
if (empty($this->labelStatus) || empty($this->labelStatusShort)) { |
869
|
|
|
global $langs; |
870
|
|
|
//$langs->load("stocktransfer@stocktransfer"); |
871
|
|
|
$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft'); |
872
|
|
|
$this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated'); |
873
|
|
|
$this->labelStatus[self::STATUS_TRANSFERED] = $langs->trans('StockStransferDecremented'); |
874
|
|
|
$this->labelStatus[self::STATUS_CLOSED] = $langs->trans('StockStransferIncremented'); |
875
|
|
|
$this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft'); |
876
|
|
|
$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated'); |
877
|
|
|
$this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->trans('StockStransferDecremented'); |
878
|
|
|
$this->labelStatusShort[self::STATUS_CLOSED] = $langs->trans('StockStransferIncremented'); |
879
|
|
|
} |
880
|
|
|
|
881
|
|
|
$statusType = 'status' . $status; |
882
|
|
|
//if ($status == self::STATUS_VALIDATED) $statusType = 'status1'; |
883
|
|
|
if ($status == self::STATUS_CLOSED) { |
884
|
|
|
$statusType = 'status6'; |
885
|
|
|
} |
886
|
|
|
|
887
|
|
|
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); |
888
|
|
|
} |
889
|
|
|
|
890
|
|
|
/** |
891
|
|
|
* Load the info information in the object |
892
|
|
|
* |
893
|
|
|
* @param int $id Id of object |
894
|
|
|
* @return void |
895
|
|
|
*/ |
896
|
|
|
public function info($id) |
897
|
|
|
{ |
898
|
|
|
$sql = 'SELECT rowid, date_creation as datec, tms as datem,'; |
899
|
|
|
$sql .= ' fk_user_creat, fk_user_modif'; |
900
|
|
|
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; |
901
|
|
|
$sql .= ' WHERE t.rowid = ' . ((int)$id); |
902
|
|
|
$result = $this->db->query($sql); |
903
|
|
|
if ($result) { |
904
|
|
|
if ($this->db->num_rows($result)) { |
905
|
|
|
$obj = $this->db->fetch_object($result); |
906
|
|
|
$this->id = $obj->rowid; |
907
|
|
|
|
908
|
|
|
$this->user_creation_id = $obj->fk_user_creat; |
909
|
|
|
$this->user_modification_id = $obj->fk_user_modif; |
910
|
|
|
$this->date_creation = $this->db->jdate($obj->datec); |
911
|
|
|
$this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem); |
912
|
|
|
} |
913
|
|
|
|
914
|
|
|
$this->db->free($result); |
915
|
|
|
} else { |
916
|
|
|
dol_print_error($this->db); |
917
|
|
|
} |
918
|
|
|
} |
919
|
|
|
|
920
|
|
|
/** |
921
|
|
|
* Initialise object with example values |
922
|
|
|
* Id must be 0 if object instance is a specimen |
923
|
|
|
* |
924
|
|
|
* @return int |
925
|
|
|
*/ |
926
|
|
|
public function initAsSpecimen() |
927
|
|
|
{ |
928
|
|
|
return $this->initAsSpecimenCommon(); |
929
|
|
|
} |
930
|
|
|
|
931
|
|
|
/** |
932
|
|
|
* Create an array of lines |
933
|
|
|
* |
934
|
|
|
* @return array|int array of lines if OK, <0 if KO |
935
|
|
|
*/ |
936
|
|
|
public function getLinesArray() |
937
|
|
|
{ |
938
|
|
|
$this->lines = array(); |
939
|
|
|
|
940
|
|
|
$objectline = new StockTransferLine($this->db); |
941
|
|
|
$result = $objectline->fetchAll('ASC', 'rang', 0, 0, "(fk_stocktransfer:=:" . ((int)$this->id) . ")"); |
942
|
|
|
|
943
|
|
|
if (is_numeric($result)) { |
944
|
|
|
$this->error = $objectline->error; |
945
|
|
|
$this->errors = $objectline->errors; |
946
|
|
|
return $result; |
947
|
|
|
} else { |
948
|
|
|
$this->lines = $result; |
949
|
|
|
return $this->lines; |
950
|
|
|
} |
951
|
|
|
} |
952
|
|
|
|
953
|
|
|
/** |
954
|
|
|
* Returns the reference to the following non used object depending on the active numbering module. |
955
|
|
|
* |
956
|
|
|
* @return string Object free reference |
957
|
|
|
*/ |
958
|
|
|
public function getNextNumRef() |
959
|
|
|
{ |
960
|
|
|
global $langs, $conf; |
961
|
|
|
$langs->load("stocks"); |
962
|
|
|
|
963
|
|
|
if (!getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADDON')) { |
964
|
|
|
$conf->global->STOCKTRANSFER_STOCKTRANSFER_ADDON = 'mod_stocktransfer_standard'; |
965
|
|
|
} |
966
|
|
|
|
967
|
|
|
if (getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADDON')) { |
968
|
|
|
$mybool = false; |
969
|
|
|
|
970
|
|
|
$file = getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADDON') . ".php"; |
971
|
|
|
$classname = getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADDON'); |
972
|
|
|
|
973
|
|
|
// Include file with class |
974
|
|
|
$dirmodels = array_merge(array('/'), (array)$conf->modules_parts['models']); |
975
|
|
|
foreach ($dirmodels as $reldir) { |
976
|
|
|
$dir = dol_buildpath($reldir . "core/modules/stocktransfer/"); |
977
|
|
|
|
978
|
|
|
// Load file with numbering class (if found) |
979
|
|
|
$mybool = ((bool)@include_once $dir . $file) || $mybool; |
980
|
|
|
} |
981
|
|
|
|
982
|
|
|
if ($mybool === false) { |
983
|
|
|
dol_print_error(null, "Failed to include file " . $file); |
984
|
|
|
return ''; |
985
|
|
|
} |
986
|
|
|
|
987
|
|
|
if (class_exists($classname)) { |
988
|
|
|
$obj = new $classname(); |
989
|
|
|
$numref = $obj->getNextValue($this); |
990
|
|
|
|
991
|
|
|
if ($numref != '' && $numref != '-1') { |
992
|
|
|
return $numref; |
993
|
|
|
} else { |
994
|
|
|
$this->error = $obj->error; |
995
|
|
|
//dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error); |
996
|
|
|
return ""; |
997
|
|
|
} |
998
|
|
|
} else { |
999
|
|
|
print $langs->trans("Error") . " " . $langs->trans("ClassNotFound") . ' ' . $classname; |
1000
|
|
|
return ""; |
1001
|
|
|
} |
1002
|
|
|
} else { |
1003
|
|
|
print $langs->trans("ErrorNumberingModuleNotSetup", $this->element); |
1004
|
|
|
return ""; |
1005
|
|
|
} |
1006
|
|
|
} |
1007
|
|
|
|
1008
|
|
|
/** |
1009
|
|
|
* Create a document onto disk according to template module. |
1010
|
|
|
* |
1011
|
|
|
* @param string $modele Force template to use ('' to not force) |
1012
|
|
|
* @param Translate $outputlangs object lang a utiliser pour traduction |
1013
|
|
|
* @param int $hidedetails Hide details of lines |
1014
|
|
|
* @param int $hidedesc Hide description |
1015
|
|
|
* @param int $hideref Hide ref |
1016
|
|
|
* @param null|array $moreparams Array to provide more information |
1017
|
|
|
* @return int 0 if KO, 1 if OK |
1018
|
|
|
*/ |
1019
|
|
|
public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) |
1020
|
|
|
{ |
1021
|
|
|
global $conf, $langs; |
1022
|
|
|
|
1023
|
|
|
$result = 0; |
1024
|
|
|
$includedocgeneration = 1; |
1025
|
|
|
|
1026
|
|
|
$langs->load("stocks"); |
1027
|
|
|
|
1028
|
|
|
if (!dol_strlen($modele)) { |
1029
|
|
|
$modele = 'eagle'; |
1030
|
|
|
|
1031
|
|
|
if ($this->model_pdf) { |
1032
|
|
|
$modele = $this->model_pdf; |
1033
|
|
|
} elseif (getDolGlobalString('STOCKTRANSFER_ADDON_PDF')) { |
1034
|
|
|
$modele = getDolGlobalString('STOCKTRANSFER_ADDON_PDF'); |
1035
|
|
|
} |
1036
|
|
|
} |
1037
|
|
|
|
1038
|
|
|
$modelpath = "core/modules/stocktransfer/doc/"; |
1039
|
|
|
|
1040
|
|
|
if ($includedocgeneration) { |
1041
|
|
|
$result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); |
1042
|
|
|
} |
1043
|
|
|
|
1044
|
|
|
return $result; |
1045
|
|
|
} |
1046
|
|
|
|
1047
|
|
|
/** |
1048
|
|
|
* Action executed by scheduler |
1049
|
|
|
* CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters' |
1050
|
|
|
* Use public function doScheduledJob($param1, $param2, ...) to get parameters |
1051
|
|
|
* |
1052
|
|
|
* @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK) |
1053
|
|
|
*/ |
1054
|
|
|
public function doScheduledJob() |
1055
|
|
|
{ |
1056
|
|
|
global $conf, $langs; |
1057
|
|
|
|
1058
|
|
|
//$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log'; |
1059
|
|
|
|
1060
|
|
|
$error = 0; |
1061
|
|
|
$this->output = ''; |
1062
|
|
|
$this->error = ''; |
1063
|
|
|
|
1064
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG); |
1065
|
|
|
|
1066
|
|
|
$now = dol_now(); |
1067
|
|
|
|
1068
|
|
|
$this->db->begin(); |
1069
|
|
|
|
1070
|
|
|
// ... |
1071
|
|
|
|
1072
|
|
|
$this->db->commit(); |
1073
|
|
|
|
1074
|
|
|
return $error; |
1075
|
|
|
} |
1076
|
|
|
} |
1077
|
|
|
|