-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathlist.php
429 lines (313 loc) · 12.2 KB
/
list.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<?php
/* Copyright (C) 2014 Alexis Algoud <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file /nomenclature/tab_project_feedback.php
* \ingroup projet
* \brief Project feedback
*/
require 'config.php';
dol_include_once('/nomenclature/class/nomenclature.class.php');
$type_object = 'product';
// GET POST
$action=GETPOST('action','alpha');
// Load translation files required by the page
$langs->loadLangs(array('products', 'nomenclature@nomenclature'));
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('nomenclatureList','globallist'));
$PDOdb = new TPDOdb;
// LIST ELEMENTS
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$page = (GETPOST("page",'int')?GETPOST("page", 'int'):0);
$type = (GETPOST("type",'alpha')?GETPOST("type", 'alpha'):0);
//Massaction
$massaction = GETPOST('massaction', 'alpha');
$confirmmassaction = GETPOST('confirm', 'alpha');
$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
$arrayofselected = is_array($toselect) ? $toselect : array();
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortfield) $sortfield="n.title";
if (! $sortorder) $sortorder="ASC";
/*
* Actions
*/
$parameters=array();
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook))
{
}
/*
* View
*/
$title = $langs->trans('Nomenclatures');
$arrayofjs = array('/core/js/listview.js');
llxHeader('', $title, '', '', 0, 0, $arrayofjs);
$shownav = 1;
if ($user->societe_id && ! in_array('nomenclature', explode(',',getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) $shownav=0;
// CONFIGURATION DU LISTVIEW
$list = new Listview($db,'nomenclature-list');
$TParam= array();
$TParam['list'] = array(
'title'=>$langs->trans('NomenclatureList'),
);
$TParam['limit'] = array(
'page'=>(isset($_REQUEST['page']) ? $_REQUEST['page'] : 0),
'nbLine'=>$limit
);
$TParam['list'] = array(
'param_url' => 'limit=' . $limit,
'massactions' => array('maj_pmp_massaction' => $langs->trans('MajPmpWithBomPriceLabel')),
'selected' => $arrayofselected
);
$TParam['title'] = array(
//'object_type' => $langs->trans('ObjectType'),
'ref' => $langs->trans('ProductRef'),
'title' => $langs->trans('NomenclatureName'),
'is_default' => $langs->trans('is_default'),
'qty_reference' => $langs->trans('nomenclatureQtyReference'),
'pmp' => $langs->trans('PMP'),
'SellPrice' => $langs->trans('PriceConseil'),
//'totalPRCMO_PMP' => $langs->trans('TotalAmountCostWithChargePMPQty'),
'totalPRCMO_OF' => $langs->trans('TotalAmountCostWithChargeOFQty'),
//'totalPRCMO' => $langs->trans('Total'),
'date_cre' => $langs->trans('CreateOn'),
'date_maj' => $langs->trans('Updated'),
);
$TParam['hide'] = array('is_default');
// defined list align for field
$TParam['position'] = array(
'text-align'=> array(
'ref' => 'left',
'title' => 'left',
'is_default' => 'center',
'qty_reference' => 'right',
'pmp' => 'right',
'SellPrice' => 'right',
'totalPRCMO_PMP' => 'right',
'totalPRCMO_OF' => 'right',
'totalPRCMO' => 'right',
'date_cre' => 'center',
'date_maj' => 'center',
)
);
$TParam['allow-fields-select'] = 1 ;// allow to select hidden fields
$TParam['sortfield'] = 'title';
$TParam['sortorder'] = 'ASC';
$TParam['type'] = array (
'date_cre' => 'date', // [datetime], [hour], [money], [number], [integer]
'date_maj' => 'datetime',
'qty_reference' => 'number',
'pmp' => 'money',
'totalPRCMO_PMP' => 'money',
'totalPRCMO_OF' => 'money',
'totalPRCMO' => 'money',
);
$TParam['search'] = array (
'object_type' => array('search_type'=> _objectTypeList(), 'table'=>'n', 'fieldname'=>'object_type' ),
'title' => array('search_type'=>true, 'table'=>'n', 'fieldname'=>'title'),
'ref' => array('search_type'=>true, 'table'=>'p', 'fieldname'=>'ref'),
'is_default' => array('search_type'=>array(0=>$langs->trans('No'), 1=>$langs->trans('Yes') )),
'qty_reference' => array('search_type'=>true, 'table'=>'n', 'fieldname'=>'qty_reference'),
'pmp' => array('search_type'=>true, 'table'=>'p', 'fieldname'=>'pmp'),
'totalPRCMO_PMP' => array('search_type'=>true, 'table'=>'n', 'fieldname'=>'totalPRCMO_PMP'),
'totalPRCMO_OF' => array('search_type'=>true, 'table'=>'n', 'fieldname'=>'totalPRCMO_OF'),
//'totalPRCMO' => array('search_type'=>true, 'table'=>'n', 'fieldname'=>'totalPRCMO'),
'date_cre' => array('search_type'=>true, 'table'=>'n', 'fieldname'=>'date_cre'),
'date_maj' => array('search_type'=>true, 'table'=>'n', 'fieldname'=>'date_maj'),
);
$TParam['operator'] = array(
'pmp' => '= '.round(floatval('nomenclature_getPMP(@rowid@)'), 2, PHP_ROUND_HALF_UP)
);
$TParam['eval'] = array(
// array of customized field function
'title'=>'linkToNomenclature(\'@val@\', @rowid@, \'@object_type@\', \'@fk_object@\')',
'ref'=>'linkToNomenclature(\'@val@\', @rowid@, \'@object_type@\', \'@fk_object@\')',
'is_default' => '_yesNo(\'@is_default@\')',
// prix d'achat total
//'BuyPrice' => 'nomenclature_getBuyPrice(@rowid@)',
'PMP' => 'nomenclature_getPMP(@rowid@)',
// prix de vente conseillé total
'SellPrice' => 'nomenclature_getSellPrice(@rowid@)',
// Prix de revient chargé (on affiche tjr le chargé)
'totalPRCMO' => 'nomenclature_totalPRCMO(@rowid@)',
// Coût de revient chargé théorique pour %s exemplaire(s)
'totalPRCMO_PMP' => 'nomenclature_totalPRCMO_PMP(@rowid@)',
// TotalAmountCostWithChargeOF=Coût de revient chargé réel pour %s exemplaire(s)
'totalPRCMO_OF' => 'nomenclature_totalPRCMO(@rowid@)',//'nomenclature_totalPRCMO_OF(@rowid@)',
);
// Query MYSQL
$sql = "SELECT p.ref, n.rowid, n.is_default, n.title, n.date_maj, n.date_cre, n.fk_object, n.object_type, n.totalPRCMO_PMP, n.totalPRCMO_OF, n.totalPRCMO, n.qty_reference, p.pmp";
$sql.= " FROM `" . MAIN_DB_PREFIX . "nomenclature` n ";
$sql.= " JOIN `" . MAIN_DB_PREFIX . "product` p ON (p.rowid = n.fk_object) ";
$sql.= " WHERE n.object_type = 'product' AND n.fk_nomenclature_parent = 0 ";
// le formulaire
print '<div class="fichecenter" >';
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="type" value="'.$type.'">';
if ($massaction == 'maj_pmp_massaction') {
$form = new Form($db);
print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMajPmp"), $langs->trans("ConfirmMajPmpQuestion"), "confirm_maj_pmp_massaction", null, 'yes', 0, 200, 500, 1);
}
if($action == 'confirm_maj_pmp_massaction' && $confirmmassaction == "yes"){
//On parcourt la liste des nomenclatures selectionnées
foreach ($arrayofselected as $nom_id){
$nom = new TNomenclature();
$res = $nom->load($PDOdb, $nom_id);
if($res){
$nom->updateProductPMPByNomPrice();
}
}
}elseif ($confirmmassaction != 'yes' && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
print $list->render($sql, $TParam);
print '</form>';
print '</div>';
llxFooter();
$db->close();
/*
* LIB DE FACTORISATION
*/
function _objectTypeList(){
global $db;
$sql = "SELECT DISTINCT object_type FROM `" . MAIN_DB_PREFIX . "nomenclature`";
$TResult = array();
$res = $db->query($sql);
if ($res)
{
while ($obj = $db->fetch_object($res))
{
$TResult[$obj->object_type] = $obj->object_type;
}
return $TResult;
}
else { dol_print_error($db); }
return $TResult;
}
function linkToNomenclature($label = '',$nomenclature_id = '', $object_type = '', $object_id = '' ){
if(empty($object_type)) return $label;
$newToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken'];
if($object_type == 'product'){
$url = dol_buildpath('nomenclature/nomenclature.php',1).'?fk_nomenclature='.intval($nomenclature_id ).'&fk_product='.intval($object_id).'#nomenclature'.intval($nomenclature_id );
}
else {
$url = dol_buildpath('nomenclature/nomenclature-detail.php',1).'?id='.intval($object_id).'&object='.$object_type.'&token='.$newToken;
}
return '<a href="'.$url.'" target="_self" >'.(empty($label)?'N/A':$label).'</label>';
}
function _yesNo($id=0){
global $langs;
$array = array(0=>$langs->trans('No'), 1=>$langs->trans('Yes') );
if(!empty($array[$id])) return $array[$id];
return $array[0];
}
function nomenclature_cache($id=0, $usecache=1){
global $PDOdb, $n_cache;
if(!empty($id) ){
if($usecache && !empty($n_cache[$id])){
return $n_cache[$id];
}
$n=new TNomenclature ;
if($n->load($PDOdb, $id)){
$n->setPrice($PDOdb,$n->qty_reference, $n->fk_object, $n->object_type);
$n_cache[$id]=$n;
return $n;
}
else{
return 0;
}
}
else{
return 0;
}
}
// prix d'achat total
function nomenclature_getBuyPrice($id=0){
$n = nomenclature_cache($id);
if(!empty($n)){
return price($n->getBuyPrice());
}
return '--';
}
// prix de vente conseillé total
function nomenclature_getSellPrice($id=0){
$n = nomenclature_cache($id);
if(!empty($n)){
return price($n->getSellPrice());
}
return '--';
}
/**
* To get the PMP of a product by giving its nomenclature
* @param int $id
* @return string
*/
function nomenclature_getPMP($id=0){
global $db;
$sql = 'SELECT pmp FROM '.MAIN_DB_PREFIX.'product p';
$sql.= ' JOIN '.MAIN_DB_PREFIX.'nomenclature n ON p.rowid = n.fk_object';
$sql.= ' WHERE n.rowid='.$id;
$resql = $db->query($sql);
if($resql){
$obj = $db->fetch_object($resql);
return $obj->pmp;
}
return '--';
}
// Prix de revient chargé (on affiche tjr le chargé)
function nomenclature_totalPRCMO($id=0){
$n = nomenclature_cache($id);
if(!empty($n)){
return price(price2num($n->totalPRCMO,'MT'));
}
return '--';
}
// Prix de revient chargé
function nomenclature_totalPR($id=0){
$n = nomenclature_cache($id);
if(!empty($n)){
return price(price2num($n->totalPR,'MT'));
}
return '--';
}
// TotalAmountCostWithChargePMP=Coût de revient chargé théorique pour %s exemplaire(s)
function nomenclature_totalPRCMO_PMP($id=0){
$n = nomenclature_cache($id);
if(!empty($n)){
return price(price2num($n->totalPRCMO_PMP,'MT'));
}
return '--';
}
// TotalAmountCostWithChargeOF=Coût de revient chargé réel pour %s exemplaire(s)
function nomenclature_totalPRCMO_OF($id=0){
$n = nomenclature_cache($id);
if(!empty($n)){
return price(price2num($n->totalPRCMO_OF,'MT'));
}
return '--';
}