-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathnomenclature-speed.php
353 lines (260 loc) · 11.6 KB
/
nomenclature-speed.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
<?php
require 'config.php';
dol_include_once('/nomenclature/class/nomenclature.class.php');
$langs->load('nomenclature@nomenclature');
$object_type = GETPOST('object', 'none');
$id = GETPOST('id', 'int');
if(GETPOST('save', 'alpha')=='ok') setEventMessage($langs->trans('Saved'));
if($object_type =='propal') {
dol_include_once('/comm/propal/class/propal.class.php');
$object = new Propal($db);
$object->fetch($id);
}
else if($object_type =='commande') {
dol_include_once('/commande/class/commande.class.php');
$object = new Commande($db);
$object->fetch($id);
}
else {
exit('? object type ?');
}
if(empty($object))exit;
$PDOdb=new TPDOdb;
$TProductAlreadyInPage=array();
// redirrection sur une vue global non modifiable
if( ($object->fk_statut>0 || $object->statut>0) && in_array($object_type, array('propal','commande')) ) {
$url = dol_buildpath('/nomenclature/nomenclature-detail.php' , 1).'?id='.$object->id.'&object='.$object_type;
header('Location: '.$url);
exit;
}
_drawlines($object, $object_type);
function _drawHeader($object, $object_type) {
global $db,$langs,$conf,$PDOdb;
if($object_type == 'propal') {
dol_include_once('/core/lib/propal.lib.php');
$head = propal_prepare_head($object);
dol_fiche_head($head, 'nomenclature', $langs->trans('Proposal'), 0, 'propal');
/*
* Propal synthese pour rappel
*/
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
print $object->ref;
print '</td></tr>';
// Ref client
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">';
print $langs->trans('RefCustomer').'</td><td align="left">';
print '</td>';
print '</tr></table>';
print '</td><td colspan="3">';
print $object->ref_client;
print '</td>';
print '</tr>';
print '</table>';
}
else if($object_type == 'commande') {
dol_include_once('/core/lib/order.lib.php');
$head = commande_prepare_head($object);
dol_fiche_head($head, 'nomenclature', $langs->trans('CustomerOrder'), 0, 'order');
/*
* Propal synthese pour rappel
*/
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
print $object->ref;
print '</td></tr>';
// Ref client
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">';
print $langs->trans('RefCustomer').'</td><td align="left">';
print '</td>';
print '</tr></table>';
print '</td><td colspan="3">';
print $object->ref_client;
print '</td>';
print '</tr>';
print '</table>';
}
if($object->fk_statut>0 || $object->statut>0) {
echo '<div class="error">'. $langs->trans('StatusOfObjectAvoidEdit') .'</div>';
llxFooter();
exit;
}
?><script type="text/javascript">
var fk_object=<?php echo $object->id; ?>;
var object_type="<?php echo $object_type; ?>";
var NOMENCLATURE_SPEED_CLICK_SELECT = <?php echo getDolGlobalInt('NOMENCLATURE_SPEED_CLICK_SELECT'); ?>;
function editLine(fk_line) {
url="<?php
if($object_type=='propal') echo dol_buildpath('/comm/propal/card.php?id='.$object->id,1);
else if($object_type=='commande')echo dol_buildpath('/commande/card.php?id='.$object->id,1);
?>&action=editline&lineid="+fk_line;
$('div#dialog-edit-line').remove();
$('body').append('<div id="dialog-edit-line"></div>');
$('div#dialog-edit-line').dialog({
title: "<?php echo $langs->trans('EditLine') ?>"
,width:"80%"
,modal:true
});
$.ajax({
url:url
}).done(function(data) {
$form = $(data).find('form#addproduct');
$form.find('input[name=cancel]').remove();
$form.find('tr[id]').not('#row-'+fk_line).remove();
$form.submit(function() {
if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" && CKEDITOR.instances['product_desc'] != "undefined") {
$form.find('textarea#product_desc').val(CKEDITOR.instances['product_desc'].getData());
}
$.post($(this).attr('action'), $(this).serialize()+'&save=1', function() {
});
$('div#dialog-edit-line').dialog('close');
return false;
});
$('div#dialog-edit-line').html($form);
});
}
</script><?php
}
function _drawlines(&$object, $object_type) {
global $db,$langs,$conf,$PDOdb,$TProductAlreadyInPage;
$newToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken'];
llxHeader('', 'Nomenclatures', '', '', 0, 0, array('/nomenclature/js/speed.js','/nomenclature/js/jquery-sortable-lists.min.js'), array('/nomenclature/css/speed.css'));
_drawHeader($object, $object_type);
$formDoli=new Form($db);
$formCore=new TFormCore;
echo '<div id="addto" style="float:right; width:200px;">';
if(getDolGlobalInt('NOMENCLATURE_ALLOW_JUST_MP')) {
print $formDoli->select_produits('', 'fk_product', '', 0,0,-1,0);
}
else{
print $formDoli->select_produits('', 'fk_product', '', 0,0,-1);
}
echo $formCore->bt($langs->trans('AddProductNomenclature'), 'AddProductNomenclature');
echo '<hr />';
echo $formCore->combo('', 'fk_new_workstation',TWorkstation::getWorstations($PDOdb, false, true), -1);
echo $formCore->bt($langs->trans('AddWorkstation'), 'AddWorkstation');
echo '<hr />';
echo $formCore->bt($langs->trans('SaveAll'), 'SaveAll');
echo '</div>';
echo '<ul id="speednomenclature" container-type="main" class="lines '.$object->element.'">';
foreach($object->lines as $k=>&$line) {
if($line->product_type == 9) {
$class="lineObject special";
$line_type="special";
}
else {
$class="lineObject";
$line_type="line";
}
echo '<li k="'.$k.'" class="'.$class.'" line-type="'.$line_type.'" object_type="'.$object->element.'" id="line-'.$line->id.'" fk_object="'.$line->id.'" fk_product="'.$line->fk_product.'">';
echo '<div>';
if($line->product_type == 0 || $line->product_type == 1) {
echo '<a href="javascript:editLine('.$line->id.');" class="editline clicable">'.img_edit($langs->trans('EditLine')).'</a>';
if(getDolGlobalInt('NOMENCLATURE_SPEED_CLICK_SELECT')) {
echo '<a style="float:right;" href="javascript:;" class="clickToSelect clicable">'.img_picto('Sélectionner cette ligne','object_opensurvey.png',' class="clicable"').'</a>';
}
}
$label = !empty($line->label) ? $line->label : (empty($line->libelle) ? $line->desc : $line->libelle);
if($line->fk_product>0) {
$product = new Product($db);
$product->fetch($line->fk_product);
echo '<div class="label">'.$product->getNomUrl(1).' '.$product->label.'</div>';
}
else if($line->product_type == 9 ) {
/* ligne titre */
if($line->qty>=90) {
echo '<div class="total label">'.(100-$line->qty).'. '.$label.'</div>';
// var_dump($line);exit;
}
else {
echo '<div class="title label">'.$line->qty.'. '.$label.'</div>';
}
}
else {
/* ligne libre */
echo '<div class="free label">'.$label.'</div>';
}
if($line->product_type == 0 || $line->product_type == 1) echo '<div class="qty"><input rel="qty" value="'.$line->qty.'" class="flat qty clicable" size="5" /></div>';
echo '</div>';
if($line->product_type == 0 || $line->product_type == 1) _drawnomenclature($line->id, $object->element,$line->fk_product,$line->qty);
echo '</li>';
}
echo '</ul>';
?>
<div class="logme"></div>
<div style="text-align: left;">
<div class="inline-block divButAction"><a href="nomenclature-detail.php?id=<?php echo GETPOST('id', 'int') ?>&object=<?php echo GETPOST('object', 'none') ?>&token=<?php echo $newToken; ?>" class="butAction">Liste produits et MO nécessaires</a></div>
</div>
<?php
dol_fiche_end();
llxFooter();
}
function _drawnomenclature($fk_object, $object_type,$fk_product,$qty, $level = 1) {
global $db,$langs,$conf,$PDOdb,$TProductAlreadyInPage;
$max_nested_aff_level = getDolGlobalInt('NOMENCLATURE_MAX_NESTED_AFF_LEVEL',7 );
if($level > $max_nested_aff_level) {
echo '<div class="error">'.$langs->trans('ThereIsTooLevelHere').'</div>';
return false;
}
$nomenclature=new TNomenclature;
$nomenclature->loadByObjectId($PDOdb, $fk_object, $object_type, true,$fk_product,$qty);
/*if($fk_object == 811) {
echo 1;
var_dump( $object_type,$fk_product,$qty , $nomenclature->TNomenclatureAll);
}*/
if(!empty($TProductAlreadyInPage[$fk_object.'_'. $object_type])) {
echo '<ul class="lines nomenclature" container-type="nomenclature" fk_nomenclature="'.$nomenclature->getId().'">';
echo '<li class="nomenclature clicable" no-hierarchie-parse="1" id="nomenclature-nouse-'.$nomenclature->getId().'-'.$fk_product.'">Nomenclature déjà affichée <a href="#" onclick="window.scrollTo(0, $(\'li[fk_object='.$fk_product.'][object_type=product]\').first().offset().top ); ">ici</a></li>';
echo '</ul>';
}
else if(!empty($nomenclature->TNomenclatureAll)) {
$TProductAlreadyInPage[$fk_object.'_'. $object_type] = 1;
if($nomenclature->iExist) {
echo '<ul class="lines nomenclature" container-type="nomenclature" fk_nomenclature="'.$nomenclature->getId().'">';
}
else {
echo '<ul class="lines notanomenclature" container-type="nomenclature" fk_nomenclature="0" fk_original_nomenclature="'.$nomenclature->fk_nomenclature_parent.'">';
echo '<div>'.$langs->trans('PseudoNomenclature') .img_help('',$langs->trans('PseudoNomenclatureInfo') ).'</div>';
}
foreach($nomenclature->TNomenclatureAll as $k=>&$line) {
if(get_class($line) === 'TNomenclatureDet' ) {
$product = new Product($db);
if($line->fk_product>0 && $product->fetch($line->fk_product)>0) {
$id = $line->getId() > 0 ? $line->getId() : $nomenclature->fk_nomenclature_parent.'-'.$k;
echo '<li class="nomenclature" k="'.$k.'" line-type="nomenclature" id="nomenclature-product-'.$id.'" object_type="product" fk_object="'.$line->fk_product.'">';
echo '<div class="clicable" rel="delete">'.img_delete('',' class="clicable"').'</div>';
if(getDolGlobalInt('NOMENCLATURE_SPEED_CLICK_SELECT')) {
echo '<a style="float:right;" href="javascript:;" class="clickToSelect clicable">'.img_picto('Sélectionner cette ligne','object_opensurvey.png',' class="clicable"').'</a>';
}
echo '<div>';
echo '<div class="label">'.($line->unifyRang+1).'. '. $product->getNomUrl(1).' '.$product->label.'</div>';
echo '<div class="qty"><input rel="qty" value="'.$line->qty.'" class="flat qty clicable" size="5" />';
if($qty > 1) echo ' (x '.$qty.')';
echo '</div>';
echo '</div>';
_drawnomenclature($product->id, 'product',$product->id,$line->qty * $qty,$level+1);
echo '</li>';
}
}
else {
echo '<li class="nomenclature workstation" line-type="workstation" k="'.$k.'" object_type="workstation" id="nomenclature-ws-'.$line->getId().'" fk_object="'.$line->workstation->getId().'">';
echo '<div class="clicable" rel="delete">'.img_delete('',' class="clicable"').'</div>';
echo '<div>';
echo '<div class="label">'.($line->unifyRang+1).'. '.$line->workstation->name.'</div>';
echo '<div class="qtyws" >
<input rel="nb_hour_prepare" value="'.$line->nb_hour_prepare.'" class="flat qty clicable" size="5" title="Heure(s) de préparation" />
<input rel="nb_hour_manufacture" value="'.$line->nb_hour_manufacture.'" class="flat qty clicable" size="5" title="Heure(s) de fabrication" />';
if($qty > 1) echo ' (x '.$qty.')';
echo '</div>
</div>';
echo '</li>';
}
}
echo '</ul>';
}
return true;
}