| [ PHPXref.com ] | [ Generated: Sun Jul 20 20:47:44 2008 ] | [ TUTOS 1.2 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Copyright 1999 - 2003 by Gero Kohnert 4 * well, copyright? Inspired by Gero, 5 * shamelessly copied and mutulated by J. Baten 6 * This should turn out to be a salesforecast report 7 * Multiply price * probability = balanced sales amount 8 * if chances are estimated correctly this should give you 9 * a good impression of future sales. 10 * version 1.1 d.d. 01032002 J. Baten initial version. far from finished. 11 * version 1.2 d.d. 02032002 J. Baten, fixed the totals at the bottom 12 * still todo 13 * -subdivide output in separate months 14 * -make graph of report (using jpgraph) 15 */ 16 include_once 'webelements.p3'; 17 include_once 'permission.p3'; 18 include_once 'appointment.pinc'; 19 include_once 'timetrack.pinc'; 20 include_once 'product.pinc'; 21 include_once 'task.pinc'; 22 23 /* Check if user is allowed to use it */ 24 check_user(); 25 loadmodules("prodct","forecast"); 26 loadlayout(); 27 28 /** 29 * sales forecast 30 */ 31 class product_forecast extends layout { 32 /** 33 * Display table with product/project info. This is the normal report. 34 * version: 1.0 date 03022002 J. Baten Seems to be find now. 35 */ 36 Function info() { 37 global $lang,$tutos; 38 39 $result = $this->dbconn->Exec($this->q); 40 $plist = array(); 41 $n = $result->numrows(); 42 if ( 0 == $n) { 43 echo $this->error($lang['Err0048']); 44 $result->free(); 45 return; 46 } 47 if ($this->format == "stat" ) { 48 $this->statinfo($result); 49 $result->free(); 50 return; 51 } 52 if ( $this->format == "image" ) { 53 $this->image($result); 54 return; 55 } 56 foreach($tutos[currencies] as $c) { 57 $sum[1][$c] = 0; 58 $sum[2][$c] = 0; 59 } 60 $sum[1][""] = 0; 61 $sum[2][""] = 0; 62 63 $flds = 0; 64 65 # Make a big array of all visible products 66 $x = 0; 67 while ( $x < $n ) { 68 $p = new product($this->dbconn); 69 $p->read_result($result,$x); 70 $x++; 71 if ( ! $p->see_ok() ) { 72 unset($p); 73 continue; 74 } 75 $sum[1][$p->currency] += $p->price; 76 $sum[2][$p->currency] += $p->getBalanced(); 77 $plist[] = &$p; 78 unset($p); 79 } 80 $n = count($plist); 81 if ( 0 == $n) { 82 echo $this->error($lang['Err0048']); 83 $result->free(); 84 return; 85 } 86 87 # start the header for the results 88 echo $this->OverviewTableStart(); 89 echo "<thead>\n"; 90 echo "<tr>\n"; 91 92 foreach ($tutos[prodfields] as $c) { 93 if ( ($c == "name") && $this->pshow[$c] ) { 94 echo $this->orderHeader("",$lang['ProdName'],""); 95 $flds++; 96 } 97 if ( ($c == "version") && $this->pshow[$c] ) { 98 echo $this->orderHeader("",$lang['ProdVersion'],""); 99 $flds++; 100 } 101 if ( ($c == "seller") && $this->pshow[$c] ) { 102 echo $this->orderHeader("",$lang['ProdRole'][4],""); 103 $flds++; 104 } 105 if ( ($c == "manager") && $this->pshow[$c] ) { 106 echo $this->orderHeader("",$lang['ProdRole'][1],""); 107 $flds++; 108 } 109 if ( ($c == "customer") && $this->pshow[$c] ) { 110 echo $this->orderHeader("",$lang['ProdRole'][6],""); 111 $flds++; 112 } 113 if ( ($c == "supplier") && $this->pshow[$c] ) { 114 echo $this->orderHeader("",$lang['ProdRole'][7],""); 115 $flds++; 116 } 117 if ( ($c == "reseller") && $this->pshow[$c] ) { 118 echo $this->orderHeader("",$lang['ProdRole'][8],""); 119 $flds++; 120 } 121 if ( ($c == "partner") && $this->pshow[$c] ) { 122 echo $this->orderHeader("",$lang['ProdRole'][9],""); 123 $flds++; 124 } 125 if ( ($c == "desc") && $this->pshow[$c] ) { 126 echo $this->orderHeader("",$lang['ProdDesc'],""); 127 $flds++; 128 } 129 if ( ($c == "desc1") && $this->pshow[$c] ) { 130 echo $this->orderHeader("",$lang['ProdDesc1'],""); 131 $flds++; 132 } 133 if ( ($c == "desc2") && $this->pshow[$c] ) { 134 echo $this->orderHeader("",$lang['ProdDesc2'],""); 135 $flds++; 136 } 137 if ( ($c == "cl1") && $this->pshow[$c] ) { 138 echo $this->orderHeader("",$lang['ProdClass1'],""); 139 $flds++; 140 } 141 if ( ($c == "cl2") && $this->pshow[$c] ) { 142 echo $this->orderHeader("",$lang['ProdClass2'],""); 143 $flds++; 144 } 145 if ( ($c == "state") && $this->pshow[$c] ) { 146 echo$this-> orderHeader("",$lang['ProdState'],""); 147 $flds++; 148 } 149 if ( ($c == "probability") && $this->pshow[$c] ) { 150 echo $this->orderHeader("",$lang['ProdProb'],""); 151 $flds++; 152 } 153 if ( ($c == "price") && $this->pshow[$c] ) { 154 echo $this->orderHeader("",$lang['ProdPrice'],""); 155 $flds++; 156 $pf = $flds; 157 } 158 if ( ($c == "cost") && $this->pshow[$c] ) { 159 echo $this->orderHeader("",$lang['ProdCost'],""); 160 $flds++; 161 $cf = $flds; 162 } 163 if ( ($c == "creator") && $this->pshow[$c] ) { 164 echo $this->orderHeader("",$lang['ProdCreator'],$this->link2); 165 $flds++; 166 } 167 if ( ($c == "creation") && $this->pshow[$c] ) { 168 echo $this->orderHeader("creation",$lang['ProdCreationS'],$this->link2); 169 $flds++; 170 } 171 if ( ($c == "p_start") && $this->pshow[$c] ) { 172 echo $this->orderHeader("",$lang['ProdStart'],""); 173 $flds++; 174 } 175 if ( ($c == "p_end") && $this->pshow[$c] ) { 176 echo $this->orderHeader("",$lang['ProdEnd'],""); 177 $flds++; 178 } 179 if ( ($c == "balanced") && $this->pshow[$c] ) { 180 echo $this->orderHeader("",$lang['SalesBalanced'],""); 181 $flds++; 182 } 183 if ( $this->user->feature_ok(usebugtracking,PERM_SEE) ) { 184 if ( ($c == "pbugs") && $this->pshow[$c] ) { 185 echo $this->orderHeader("",$lang['Bugs'],""); 186 $flds++; 187 } 188 } 189 } 190 echo "</tr>\n"; 191 echo "</thead>\n"; 192 193 $a = 0; 194 $end = $n; 195 $line = 0; 196 197 $sumPeriod = array(); 198 $oldperiod = ""; 199 $notthefirst=false; 200 # start the main body with the results 201 echo "<tbody>\n"; 202 while ( ($a < $n) && ($a < $end) ) { 203 $p = &$plist[$a]; 204 $p->readroles(); 205 206 # here we select the period to display 207 $period=$p->p_end->month."/".$p->p_end->year; 208 if ( $period == "-1/-1" ) { 209 $period=$lang["UndefinedEndDate"]; 210 } 211 # a new timeperiod has started. Let's make a row. 212 # and if it is not the first header then print a subtotal 213 if ( $oldperiod != $period ) { 214 if ( $notthefirst == true ) { 215 $periodtotal=$sumPeriod[$oldperiod]; 216 echo "<tr><td colspan='". ($flds - 1) ."'> </td><td nowrap align='right'><i><b>"; 217 foreach($periodtotal as $i => $f) { 218 echo number_format($f,2,$lang['DecPoint'],$lang['ThousandPoint']) ." ". htmlspecialchars($i) ."<br>\n"; 219 } 220 echo "</b></i></td></tr>"; 221 } 222 $sumPeriod[$period] = array(); 223 echo "<tr><td colspan='". $flds ."' align='left'><h2>".$period."</h2></td></tr>"; 224 $notthefirst=true; 225 } 226 $oldperiod=$period; 227 if (!isset($sumPeriod[$period][$p->currency])) { 228 $sumPeriod[$period][$p->currency] = 0; 229 } 230 $sumPeriod[$period][$p->currency] += $p->getBalanced(); 231 # 232 echo $this->OverviewRowStart($line); 233 foreach ($tutos[prodfields] as $c) { 234 # projectname 235 if ( ($c == "name") && $this->pshow[$c] ) { 236 $b = myentities($p->name); 237 if ( $this->filter['name'] != "" ) { 238 $b = eregi_replace("(". $this->filter['name'] .")","<span class=\"found\">\\1</span>",$b); 239 } 240 echo " <td valign=\"top\"> ". makelink($p->getUrl(),$b) ."</td>\n"; 241 } 242 if ( ($c == "version") && $this->pshow[$c] ) { 243 $b = myentities($p->version); 244 if ( $this->filter['name'] != "" ) { 245 $b = eregi_replace("(". $this->filter['name'] .")","<span class=\"found\">\\1</span>",$b); 246 } 247 echo " <td valign=\"top\"> ". $b ."</td>\n"; 248 } 249 250 # Customer 251 if ( ($c == "customer") && $this->pshow[$c] ) { 252 echo " <td valign=\"top\">\n "; 253 if (isset($p->role[6]) && (count($p->role[6]) > 0) ) { 254 @reset ($p->role[6]) ; 255 $x = 0; 256 while ( list ($i,$r) = @each ($p->role[6]) ) { 257 if ( $x > 0 ) { 258 echo "<br>\n "; 259 } 260 echo $r->getLink(); 261 $x++; 262 } 263 } 264 echo " </td>\n"; 265 } 266 267 # someone forget to say 'description' here :-) 268 if ( ($c == "desc") && $this->pshow[$c] ) { 269 $b = myentities($p->description); 270 if ( $this->filter['name'] != "" ) { 271 $b = eregi_replace("(". $this->filter['name'] .")","<span class=\"found\">\\1</span>",$b); 272 } 273 echo " <td valign=\"top\"> ". $b ."</td>\n"; 274 } 275 276 # state 277 if ( ($c == "state") && $this->pshow[$c] ) { 278 echo " <td valign=\"top\"> ". $lang['ProdStates'][$p->state] ."</td>\n"; 279 } 280 # probability (mucho importante) 281 if ( ($c == "probability") && $this->pshow[$c] ) { 282 echo " <td valign=\"top\"> ". $p->probability ."%</td>\n"; 283 } 284 # price (also mucho importante) 285 if ( ($c == "price") && $this->pshow[$c] ) { 286 echo " <td valign=\"top\" align=\"right\"> ". number_format($p->price,2,$lang['DecPoint'],$lang['ThousandPoint']) ." ". htmlspecialchars($p->currency) ."</td>\n"; 287 } 288 # price (also mucho importante) 289 if ( ($c == "cost") && $this->pshow[$c] ) { 290 echo " <td valign=\"top\" align=\"right\"> ". number_format($p->cost,2,$lang['DecPoint'],$lang['ThousandPoint']) ." ". htmlspecialchars($p->currency) ."</td>\n"; 291 } 292 # balanced result 293 if ( ($c == "balanced") && $this->pshow[$c] ) { 294 echo " <td valign=\"top\" align=\"right\"> ". number_format($p->getBalanced(),2,$lang['DecPoint'],$lang['ThousandPoint']) ." ". htmlspecialchars($p->currency) ."</td>\n"; 295 } 296 # start date 297 if ( ($c == "p_start") && $this->pshow[$c] ) { 298 echo " <td valign=\"top\"> ". $p->p_start->getLinkDate() ."</td>\n"; 299 } 300 # end date 301 if ( ($c == "p_end") && $this->pshow[$c] ) { 302 echo " <td valign=\"top\"> ". $p->p_end->getLinkDate() ."</td>\n"; 303 } 304 } 305 echo $this->OverviewRowEnd($line++); 306 unset($plist[$a]); 307 unset($p); 308 $a++; 309 } 310 echo "</tbody>\n"; 311 312 echo "<tfoot>\n"; 313 echo $this->list_navigation($this->link1,$flds,$this->start,$a,$n); 314 315 # Sums of amounts 316 if ( ($this->pshow['price'] == 1) || ($this->pshow['balanced'] == 1) ) { 317 echo "<tr>\n"; 318 $fill = 0; 319 foreach ($tutos[prodfields] as $c) { 320 if ( $this->pshow[$c] == 0 ) { 321 continue; 322 } 323 # display total sum of price 324 if ( $c == "price" ) { 325 if ( $fill > 0 ) { 326 echo " <td colspan=\"". $fill ."\"> </td>\n"; 327 $fill = 0; 328 } 329 echo " <td nowrap align=\"right\">\n"; 330 @reset($sum[1]); 331 $pre = ""; 332 while( list ($i1,$f1) = @each ($sum[1])) { 333 if ( $f1 ) { 334 echo $pre . number_format($f1,2,$lang['DecPoint'],$lang['ThousandPoint']) ." ". $i1; 335 $pre = "<br>\n"; 336 } 337 } 338 echo " </td>\n"; 339 } else if ( $c == "balanced" ) { 340 # display total sum of balanced 341 if ( $fill > 0 ) { 342 echo " <td colspan=\"". $fill ."\"> </td>\n"; 343 $fill = 0; 344 } 345 echo " <td nowrap align=\"right\">\n"; 346 @reset($sum[2]); 347 $pre = ""; 348 while( list ($i1,$f1) = @each ($sum[2])) { 349 if ( $f1 ) { 350 echo $pre . number_format($f1,2,$lang['DecPoint'],$lang['ThousandPoint']) ." ". $i1; 351 $pre = "<br>\n"; 352 } 353 } 354 echo " </td>\n"; 355 } else { 356 $fill++; 357 } 358 } 359 if ( $fill > 0 ) { 360 echo " <td colspan=\"". $fill ."\"> </td>\n"; 361 } 362 echo "</tr>\n"; 363 } 364 365 echo "</tfoot>\n"; 366 echo $this->OverviewTableEnd(); 367 } 368 /** 369 * version 1.0 date 03032002 initial version 370 * This procedure makes a graphic display of the information. 371 * since I can't use jpgrapg to make an inline graphic, I just 372 * call myself as an image... :-) cute no? 373 */ 374 Function statinfo() { 375 global $lang,$tutos; 376 377 load_jpgraph( array("jpgraph_gantt.php","jpgraph_bar.php") ); 378 379 if ($tutos[usejpgraph] != 0 ) { 380 $src = "sales_forecast.php?format=image"; 381 $src = addSessionKey($src); 382 echo "<img border=\"0\" src=\"".$src."\">"; 383 } else { 384 echo $this->error("no jpgraph"); 385 } 386 } 387 388 # this function is used by the above mentioned function 389 Function image(&$result) { 390 global $lang,$tutos; 391 392 load_jpgraph( array("jpgraph_gantt.php","jpgraph_bar.php") ); 393 #add a temporary field 394 # now where can I put the above extension? 395 396 $n = $result->numrows(); 397 $a = 0; 398 $cnt = 0; 399 $notthefirst=false; 400 $sumperiodtotal=0; 401 $datax=array(); 402 $datay1=array(); 403 $datay2=array(); 404 $sumPeriod = array(); 405 $oldperiod = ""; 406 while ( $a < $n ) { 407 $p = new product($this->dbconn); 408 $p->read_result($result,$a); 409 #$p->readroles(); 410 $cnt++; 411 # here we select the period to display 412 $m=$p->p_end->month; 413 $y=$p->p_end->year; 414 $period= $m."/".$y; 415 if ( $period == "-1/-1" ) { 416 $period=$lang["UndefinedEndDate"]; 417 } 418 # a new timeperiod has started. Let's make a row. 419 # and if it is not the first header then print a subtotal 420 if ( $oldperiod != $period ) { 421 if ( $notthefirst == true ) { 422 array_push($datax,$oldperiod); 423 424 $periodtotal=$sumPeriod[$oldperiod]; 425 array_push($datay1,$periodtotal); 426 427 $sumperiodtotal+=$periodtotal; 428 array_push($datay2,$sumperiodtotal); 429 430 $sumPeriod[$period]=0; 431 } 432 $notthefirst=true; 433 } 434 $oldperiod=$period; 435 if (isset($sumPeriod[$period])) { 436 $sumPeriod[$period]+=$p->getBalanced(); 437 } else { 438 $sumPeriod[$period]= $p->getBalanced(); 439 } 440 #unset($p); 441 $a++; 442 } 443 # let's get the last values... 444 array_push($datax,$oldperiod); 445 446 $periodtotal=$sumPeriod[$oldperiod]; 447 array_push($datay1,$periodtotal); 448 449 $sumperiodtotal+=$periodtotal; 450 array_push($datay2,$sumperiodtotal); 451 452 $graph = new Graph(600,400,"auto"); 453 $graph->img->SetMargin(90,40,40,40); 454 $graph->SetScale("textlin"); 455 # $graph->SetShadow(); 456 $graph->title->Set($lang['SalesForecastRep']); 457 $graph->title->SetFont(FF_FONT1,FS_BOLD); 458 459 $graph->xaxis->title->Set($lang["Period"]); 460 $graph->xaxis->SetTickLabels($datax); 461 $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); 462 463 $graph->yaxis->title->Set($lang["Est_revenue"]); 464 $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); 465 $graph->yaxis->SetTitleMargin(65); 466 467 $p1 = new BarPlot($datay2); 468 $p1->SetFillColor("orange"); 469 $p1->SetLegend($lang["AccumulatedRevenue"]); 470 471 $p2 = new BarPlot($datay1); 472 $p2->SetFillColor("blue"); 473 $p2->SetWidth(1.0); 474 # $p2->SetValueFormat("%0d"); 475 # $p2->ShowValue(); 476 $p2->SetLegend($lang["PeriodRevenue"]); 477 478 // Create the grouped bar plot 479 $plot = new AccBarPlot(array($p1,$p2)); 480 $plot->SetShadow(); 481 482 $graph->Add($plot); 483 $graph->Stroke(); 484 } 485 486 /** 487 * navigate 488 */ 489 Function navigate() { 490 global $lang,$tutos; 491 492 echo "<tr><td>\n"; 493 $m = product::getSelectLink($this->user,$lang['Search']); 494 echo menulink($m[url],$m[text],$m[info]) ."<br>\n"; 495 496 echo menulink("product_new.php",$lang['NewEntry'],$lang['ProdCreateInfo']) ."<br>"; 497 echo "</td></tr>\n"; 498 echo "<tr><td>\n"; 499 $ll = addUrlParameter($this->link1,"format=paper"); 500 echo menulink($ll,$lang['Printable'],$lang['PrintableInfo']); 501 502 if ( $this->format != "stat" ) { 503 echo "<br>"; 504 $ll = addUrlParameter($this->link1,"format=stat"); 505 echo menulink($ll,$lang['Graph'],$lang['GraphInfo']); 506 } 507 echo "</td></tr>\n"; 508 } 509 /** 510 * prepare 511 */ 512 Function prepare() { 513 global $msg,$tutos,$lang; 514 515 $this->name = $lang['SalesForecastRep']; 516 $this->link1 = "sales_forecast.php"; 517 $this->filter = array(); 518 $this->filter['name'] = ""; 519 $this->pshow = array(); 520 $tutos[prodfields][] = "balanced"; 521 foreach ($tutos[prodfields] as $c) { 522 $this->pshow[$c] = 0; 523 } 524 $this->pshow['name'] = 1; 525 $this->pshow['customer'] = 1; 526 $this->pshow['desc'] = 1; 527 $this->pshow['cost'] = 1; 528 $this->pshow['price'] = 1; 529 $this->pshow['probability'] = 1; 530 $this->pshow['balanced'] = 1; 531 $this->pshow['state'] = 1; 532 $this->pshow['p_start'] = 1; 533 $this->pshow['p_end'] = 1; 534 $this->pshow['balanced'] = 1; 535 536 $this->flds['name'] = 'ProdName'; 537 $this->flds['version'] = 'ProdVersion'; 538 $this->flds['customer'] = 'ProdRole6'; 539 $this->flds['desc'] = 'ProdDesc'; 540 $this->flds['cost'] = 'ProdCost'; 541 $this->flds['price'] = 'ProdPrice'; 542 $this->flds['probability'] = 'ProdProb'; 543 $this->flds['balanced'] = 'balanced'; 544 $this->flds['state'] = 'ProdState'; 545 $this->flds['p_start'] = 'ProdStart'; 546 $this->flds['p_end'] = 'ProdEnd'; 547 $p = new product($this->dbconn); 548 for ( $cl = 1;$cl <= $p->classes; $cl++) { 549 $x = sprintf("cl%d",$cl); 550 $this->flds['cl'.$cl] = 'ProdClass'.$cl; 551 } 552 553 $this->q = "SELECT * FROM ". $this->dbconn->prefix ."products where state in (0,1,4)"; 554 $pre = " WHERE "; 555 $this->q .= " ORDER by p_end ASC"; 556 } 557 } 558 559 560 # functions to do when we have a lot of info BUT BEFORE any output! 561 # is the file calles with an argument 'function'? 562 563 564 $l = new product_forecast($current_user); 565 $l->display(); 566 $dbconn->Close(); 567 ?> 568 <!-- 569 CVS Info: $Id: sales_forecast.php,v 1.24 2004/03/13 13:31:47 gokohnert Exp $ 570 $Author: gokohnert $ 571 -->
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |