/graph/cost.php

https://github.com/zsalwen/Service-Office · PHP · 158 lines · 121 code · 27 blank · 10 comment · 10 complexity · 0d982c5764089407ba060506ed22b30c MD5 · raw file

  1. <?
  2. include("cost.linemaker.php");
  3. mysql_connect();
  4. mysql_select_db('core');
  5. function leading_zeros($value, $places){
  6. if(is_numeric($value)){
  7. for($x = 1; $x <= $places; $x++){
  8. $ceiling = pow(10, $x);
  9. if($value < $ceiling){
  10. $zeros = $places - $x;
  11. for($y = 1; $y <= $zeros; $y++){
  12. $leading .= "0";
  13. }
  14. $x = $places + 1;
  15. }
  16. }
  17. $output = $leading . $value;
  18. }
  19. else{
  20. $output = $value;
  21. }
  22. return $output;
  23. }
  24. function getPage($url, $referer, $timeout, $header){
  25. if(!isset($timeout))
  26. $timeout=30;
  27. $curl = curl_init();
  28. if(strstr($referer,"://")){
  29. curl_setopt ($curl, CURLOPT_REFERER, $referer);
  30. }
  31. curl_setopt ($curl, CURLOPT_URL, $url);
  32. curl_setopt ($curl, CURLOPT_TIMEOUT, $timeout);
  33. curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
  34. curl_setopt ($curl, CURLOPT_HEADER, (int)$header);
  35. curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
  36. curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
  37. $html = curl_exec ($curl);
  38. curl_close ($curl);
  39. return $html;
  40. }
  41. $year=$_GET[year];
  42. $attid=$_GET[attid];
  43. $month=0;
  44. $mainPaidIn=0;
  45. $mainOwed=0;
  46. $mainPaidOut=0;
  47. $mainLiveMargin=0;
  48. $mainMargin=0;
  49. /*$patrick = 5166; // salary - no overtime
  50. $zach = 3120 + 540; // 18 hr + overtime
  51. $danny = 2600; // 15 hr + overtime
  52. $alex = 2253; // 13 / hr
  53. $salary = $patrick + $zach + $danny + $alex;
  54. $salary2 = $salary * .09; // 9% of monthly total
  55. $health = 2500; // staff health insurance
  56. $courier = 3000; // better aim high...*/
  57. //monthly burn rate (not including postage, which is calculated within Service-Web-Service/cost.php
  58. $burn=45186.24;
  59. while($month < 12){
  60. $month++;
  61. $count = $month;
  62. $month = leading_zeros($month, '2') ;
  63. $csv = getPage("http://data.mdwestserve.com/cost.php?month=$month&year=$year&attid=$attid", 'MDWS GRAPH', '5', '');
  64. $value = explode(',',$csv);
  65. $stat[1][$count] = $value[0];
  66. $mainPaidIn = $mainPaidIn + $value[0];
  67. $stat[2][$count] = $value[1];
  68. $mainOwed = $mainOwed + $value[1];
  69. $stat[3][$count] = $value[2];
  70. $mainPaidOut = $mainPaidOut + $value[2];
  71. $stat[4][$count] = $value[3];
  72. $mainLiveMargin = $mainLiveMargin + $value[3];
  73. $stat[5][$count] = $value[4];
  74. $mainMargin = $mainMargin + $value[4];
  75. if ($value[4] != 0){
  76. $stat[11][$count] = $value[4] - $burn ;
  77. }
  78. }
  79. $year2=$_GET[year]+1;
  80. $month=0;
  81. while($month < 12){
  82. $month++;
  83. $count = $month;
  84. $month = leading_zeros($month, '2') ;
  85. $csv = getPage("http://data.mdwestserve.com/cost.php?month=$month&year=$year2&attid=$attid", 'MDWS GRAPH', '5', '');
  86. $value = explode(',',$csv);
  87. $stat[6][$count] = $value[0];
  88. $mainPaidIn = $mainPaidIn + $value[0];
  89. $stat[7][$count] = $value[1];
  90. $mainOwed = $mainOwed + $value[1];
  91. $stat[8][$count] = $value[2];
  92. $mainPaidOut = $mainPaidOut + $value[2];
  93. $stat[9][$count] = $value[3];
  94. $mainLiveMargin = $mainLiveMargin + $value[3];
  95. $stat[10][$count] = $value[4];
  96. $mainMargin = $mainMargin + $value[4];
  97. if ($value[4] != 0){
  98. $stat[12][$count] = $value[4] - $burn ;
  99. }
  100. }
  101. $l = new Line();
  102. $l->SetTitleColor(0, 0, 0);
  103. $l->SetTitle("$year / $year2 $table $id $field");
  104. $l->AddValue("January ".$stat[11][1], array($stat[1][1], $stat[2][1],$stat[3][1], $stat[4][1],$stat[5][1]));
  105. $l->AddValue("Febuary ".$stat[11][2], array($stat[1][2], $stat[2][2],$stat[3][2], $stat[4][2],$stat[5][2]));
  106. $l->AddValue("March ".$stat[11][3], array($stat[1][3], $stat[2][3],$stat[3][3], $stat[4][3],$stat[5][3]));
  107. $l->AddValue("April ".$stat[11][4], array($stat[1][4], $stat[2][4],$stat[3][4], $stat[4][4],$stat[5][4]));
  108. $l->AddValue("May ".$stat[11][5], array($stat[1][5], $stat[2][5],$stat[3][5], $stat[4][5],$stat[5][5]));
  109. $l->AddValue("June ".$stat[11][6], array($stat[1][6], $stat[2][6],$stat[3][6], $stat[4][6],$stat[5][6]));
  110. $l->AddValue("July ".$stat[11][7], array($stat[1][7], $stat[2][7],$stat[3][7], $stat[4][7],$stat[5][7]));
  111. $l->AddValue("August ".$stat[11][8], array($stat[1][8], $stat[2][8],$stat[3][8], $stat[4][8],$stat[5][8]));
  112. $l->AddValue("September ".$stat[11][9], array($stat[1][9], $stat[2][9],$stat[3][9], $stat[4][9],$stat[5][9]));
  113. $l->AddValue("October ".$stat[11][10], array($stat[1][10], $stat[2][10],$stat[3][10], $stat[4][10],$stat[5][10]));
  114. $l->AddValue("November ".$stat[11][11], array($stat[1][11], $stat[2][11],$stat[3][11], $stat[4][11],$stat[5][11]));
  115. $l->AddValue("December ".$stat[11][12], array($stat[1][12], $stat[2][12],$stat[3][12], $stat[4][12],$stat[5][12]));
  116. $l->AddValue("January ".$stat[12][1], array($stat[6][1], $stat[7][1],$stat[8][1], $stat[9][1],$stat[10][1]));
  117. $l->AddValue("Febuary ".$stat[12][2], array($stat[6][2], $stat[7][2],$stat[8][2], $stat[9][2],$stat[10][2]));
  118. $l->AddValue("March ".$stat[12][3], array($stat[6][3], $stat[7][3],$stat[8][3], $stat[9][3],$stat[10][3]));
  119. $l->AddValue("April ".$stat[12][4], array($stat[6][4], $stat[7][4],$stat[8][4], $stat[9][4],$stat[10][4]));
  120. $l->AddValue("May ".$stat[12][5], array($stat[6][5], $stat[7][5],$stat[8][5], $stat[9][5],$stat[10][5]));
  121. $l->AddValue("June ".$stat[12][6], array($stat[6][6], $stat[7][6],$stat[8][6], $stat[9][6],$stat[10][6]));
  122. $l->AddValue("July ".$stat[12][7], array($stat[6][7], $stat[7][7],$stat[8][7], $stat[9][7],$stat[10][7]));
  123. $l->AddValue("August ".$stat[12][8], array($stat[6][8], $stat[7][8],$stat[8][8], $stat[9][8],$stat[10][8]));
  124. $l->AddValue("September ".$stat[12][9], array($stat[6][9], $stat[7][9],$stat[8][9], $stat[9][9],$stat[10][9]));
  125. $l->AddValue("October ".$stat[12][10], array($stat[6][10], $stat[7][10],$stat[8][10], $stat[9][10],$stat[10][10]));
  126. $l->AddValue("November ".$stat[12][11], array($stat[6][11], $stat[7][11],$stat[8][11], $stat[9][11],$stat[10][11]));
  127. $l->AddValue("December ".$stat[12][12], array($stat[6][12], $stat[7][12],$stat[8][12], $stat[9][12],$stat[10][12]));
  128. $l->SetSeriesLabels(Array("Client Paid ".$mainPaidIn, "Balence Due ".$mainOwed,"Contractor Paid ".$mainPaidOut,"Live Margin ".$mainLiveMargin,"Est. Margin ".$mainMargin));
  129. $l->spit("jpg");
  130. ?>