Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL & ~E_NOTICE);
  3.  
  4. $name = $_GET['name'];
  5. $price = $_GET['price'];
  6. $amount = $_GET['amount'];
  7. $percent = $_GET['percent'];
  8. $period = $_GET['period'];
  9. $sum = $price * $amount;
  10.  
  11. ?>
  12. <div align="left">
  13. <form method="get">
  14. Shareholder name: <br><input type="text" name="name" value="<?php echo $name; ?>"><br>
  15. Price: <br><input type="text" name="price" value="<?php echo $price; ?>"><br>
  16. Amount: <br><input type="text" name="amount" value="<?php echo $amount; ?>"><br>
  17. Growth per year (%): <br><input type="text" name="percent" value="<?php echo $percent; ?>"><br>
  18. Period (Years): <br><input type="text" name="period" value="<?php echo $period; ?>"><br>
  19. <input type="submit" value="Calculate">
  20. </form>
  21. </div>
  22.  
  23. <?php
  24. $sumst=$sum;
  25. $percent=$percent * 0.01;
  26. $sum1=$sum;
  27. if(isset($name) and is_numeric($price) and is_numeric($amount) and is_numeric($percent) and is_numeric($period)){
  28. echo "<table border=\"1\" bordercolor=\"green\" bgcolor=\"#F0FFF0\">";
  29. echo "<th>Year</th>";
  30. echo "<th>Sum</th>";
  31. echo "<th>Difference from previous year</th>";
  32. echo "<th>Difference from start</th>";
  33. echo "<th>Difference from previous difference (just because)</th>";
  34. echo "<tr>";
  35. echo "<td>0</td>";
  36. echo "<td>".$sum."</td>";
  37. echo "<td>-</td>";
  38. echo "<td>-</td>";
  39. echo "<td>-</td>";
  40. for($i=1; $i<=$period; $i++){
  41. $sum2 = $sum;
  42. echo "<tr>";
  43. //Year number
  44. echo "<td>".$i."</td>";
  45. //Sum calculation
  46. $sum = $sum + $percent * $sum;
  47. echo "<td>".$sum."</td>";
  48. //Difference from previous year
  49. $difprev2 = $difprev;
  50. $difprev=$sum-$sum2;
  51. echo "<td>".$difprev."</td>";
  52. //Difference from start
  53. $difst = $sum - $sum1;
  54. echo "<td>".$difst."</td>";
  55. //Difference from previous difference
  56. $difdif = $difprev - $difprev2;
  57. echo "<td>".$difdif."</td>";
  58. }
  59. echo "</tr>";
  60. echo "</table>";
  61. echo "<br>";
  62. }
  63. else{
  64. echo "<font size=\"20\" color=\"#900020\" font-size:large>Please fill in all fields.</font>";
  65. }
  66. ?>
  67.  
  68. <html>
  69. <head>
  70. <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  71. <script type="text/javascript">
  72. google.charts.load('current', {'packages':['corechart']});
  73. google.charts.setOnLoadCallback(drawChart);
  74.  
  75. function drawChart() {
  76. var data = new google.visualization.DataTable();
  77. data.addColumn('number', 'Year');
  78. data.addColumn('number', 'Sum');
  79. data.addRows([
  80. [0, <?php echo $sumst; ?>],
  81. <?php
  82. for ($i=1; $i<=$period; $i++){
  83. $sumst = $sumst * $percent + $sumst;
  84. echo "[".$i.", ".$sumst."],";
  85. }
  86. ?>
  87. ]);
  88.  
  89. var options = {
  90. title: '<?php echo $name; ?>',
  91. subtitle: 'Investment calculator',
  92. curveType: 'function',
  93. legend: { position: 'bottom' }
  94. };
  95.  
  96. var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
  97.  
  98. chart.draw(data, options);
  99. }
  100. </script>
  101. </head>
  102. <body>
  103. <div id="curve_chart" style="width: 900px; height: 500px"></div>
  104. </body>
  105. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement