Subversion Repositories public

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 andreas 1
<?
2
require_once('version.inc');
3
require_once('dbaccess.inc');
4
require_once('language.inc');
5
require_once('header.inc');
6
require_once('helper.inc');
7
require_once('crypt.inc');
8
require_once('settings.inc');
9
 
10
$knopf = 0;
11
$func = $_REQUEST['func'];
12
 
13
# Auswertungsmenue
14
if (isset($_REQUEST['ressource'])) { $knopf = 26; $headline = 30; }
15
 
16
$drm = array(true, false, false, false, false, true, false);
17
 
18
require_once('menu.inc');
19
require_once('knumber.inc');
20
 
21
# Folgende Funktion erlaubt die Auswahl einer Periode fuer die der Statusbericht
22
# erzeugt werden soll.
23
#
24
function Preselect() {
25
	global $periode;
26
	global $unum;
27
	global $menu;
28
	global $rstufe;
29
 
30
	$db = OpenDB();
31
?>
32
<form action="prtressource.php" method="post">
33
<input type="hidden" name="menu" value="<? echo "$menu"; ?>">
34
<input type="hidden" name="headline" value="30">
35
<input type="hidden" name="func" value="prplan">
36
 
37
<table border=0>
38
<?php
39
	# Auswahl eines Projekts
40
	echo "<tr><td>Projektauswahl:</td>\n";
41
	echo "<td>";
42
 
43
	$query = "select pl_num, pl_prnum, pl_lfd, pr_name from plan, project ";
44
	$query .= "where pr_num = pl_prnum and pl_status in (2,3,4) ";
45
	$query .= "order by pl_prnum, pl_lfd desc";
46
 
47
	$result = QueryDB($db, $query);
48
 
49
	if (!$result) {
50
	   closeDB($db);
51
	   return;
52
	}
53
 
54
	echo "<select name=\"pl_num\">\n";
55
	$numrows = numrowsDB($result);
56
	$rows = 0;
57
 
58
	while ($rows < $numrows) {
59
	   $data = fetchDB($result, $rows);
60
	   $pl_num = $data[0];
61
	   $pl_prnum = $data[1];
62
	   $pl_lfd = $data[2];
63
	   $pr_name = $data[3];
64
	   echo "<option value=\"$pl_num\">$pl_lfd: $pl_prnum $pr_name</option>\n";
65
	   $rows++;
66
	}
67
 
68
	echo "</select>";
69
	echo "</td></tr>\n";
70
	echo "</table>\n";
71
	echo "<br><input type=\"submit\" name=\"submit\" value=\"Senden\"> <input type=\"reset\">\n";
72
	echo "</form>\n";
73
	closeDB($db);
74
}
75
 
76
function CreateTempPlan($db, $pl_num, $prnum) {
77
	global $leneinheit;
78
 
79
	# Als erstes erzeugen wir eine temporaere Tabelle in die wir die
80
	# einzelnen Daten unseres Plans zusammentragen und korrekt zuordnen.
81
	#
82
	$query = "create local temporary table TempPlan (";
83
	$query .= "tmp_lfd integer not null unique, tmp_miname integer,";
84
	$query .= "tmp_phase integer, tmp_periode integer, tmp_plan double precision,";
85
	$query .= "tmp_ist double precision, tmp_taname varchar(50), tmp_notiz varchar(8192),";
86
	$query .= "constraint \"tempplan_pkey\" primary key (\"tmp_lfd\"))";
87
	$result = QueryDB($db, $query);
88
 
89
	if (!$result)
90
	   return false;
91
 
92
	# Nun erzeugen wir einen Plan, ausgehend von den Tasks. Das ist der
93
	# erste von insgesamt zwei Schritten!
94
	#
95
	$query = "select al_hours, al_pstart, al_phase, ta_name, ta_notiz,";
96
	$query .= "al_ressource from allocation, task where ";
97
	$query .= "ta_num = al_task and ta_plnum = $pl_num ";
98
	$query .= "and ta_meeting = 0";
99
	$result = QueryDB($db, $query);
100
 
101
	if (!$result)
102
	   return false;
103
 
104
	$numrows = numrowsDB($result);
105
 
106
	if ($numrows <= 0) {
107
	   Error("Der von Ihnen gew&auml;hlte Plan $pl_num enth&auml;lt keine Tasks!");
108
	   return false;
109
	}
110
 
111
	$rows = 0;
112
	$zaehler = 1;
113
 
114
	while ($rows < $numrows) {
115
	   $data = fetchDB($result, $rows);
116
	   $al_hours = $data[0];
117
	   $al_pstart = $data[1];
118
	   $al_phase = $data[2];
119
	   $ta_name = $data[3];
120
	   $ta_notiz = $data[4];
121
	   $al_ressource = $data[5];
122
 
123
	   $mon = gmdate("n", $al_pstart);
124
	   $year = gmdate("Y", $al_pstart);
125
	   $al_pstart = gmmktime(0, 0, 0, $mon, 1, $year);
126
 
127
	   $query = "insert into TempPlan (tmp_lfd, tmp_miname, tmp_phase,";
128
	   $query .= "tmp_periode, tmp_plan, tmp_ist, tmp_taname, tmp_notiz) ";
129
	   $query .= "values ($zaehler, $al_ressource, $al_phase, $al_pstart,";
130
	   $query .= "$al_hours, 0, '$ta_name', '$ta_notiz')";
131
 
132
	   if (!QueryDB($db, $query))
133
	      return false;
134
 
135
	   $rows++;
136
	   $zaehler++;
137
	}
138
 
139
	# Nun suchen wir alle IST-Meldungen und ergaenzen die Daten, sofern
140
	# sie bereits vorhanden sind, oder fuegen einen neuen Datensatz ein.
141
	#
142
	$query = "select wd_minum, wd_datum, wd_hours / $leneinheit, wd_phase, ";
143
	$query .= "ta_name from wdone, task where ";
144
	$query .= "wd_prnum = $prnum and ta_num = wd_task";
145
	$result = QueryDB($db, $query);
146
 
147
	if (!$result)
148
	   return false;
149
 
150
	$numrows = numrowsDB($result);
151
 
152
	if ($numrows <= 0) {
153
	   Error("Der von Ihnen gew&auml;hlte Plan $pl_num enth&auml;lt keine IST-Buchungen!");
154
	   return true;
155
	}
156
 
157
	$rows = 0;
158
 
159
	while ($rows < $numrows) {
160
	   $data = fetchDB($result, $rows);
161
	   $wd_minum = $data[0];
162
	   $wd_datum = $data[1];
163
	   $wd_ist = $data[2];
164
	   $wd_phase = $data[3];
165
	   $ta_name = $data[4];
166
 
167
	   $mon = gmdate("n", $wd_datum);
168
	   $year = gmdate("Y", $wd_datum);
169
	   $per = gmmktime(0, 0, 0, $mon, 1, $year);
170
	   $query = "select tmp_lfd, tmp_ist from TempPlan where ";
171
	   $query .= "tmp_miname = $wd_minum and tmp_periode =$per ";
172
	   $query .= "and tmp_taname = '$ta_name'";
173
	   $result2 = QueryDB($db, $query);
174
 
175
	   if (!$result2)
176
	      return false;
177
 
178
	   $nr = numrowsDB($result2);
179
 
180
	   if ($nr > 0) {
181
	      $data = fetchDB($result2, 0);
182
	      $tmp_lfd = $data[0];
183
	      $tmp_ist = $data[1];
184
 
185
	      $wd_ist += $tmp_ist;
186
 
187
	      $query = "update TempPlan set tmp_ist = $wd_ist ";
188
	      $query .= "where tmp_lfd = $tmp_lfd";
189
 
190
	      if (!QueryDB($db, $query))
191
	         return false;
192
	   } else {
193
	      $mon = gmdate("n", $wd_datum);
194
	      $year = gmdate("Y", $wd_datum);
195
	      $wd_datum = gmmktime(0, 0, 0, $mon, 1, $year);
196
 
197
	      $query = "insert into TempPlan (tmp_lfd, tmp_miname, tmp_phase,";
198
	      $query .= "tmp_periode, tmp_plan, tmp_ist, tmp_taname) ";
199
	      $query .= "values ($zaehler, $wd_minum, $wd_phase, $wd_datum,";
200
	      $query .= "0, $wd_ist, '$ta_name')";
201
 
202
	      if (!QueryDB($db, $query))
203
	         return false;
204
 
205
	      $zaehler++;
206
	   }
207
 
208
	   $rows++;
209
	}
210
 
211
	return true;
212
}
213
 
214
function PrintRessource($pl_num) {
215
	global $phase;
216
 
217
	$db = OpenDB();
218
	# Ermitteln der Projektnummer
219
	$query = "select pl_prnum from plan where pl_num = $pl_num";
220
	$result = QueryDB($db, $query);
221
 
222
	if (!$result) {
223
	   closeDB($db);
224
	   return;
225
	}
226
 
227
	$data = fetchDB($result, 0);
228
	$prnum = $data[0];
229
 
230
	# Folgende Funktion erzeugt uns einen Plan mit zugehoerigen IST-Werten,
231
	# wobei diese bereits innerhalb einer Periode aufsummiert wurden.
232
	#
233
	if (CreateTempPlan($db, $pl_num, $prnum) == false) {
234
	   closeDB($db);
235
	   return;
236
	}
237
 
238
	# Wieviele Perioden gibt es insgesamt?
239
	$query = "select count(distinct tmp_periode) from TempPlan";
240
	$result = QueryDB($db, $query);
241
 
242
	if (!$result) {
243
	   closeDB($db);
244
	   return;
245
	}
246
 
247
	$data = fetchDB($result, 0);
248
	$numper = $data[0];
249
	$np = $numper * 2;
250
 
251
	# Zeichnen des Tabellenkopfs
252
?>
253
<table border=1>
254
   <tr>
255
      <td colspan=2>&nbsp;</td>
256
      <td colspan=<? echo "$np"; ?> class="stbb">Periode</td>
257
      <td colspan=2 class="stbb">Summe</td>
258
      <td colspan=2 class="stbb">Total</td>
259
   </tr>
260
   <tr>
261
      <td rowspan=2 valign="top" class="stbb">Ressource</td>
262
<?php
263
	if ($phase)
264
           echo "<td rowspan=2 valign=\"top\" class=\"stbb\">Phase / Task</td>\n";
265
        else
266
           echo "<td rowspan=2 valign=\"top\" class=\"stbb\">Task</td>\n";
267
 
268
	$query = "select distinct tmp_periode from TempPlan order by tmp_periode";
269
	$result = QueryDB($db, $query);
270
 
271
	if (!$result) {
272
	   echo "</tr></table>";
273
	   closeDB($db);
274
	   return;
275
	}
276
 
277
	$numrows = numrowsDB($result);
278
	$r = 0;
279
 
280
	while ($r < $numrows) {
281
	   $data = fetchDB($result, $r);
282
	   $tmp_periode = $data[0];
283
 
284
	   $mon = gmdate("n", $tmp_periode);
285
	   $year = gmdate("Y", $tmp_periode);
286
 
287
	   if ($r == 0) {
288
	      $fmon = $mon;
289
	      $fyear = $year;
290
	   }
291
 
292
	   echo "      <td colspan=2 class=\"stbb\">$mon/$year</td>\n";
293
	   $sumperp[$r] = 0.0;
294
	   $sumperi[$r] = 0.0;
295
	   $r++;
296
	}
297
 
298
	$lmon = $mon;
299
	$lyear = $year;
300
	echo "      <td colspan=2>&nbsp;</td>\n";
301
	echo "      <td colspan=2>&nbsp;</td>\n";
302
	echo "   </tr>\n   <tr>\n";
303
	$r = 0;
304
 
305
	while ($r < $numrows) {
306
	   echo "      <td class=\"stbb\">Plan</td>\n";
307
	   echo "      <td class=\"stbb\">IST</td>\n";
308
	   $r++;
309
	}
310
 
311
	echo "      <td class=\"stbb\">Plan</td>\n";
312
	echo "      <td class=\"stbb\">IST</td>\n";
313
	echo "      <td class=\"stbb\">Plan</td>\n";
314
	echo "      <td class=\"stbb\">IST</td>\n   </tr>\n";
315
 
316
	# Nun fuellen wir die Tabelle mit Daten...
317
	#
318
	$query = "select tmp_miname, tmp_phase, tmp_periode, tmp_plan, tmp_ist, ";
319
	$query .= "tmp_taname, mi_nname, mi_vname from TempPlan, mitarbeiter ";
320
	$query .= "where mi_num = tmp_miname order by mi_nname, mi_vname, ";
321
	$query .= "tmp_phase, tmp_taname, tmp_periode";
322
	$result = QueryDB($db, $query);
323
 
324
	if (!$result) {
325
	   closeDB($db);
326
	   return;
327
	}
328
 
329
	$numrows = numrowsDB($result);
330
	$r = 0;
331
	$pz = 0;
332
	$first = true;
333
	$last = false;
334
	$sump = 0.0;
335
	$totp = 0.0;
336
	$sumptotal = 0.0;
337
	$sumi = 0.0;
338
	$toti = 0.0;
339
	$sumitotal = 0.0;
340
	$oldname = 0;
341
	$oldtaname = "";
342
	$oldphase = -1;
343
	$class = "nw";
344
	$ldate = gmmktime(0, 0, 0, $lmon, 1, $lyear);
345
	$adate = gmmktime(0, 0, 0, $fmon, 1, $fyear);
346
	$flag = 0;
347
 
348
	while ($r < $numrows) {
349
	   $data = fetchDB($result, $r);
350
	   $tmp_miname = $data[0];
351
	   $tmp_phase = $data[1];
352
	   $tmp_periode = $data[2];
353
	   $tmp_plan = $data[3];
354
	   $tmp_ist = $data[4];
355
	   $tmp_taname = $data[5];
356
	   $mi_nname = $data[6];
357
	   $mi_vname = $data[7];
358
 
359
	   $mon = gmdate("n", $tmp_periode);
360
	   $year = gmdate("Y", $tmp_periode);
361
 
362
	   if ($r == 0) {
363
	      $oldname = $tmp_miname;
364
	      $oldphase = $tmp_phase;
365
	      $oldtaname = $tmp_taname;
366
	   }
367
 
368
	   if ($oldphase != $tmp_phase || $oldname != $tmp_miname || $oldtaname != $tmp_taname) {
369
	      while ($adate <= $ldate) {
370
	         echo "<td class=\"$class\" align=\"right\">&nbsp;</td><td class=\"$class\" align=\"right\">&nbsp;</td>\n";
371
	         $aktmon++;
372
 
373
	         if ($aktmon > 12) {
374
	            $aktyear++;
375
	            $aktmon = 1;
376
	         }
377
 
378
	         $adate = gmmktime(0, 0, 0, $aktmon, 1, $aktyear);
379
 
380
	         if ($class == "nw")
381
	            $class = "nw1";
382
	         else
383
	            $class = "nw";
384
	      }
385
 
386
	      printf ("<td class=\"sum\" align=\"right\">%s</td>", FormatNum($sump, 3));
387
	      printf ("<td class=\"sum\" align=\"right\">%s</td>\n", FormatNum($sumi, 3));
388
	      echo "<td colspan=2>&nbsp;</td></tr>\n";
389
 
390
	      if ($oldname != $tmp_miname) {
391
		 echo "<tr><td colspan=2>&nbsp;</td>";
392
		 $pz = 0;
393
 
394
		 while ($pz < $numper) {
395
		    printf ("<td class=\"lsum\" align=\"right\">%s</td>", FormatNum($sumperp[$pz], 3));
396
		    printf ("<td class=\"lsum\" align=\"right\">%s</td>", FormatNum($sumperi[$pz], 3));
397
		    $sumperp[$pz] = 0.0;
398
		    $sumperi[$pz] = 0.0;
399
		    $pz++;
400
		 }
401
 
402
	         echo "<td colspan=2>&nbsp;</td>";
403
	         printf("<td class=\"lsum\" align=\"right\">%s</td>", FormatNum($totp, 3));
404
	         printf("<td class=\"lsum\" align=\"right\">%s</td></tr>\n", FormatNum($toti, 3));
405
	         $oldname = $tmp_miname;
406
	         $totp = 0.0;
407
	         $toti = 0.0;
408
	      }
409
 
410
	      $oldphase = $tmp_phase;
411
	      $oldtaname = $tmp_taname;
412
	      $sump = 0.0;
413
	      $sumi = 0.0;
414
	      $pz = 0;
415
	      $first = true;
416
	      $last = true;
417
	      $class = "nw";
418
	   }
419
 
420
	   if ($first) {
421
	      echo "<tr><td class=\"nw\">$mi_nname $mi_vname</td>\n";
422
 
423
	      if ($phase)
424
	         echo "<td class=\"nw\">$tmp_phase: $tmp_taname</td>\n";
425
	      else
426
	         echo "<td class=\"nw\">$tmp_taname</td>\n";
427
 
428
	      $aktmon = $fmon;
429
	      $aktyear = $fyear;
430
	      $adate = gmmktime(0, 0, 0, $aktmon, 1, $aktyear);
431
	      $first = false;
432
	      $class = "nw";
433
	      $pz = 0;
434
	   }
435
 
436
	   if ($mon != $aktmon || $year != $aktyear) {
437
	      while ($adate < $ldate && $adate != $tmp_periode) {
438
	         echo "<td class=\"$class\" align=\"right\">&nbsp;</td><td class=\"$class\" align=\"right\">&nbsp;</td>\n";
439
	         $aktmon++;
440
	         $pz++;
441
 
442
	         if ($aktmon > 12) {
443
	            $aktyear++;
444
	            $aktmon = 1;
445
	         }
446
 
447
	         $adate = gmmktime(0, 0, 0, $aktmon, 1, $aktyear);
448
 
449
	         if ($class == "nw")
450
	            $class = "nw1";
451
	         else
452
	            $class = "nw";
453
	      }
454
	   }
455
 
456
	   printf ("<td class=\"$class\" align=\"right\">%s</td>", FormatNum($tmp_plan, 3));
457
 
458
	   if (($tmp_plan - $tmp_ist) < 0) {
459
	      $class = "five";
460
 
461
	      if ($class == "nw")
462
	         $flag = 1;
463
	   }
464
 
465
	   printf ("<td class=\"$class\" align=\"right\">%s</td>\n", FormatNum($tmp_ist, 3));
466
	   $aktmon++;
467
 
468
	   if ($aktmon > 12) {
469
	      $aktmon = 1;
470
	      $aktyear++;
471
	   }
472
 
473
	   $adate = gmmktime(0, 0, 0, $aktmon, 1, $aktyear);
474
 
475
	   if ($flag)
476
	      $class = "nw";
477
 
478
	   if ($class == "nw")
479
	      $class = "nw1";
480
	   else
481
	      $class = "nw";
482
 
483
	   $sump += $tmp_plan;
484
	   $sumi += $tmp_ist;
485
	   $totp += $tmp_plan;
486
	   $toti += $tmp_ist;
487
	   $sumptotal += $tmp_plan;
488
	   $sumitotal += $tmp_ist;
489
	   $sumperp[$pz] += $tmp_plan;
490
	   $sumperi[$pz] += $tmp_ist;
491
	   $pz++;
492
	   $last = false;
493
	   $r++;
494
	}
495
 
496
	while ($adate <= $ldate) {
497
	   echo "<td class=\"$class\" align=\"right\">&nbsp;</td><td class=\"$class\" align=\"right\">&nbsp;</td>\n";
498
	   $aktmon++;
499
 
500
	   if ($aktmon > 12) {
501
	      $aktyear++;
502
	      $aktmon = 1;
503
	   }
504
 
505
	   $adate = gmmktime(0, 0, 0, $aktmon, 1, $aktyear);
506
 
507
	   if ($class == "nw")
508
	      $class = "nw1";
509
	   else
510
	      $class = "nw";
511
	}
512
 
513
	printf ("<td class=\"sum\" align=\"right\">%s</td>", FormatNum($sump, 3));
514
	printf ("<td class=\"sum\" align=\"right\">%s</td>\n", FormatNum($sumi, 3));
515
	echo "<td colspan=2>&nbsp;</td></tr>\n";
516
 
517
	echo "<tr><td colspan=2>&nbsp;</td>";
518
	$pz = 0;
519
 
520
	while ($pz < $numper) {
521
	   printf ("<td class=\"lsum\" align=\"right\">%s</td>", FormatNum($sumperp[$pz], 3));
522
	   printf ("<td class=\"lsum\" align=\"right\">%s</td>", FormatNum($sumperi[$pz], 3));
523
	   $pz++;
524
	}
525
 
526
	printf ("<td colspan=2>&nbsp;</td><td class=\"lsum\" align=\"right\">%s</td>", FormatNum($totp, 3));
527
	printf ("<td class=\"lsum\" align=\"right\">%s</td></tr>\n", FormatNum($toti, 3));
528
	$cs = 2 + $np + 2;
529
	printf ("<tr><td colspan=$cs>&nbsp;</td><td class=\"two\" align=\"right\">%s</td>", FormatNum($sumptotal, 3));
530
	printf ("<td class=\"two\" align=\"right\">%s</td></tr>\n", FormatNum($sumitotal, 3));
531
	echo "</table>\n";
532
	closeDB($db);
533
}
534
 
