Subversion Repositories public

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 andreas 1
<?
2
function SelectTemp($db, $prnum) {
3
	$query = "select tmp_lfd, tmp_miname, tmp_periode, tmp_plan, ";
4
	$query .= "tmp_ist, tmp_taname, tmp_status, tmp_hash, tmp_plnum ";
5
	$query .= "from TempPlan order by tmp_periode";
6
 
7
	if (!($result = QueryDB($db, $query)))
8
	   return;
9
 
10
	$anz = numrowsDB($result);
11
	$i = 0;
12
	$dbstr = "\nLFD.   Ma.    Periode   Plan   IST   PlNr. St. PrNr. Hashwert\n";
13
	//          1234567890123456789012345678901234567890123456789
14
	//          xxxxx_xxxxx_xx.xx.xxxx_xx,xxx_xx,xxx_xxxxx_xx_xxxxxx
15
 
16
	while ($i < $anz) {
17
	   $data = fetchDB($result, $i);
18
	   $tmp_lfd = $data[0];
19
	   $tmp_miname = $data[1];
20
	   $tmp_periode = $data[2];
21
	   $tmp_plan = $data[3];
22
	   $tmp_ist = $data[4];
23
	   $tmp_taname = $data[5];
24
	   $tmp_status = $data[6];
25
	   $tmp_hash = $data[7];
26
	   $tmp_plnum = $data[8];
27
 
28
	   $ss = sprintf("%5d %5d %02d.%02d.%4d %6s %6s %5d %2d %6d %s\n", $tmp_lfd,
29
	   		$tmp_miname, gmdate("j", $tmp_periode), gmdate("n", $tmp_periode),
30
	   		gmdate("Y", $tmp_periode), FormatNum($tmp_plan, 3), FormatNum($tmp_ist, 3),
31
	   		$tmp_plnum, $tmp_status, $prnum, $tmp_hash);
32
	   $dbstr .= $ss;
33
	   $i++;
34
	}
35
 
36
	if ($anz > 0)
37
	   DEBUG($dbstr);
38
}
39
 
40
function CreateTempPlan($db, $pl_num, $prnum, $dfrom, $dto, $quiet=false, $minum=0, $ta=false, $ph=false) {
41
	global $leneinheit;
42
	global $phase;
43
	$mi_num = $_REQUEST['mi_num'];
44
	$f_tasks = $_REQUEST['fields_0'];
45
	$pjclosed = $_REQUEST['pjclosed'];
46
 
47
	if ($phase)
48
	   $f_phase = $_REQUEST['fields_6'];
49
 
50
	if ((!isset($mi_num) || $mi_num == 0) && $minum > 0)
51
	   $mi_num = $minum;
52
 
53
	if ($ta == true)
54
	   $f_tasks = $ta;
55
 
56
	if ($ph == true)
57
	   $f_phase = $pa;
58
 
59
	if (isset($pjclosed) && CheckTrue($pjclosed))
60
	   $pjc = ",6";
61
 
62
	# Als erstes erzeugen wir eine temporaere Tabelle in die wir die
63
	# einzelnen Daten unseres Plans zusammentragen und korrekt zuordnen.
64
	#
65
	$query = "create local temporary table TempPlan (";
66
	$query .= "tmp_lfd integer not null unique, tmp_miname integer,";
67
	$query .= "tmp_phase integer, tmp_periode integer, tmp_plan double precision,";
68
	$query .= "tmp_ist double precision, tmp_taname varchar(50), tmp_notiz varchar(8192),";
69
	$query .= "tmp_status smallint, tmp_hash char(34), tmp_plnum integer, ";
70
	$query .= "tmp_start integer, tmp_duration smallint, ";
71
	$query .= "constraint \"tempplan_pkey\" primary key (\"tmp_lfd\"))";
72
	$result = QueryDB($db, $query);
73
 
74
	if (!$result)
75
	   return false;
76
 
77
	# Ermitteln ob es sich um ein Projekt oder um ein Konto handelt.
78
	$query = "select pr_status from project where pr_num = $prnum";
79
 
80
	if (!($result = QueryDB($db, $query)))
81
	   return false;
82
 
83
	$data = fetchDB($result, 0);
84
	$pr_status = $data[0];
85
 
86
	# Nun erzeugen wir einen Plan, ausgehend von den Tasks. Das ist der
87
	# erste von insgesamt zwei Schritten!
88
	# Hier muessen wir zwischen einem Projekt und einem Konto
89
	# unterscheiden. Konten haben keine Zuordnungen zu einem Task!
90
	#
91
	if ($pr_status == 0) {		// 0 = Projekt!
92
	   $query = "select al_hours, al_pstart";
93
 
94
	   if ($phase && $f_phase)
95
	      $query .= ", al_phase ";
96
 
97
	   if ($f_tasks)
98
	      $query .= ", ta_name ";
99
 
100
	   $query .= ", ta_notiz, al_ressource, ta_hash, ta_plnum, pl_status, ";
101
	   $query .= "ta_start, ta_duration ";
102
	   $query .= "from allocation, task, plan where ";
103
//	   $query .= "pl_num = ta_plnum and pl_prnum = $prnum and ";
104
	   $query .= "pl_num = ta_plnum and pl_num = $pl_num and ";
105
//	   $query .= "ta_num = al_task and ta_plnum = $pl_num and ";
106
	   $query .= "ta_num = al_task and pl_status in (2,3,4,5 $pjc) and ";
107
	   $query .= "ta_meeting = 0 and al_pstart between $dfrom and $dto ";
108
 
109
	   if (isset($mi_num) && $mi_num > 0)
110
	      $query .= "and al_ressource = $mi_num ";
111
	} else {
112
	   $query = "select distinct on (wd_minum) ta_num, ta_name,wd_minum,";
113
	   $query .= "ta_hash, ta_plnum, ta_start, ta_duration from wdone, task ";
114
	   $query .= "where ta_plnum = $pl_num and wd_task = ta_num ";
115
 
116
	   if (isset($mi_num) && $mi_num > 0)
117
	      $query .= "and wd_minum = $mi_num ";
118
	}
119
 
120
	if (!($result = QueryDB($db, $query)))
121
	   return false;
122
 
123
	$numrows = numrowsDB($result);
124
 
125
	if ($numrows <= 0) {
126
	   if (!$quiet)
127
	      Error("Das Projekt $prnum enth&auml;lt f&uuml;r den Zeitraum vom " . gmdate("n.Y", $dfrom) . " bis " . gmdate("n.Y", $dto) . " einen Plan ohne Tasks ($mi_num)!");
128
	}
129
 
130
	$rows = 0;
131
	$zaehler = 1;
132
 
133
	while ($rows < $numrows) {
134
	   $data = fetchDB($result, $rows);
135
 
136
	   if ($pr_status == 0) {
137
	      $al_hours = $data[0];
138
	      $al_pstart = $data[1];
139
	      $x = 2;
140
 
141
	      if ($phase && $f_phase) {
142
		 $al_phase = $data[$x];
143
		 $x++;
144
	      } else
145
		 $al_phase = 0;
146
 
147
	      if ($f_tasks) {
148
	         $ta_name = $data[$x];
149
		 $x++;
150
	      } else
151
	         $ta_name = "";
152
 
153
	      $ta_notiz = $data[$x];
154
	      $x++;
155
	      $al_ressource = $data[$x];
156
	      $x++;
157
	      $ta_hash = $data[$x];
158
	      $x++;
159
	      $ta_plnum = $data[$x];
160
	      $x++;
161
	      $pl_status = $data[$x];
162
	      $x++;
163
	      $ta_start = $data[$x];
164
	      $x++;
165
	      $ta_duration = $data[$x];
166
	   } else {
167
	      $al_hours = 0;
168
	      $al_pstart = $dfrom;
169
	      $ta_num = $data[0];
170
	      $al_phase = 0;
171
 
172
	      if ($f_tasks)
173
	         $ta_name = $data[1];
174
	      else
175
	         $ta_name = "";
176
 
177
	      $al_ressource = $data[2];
178
	      $ta_notiz = "";
179
	      $ta_hash = $data[3];
180
	      $ta_plnum = $data[4];
181
	      $ta_start = $data[5];
182
	      $ta_duration = $data[6];
183
	      $pl_status = 0;
184
	   }
185
 
186
	   $mon = gmdate("n", $al_pstart);
187
	   $year = gmdate("Y", $al_pstart);
188
	   $al_pstart = gmmktime(0, 0, 0, $mon, 1, $year);
189
	   $flag = false;
190
 
191
	   $query = "select tmp_lfd, tmp_plan, tmp_plnum, tmp_hash, tmp_taname from TempPlan where ";
192
	   $query .= "tmp_periode = $al_pstart and tmp_phase = $al_phase ";
193
	   $query .= "and tmp_miname = $al_ressource ";
194
 
195
	   if ($f_tasks)
196
	      $query .= "and tmp_hash = '$ta_hash' ";
197
//	      $query .= "and (tmp_hash = '$ta_hash' or tmp_taname = '$ta_name') ";
198
 
199
	   if (!($res = QueryDB($db, $query)))
200
	      return false;
201
 
202
	   if (numrowsDB($res) > 0) {
203
	      $data = fetchDB($res, 0);
204
	      $tmp_lfd = $data[0];
205
	      $tmp_plan = $data[1];
206
	      $tmp_plnum = $data[2];
207
	      $tmp_hash = $data[3];
208
	      $tmp_taname = $data[4];
209
 
210
	      if ($tmp_plnum < $ta_plnum && ($tmp_hash == $ta_hash || ($tmp_taname == $ta_name && $f_tasks))) {
211
	         $tmp_plan = $al_hours;
212
		 $tmp_plnum = $ta_plnum;
213
		 $tmp_hash = $ta_hash;
214
	      } else if (!$f_tasks)
215
		 $tmp_plan += $al_hours;
216
 
217
	      $query = "update TempPlan set tmp_plan = $tmp_plan, tmp_plnum = $tmp_plnum, tmp_hash = '$tmp_hash' ";
218
	      $query .= "where tmp_lfd = $tmp_lfd";
219
 
220
	      if (!QueryDB($db, $query))
221
	         return false;
222
	   } else
223
	      $flag = true;
224
 
225
	   if ($flag) {
226
	      $ta_name = addslashes($ta_name);
227
	      $ta_notiz = addslashes($ta_notiz);
228
	      $query = "insert into TempPlan (tmp_lfd, tmp_miname, tmp_phase,";
229
	      $query .= "tmp_periode, tmp_plan, tmp_ist,tmp_taname,tmp_notiz,";
230
	      $query .= "tmp_status, tmp_hash, tmp_plnum, tmp_start, tmp_duration) ";
231
	      $query .= "values ($zaehler, $al_ressource, $al_phase, $al_pstart,";
232
	      $query .= "$al_hours, 0, '$ta_name', '$ta_notiz', $pr_status,";
233
	      $query .= "'$ta_hash', $ta_plnum, $ta_start, $ta_duration)";
234
 
235
	      if (!QueryDB($db, $query))
236
	         return false;
237
 
238
	      $zaehler++;
239
	   }
240
 
241
	   $rows++;
242
	}
243
 
244
	# Nun suchen wir alle IST-Meldungen und ergaenzen die Daten, sofern
245
	# sie bereits vorhanden sind, oder fuegen einen neuen Datensatz ein.
246
	#
247
	$query = "select wd_minum, wd_datum, wd_hours / $leneinheit,";
248
	$query .= "ta_hash, ta_plnum, ta_start, ta_duration, wd_task ";
249
 
250
	if ($phase && $f_phase)
251
	   $query .= ", wd_phase ";
252
 
253
	if ($f_tasks)
254
	   $query .= ", ta_name ";
255
 
256
	$query .= "from wdone, task where ";
257
	$query .= "wd_prnum = $prnum and ta_num = wd_task and ";
258
	$query .= "wd_datum between $dfrom and $dto ";
259
 
260
	if (isset($mi_num) && $mi_num > 0)
261
	   $query .= "and wd_minum = $mi_num ";
262
 
263
	if (!($result = QueryDB($db, $query)))
264
	   return false;
265
 
266
	$numrows = numrowsDB($result);
267
 
268
	if ($numrows <= 0) {
269
	   if (!$quiet)
270
	       Error("Zum Projekt $prnum gibt es f&uuml;r den Zeitraum vom " . gmdate("n.Y", $dfrom) . " bis " . gmdate("n.Y", $dto) . " keine IST-Buchungen ($mi_num)!");
271
 
272
	   return true;
273
	}
274
 
275
	$rows = 0;
276
 
277
	while ($rows < $numrows) {
278
	   $data = fetchDB($result, $rows);
279
	   $wd_minum = $data[0];
280
	   $wd_datum = $data[1];
281
	   $wd_ist = $data[2];
282
	   $ta_hash = $data[3];
283
	   $ta_plnum = $data[4];
284
	   $ta_start = $data[5];
285
	   $ta_duration = $data[6];
286
	   $wd_task = $data[7];
287
	   $x = 8;
288
 
289
	   if ($phase && $f_phase) {
290
	      $wd_phase = $data[$x];
291
	      $x++;
292
	   } else
293
	      $wd_phase = 0;
294
 
295
	   if ($f_tasks) {
296
	      $ta_name = $data[$x];
297
	      $x++;
298
	   } else
299
	      $ta_name = "";
300
 
301
	   $mon = gmdate("n", $wd_datum);
302
	   $year = gmdate("Y", $wd_datum);
303
	   $per = gmmktime(0, 0, 0, $mon, 1, $year);
304
	   $slash_name = addslashes($ta_name);
305
	   $query = "select tmp_lfd, tmp_ist, tmp_plan, tmp_plnum, tmp_hash ";
306
	   $query .= "from TempPlan where ";
307
	   $query .= "tmp_miname = $wd_minum and tmp_periode =$per ";
308
 
309
	   if ($f_tasks)
310
	      $query .= "and (tmp_hash = '$ta_hash' or tmp_taname = '$slash_name')";
311
 
312
	   if ($f_phase)
313
	      $query .= " and tmp_phase = $wd_phase";
314
 
315
	   $result2 = QueryDB($db, $query);
316
 
317
	   if (!$result2)
318
	      return false;
319
 
320
	   $nr = numrowsDB($result2);
321
 
322
	   if ($nr > 0) {
323
	      $data = fetchDB($result2, 0);
324
	      $tmp_lfd = $data[0];
325
	      $tmp_ist = $data[1];
326
	      $tmp_plan = $data[2];
327
	      $tmp_plnum = $data[3];
328
	      $tmp_hash = $data[4];
329
	      $ist_alt = $wd_ist;
330
	      $wd_ist += $tmp_ist;
331
	      $query = "update TempPlan set tmp_ist = $wd_ist ";
332
 
333
	      # Handelt es sich um einen unterschiedlichen Plan und es
334
	      # wurden keine Tasks gewaehlt, dann muessen wir den Planwert
335
	      # suchen und ebenfalls aufaddieren.
336
 
337
	      if ($ta_plnum < $pl_num && $ist_alt > 0 && $tmp_plan <= 0.0 && !$f_tasks && $ta_hash != $tmp_hash) {
338
	         $mon = gmdate("n", $wd_datum);
339
	         $year = gmdate("Y", $wd_datum);
340
	         $wd_datum = gmmktime(0, 0, 0, $mon, 1, $year);
341
	         $per_end = gmmktime(0, 0, 0, $mon, daysinmonth($mon, $year), $year);
342
	         $xquery = "select al_hours from allocation where ";
343
	         $xquery .= "al_task = $wd_task and al_ressource = $wd_minum and ";
344
	         $xquery .= "al_pstart between $wd_datum and $per_end";
345
 
346
	         if (!($resal = QueryDB($db, $xquery)))
347
	            return false;
348
 
349
	         if (numrowsDB($resal) > 0) {
350
	            $data = fetchDB($resal, 0);
351
	            $al_hours = $data[0];
352
	            $query .= ", tmp_plan = tmp_plan + $al_hours ";
353
	         }
354
	      }
355
 
356
	      $query .= "where tmp_lfd = $tmp_lfd";
357
 
358
	      if (!QueryDB($db, $query))
359
	         return false;
360
	   } else {
361
	      # Da es sich um einen neuen IST-Wert handelt, der moeglicherweise
362
	      # von einem aelteren Plan stammt, muessen wir den Planwert dazu
363
	      # ermitteln.
364
	      # Korrektur 12.07.2006: Planwerte von aelteren Plaenen duerfen
365
	      # nicht hinzaddiert werden!
366
	      $mon = gmdate("n", $wd_datum);
367
	      $year = gmdate("Y", $wd_datum);
368
	      $wd_datum = gmmktime(0, 0, 0, $mon, 1, $year);
369
	      $per_end = gmmktime(0, 0, 0, $mon, daysinmonth($mon, $year), $year);
370
//	      $query = "select al_hours from allocation where ";
371
//	      $query .= "al_task = $wd_task and al_ressource = $wd_minum and ";
372
//	      $query .= "al_pstart between $wd_datum and $per_end";
373
 
374
//	      if (!($resal = QueryDB($db, $query)))
375
//	         return false;
376
 
377
//	      if (numrowsDB($resal) > 0) {
378
//	         $data = fetchDB($resal, 0);
379
//	         $al_hours = $data[0];
380
//	      } else
381
	         $al_hours = 0.0;
382
 
383
	      $ta_name = addslashes($ta_name);
384
	      $query = "insert into TempPlan (tmp_lfd, tmp_miname, tmp_phase,";
385
	      $query .= "tmp_periode, tmp_plan,tmp_ist,tmp_taname,tmp_status,";
386
	      $query .= "tmp_hash, tmp_plnum, tmp_start, tmp_duration) ";
387
	      $query .= "values ($zaehler, $wd_minum, $wd_phase, $wd_datum,";
388
	      $query .= "$al_hours, $wd_ist, '$ta_name', $pr_status,";
389
	      $query .= "'$ta_hash', $ta_plnum, $ta_start, $ta_duration)";
390
 
391
	      if (!QueryDB($db, $query))
392
	         return false;
393
 
394
	      $zaehler++;
395
	   }
396
 
397
	   $rows++;
398
	}
399
 
400
	return true;
401
}
402
 
403
function ShowTempPlan($db=-1, $pr_num, $dfrom, $dto) {
404
	global $datetime;
405
 
406
	if ($db == -1)
407
	   $db = OpenDB();
408
 
409
	$query = "select tmp_lfd, mi_nname, mi_vname, tmp_periode, tmp_plan,";
410
	$query .= "tmp_ist, tmp_taname, tmp_notiz, tmp_status, tmp_hash, tmp_plnum ";
411
	$query .= "from TempPlan, mitarbeiter where ";
412
	$query .= "mi_num = tmp_miname order by tmp_hash";
413
 
414
	if (!($result = QueryDB($db, $query)))
415
	   return false;
416
 
417
	$anz = numrowsDB($result);
418
 
419
	if ($anz <= 0)
420
	   return true;
421
 
422
?>
423
<table class="input">
424
   <tr>
425
      <td><table border=0>
426
             <tr>
427
                <td>Projektnummer:</td>
428
                <td><? echo "$pr_num"; ?></td>
429
	     </tr>
430
	     <tr>
431
	        <td>Datum von:</td>
432
	        <td><? echo gmdate($datetime, $dfrom); ?></td>
433
	     </tr>
434
	     <tr>
435
	        <td>Datum bis:</td>
436
	        <td><? echo gmdate($datetime, $dto); ?></td>
437
	     </tr>
438
          </table>
439
      </td>
440
   </tr>
441
</table>
442
<table class="sel">
443
   <tr>
444
      <th class="sel">Lfd.</th>
445
      <th class="sel">Pl.Nr.</th>
446
      <th class="sel">Mitarbeiter</th>
447
      <th class="sel">Periode</th>
448
      <th class="sel">Plan</th>
449
      <th class="sel">IST</th>
450
      <th class="sel">Taskname</th>
451
      <th class="sel">Notiz</th>
452
      <th class="sel">Status</th>
453
      <th class="sel">Hash</th>
454
   </tr>
455
<?
456
	$i = 0;
457
 
458
	while ($i < $anz) {
459
	   $data = fetchDB($result, $i);
460
	   $tmp_lfd = $data[0];
461
	   $mi_nname = $data[1];
462
	   $mi_vname = $data[2];
463
	   $tmp_periode = $data[3];
464
	   $tmp_plan = $data[4];
465
	   $tmp_ist = $data[5];
466
	   $tmp_taname = $data[6];
467
	   $tmp_notiz = $data[7];
468
	   $tmp_status = $data[8];
469
	   $tmp_hash = $data[9];
470
	   $tmp_plnum = $data[10];
471
 
472
	   echo "<tr>\n<td class=\"selnum\">$tmp_lfd</td>\n";
473
	   echo "<td class=\"sel\">$tmp_plnum</td>\n";
474
	   echo "<td class=\"sel\">$mi_nname $mi_vname</td>\n";
475
	   echo "<td class=\"sel\">" . gmdate($datetime, $tmp_periode) . "</td>\n";
476
	   echo "<td class=\"selnum\">" . FormatNum($tmp_plan, 3) . "</td>\n";
477
	   echo "<td class=\"selnum\">" . FormatNum($tmp_ist, 3) . "</td>\n";
478
	   echo "<td class=\"sel\">$tmp_taname</td>\n";
479
	   echo "<td class=\"sel\">$tmp_notiz</td>\n";
480
	   echo "<td class=\"sel\">";
481
 
482
	   if ($tmp_status == 0)
483
	      echo "Projekt";
484
	   else
485
	      echo "Konto";
486
 
487
	   echo "</td>\n";
488
	   echo "<td class=\"sel\">$tmp_hash</td>\n</tr>\n";
489
	   $i++;
490
	}
491
 
492
	echo "</table>";
493
	return true;
494
}
495
?>