535
# Auswertung des Menues:
536
#
537
if ($knopf == 26)		// Ressourcenauslastung
538
   Preselect();
539
 
540
# Auswertung der Funktionen
541
if ($func == "prplan") {
542
   $pl_num = $_REQUEST['pl_num'];
543
 
544
   # Ermitteln des Projektnamens und Anzeigen des selben.
545
   $db = OpenDB();
546
   $query = "select pl_prnum, pr_name from plan, project ";
547
   $query .= "where pr_num = pl_prnum and pl_num = $pl_num";
548
   $result = QueryDB($db, $query);
549
   $data = fetchDB($result, 0);
550
   $selpro = $data[0];
551
   $pr_name = $data[1];
552
   echo "<p class=\"cry\">Projekt: $selpro $pr_name<br>\n";
553
   echo "Ressourcenauslastung der Mitarbeiter in PT</p>";
554
   echo "<br>\n";
555
   closeDB($db);
556
 
557
   echo "<a href=\"#\" onClick=\"javascript:open_mwindow('prtressource.php?pl_num=$pl_num&header=2&func=PrintPlan', 'Ressourcenauslastung: $selpro $pr_name', 750, 550)\">";
558
   echo "<img src=\"image/print.png\" border=0 alt=\"Drucken\"></a>\n";
559
 
560
   PrintRessource($pl_num);
561
}
562
 
563
if ($func == "PrintPlan") {
564
   $pl_num = $_REQUEST['pl_num'];
565
 
566
   # Ermitteln des Projektnamens und Anzeigen des selben.
567
   $db = OpenDB();
568
   $query = "select pl_prnum, pr_name from plan, project ";
569
   $query .= "where pr_num = pl_prnum and pl_num = $pl_num";
570
   $result = QueryDB($db, $query);
571
   $data = fetchDB($result, 0);
572
   $selpro = $data[0];
573
   $pr_name = $data[1];
574
   echo "<p class=\"cry\">Projekt: $selpro $pr_name<br>\n";
575
   echo "Ressourcenauslastung der Mitarbeiter in PT</p>";
576
   echo "<br>\n";
577
   closeDB($db);
578
 
579
   PrintRessource($pl_num);
580
}
581
 
582
require('footer.inc');
583
?>