Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL & ~E_NOTICE);
- $name = $_GET['name'];
- $price = $_GET['price'];
- $amount = $_GET['amount'];
- $percent = $_GET['percent'];
- $period = $_GET['period'];
- $sum = $price * $amount;
- ?>
- <div align="left">
- <form method="get">
- Shareholder name: <br><input type="text" name="name" value="<?php echo $name; ?>"><br>
- Price: <br><input type="text" name="price" value="<?php echo $price; ?>"><br>
- Amount: <br><input type="text" name="amount" value="<?php echo $amount; ?>"><br>
- Growth per year (%): <br><input type="text" name="percent" value="<?php echo $percent; ?>"><br>
- Period (Years): <br><input type="text" name="period" value="<?php echo $period; ?>"><br>
- <input type="submit" value="Calculate">
- </form>
- </div>
- <?php
- $sumst=$sum;
- $percent=$percent * 0.01;
- $sum1=$sum;
- if(isset($name) and is_numeric($price) and is_numeric($amount) and is_numeric($percent) and is_numeric($period)){
- echo "<table border=\"1\" bordercolor=\"green\" bgcolor=\"#F0FFF0\">";
- echo "<th>Year</th>";
- echo "<th>Sum</th>";
- echo "<th>Difference from previous year</th>";
- echo "<th>Difference from start</th>";
- echo "<th>Difference from previous difference (just because)</th>";
- echo "<tr>";
- echo "<td>0</td>";
- echo "<td>".$sum."</td>";
- echo "<td>-</td>";
- echo "<td>-</td>";
- echo "<td>-</td>";
- for($i=1; $i<=$period; $i++){
- $sum2 = $sum;
- echo "<tr>";
- //Year number
- echo "<td>".$i."</td>";
- //Sum calculation
- $sum = $sum + $percent * $sum;
- echo "<td>".$sum."</td>";
- //Difference from previous year
- $difprev2 = $difprev;
- $difprev=$sum-$sum2;
- echo "<td>".$difprev."</td>";
- //Difference from start
- $difst = $sum - $sum1;
- echo "<td>".$difst."</td>";
- //Difference from previous difference
- $difdif = $difprev - $difprev2;
- echo "<td>".$difdif."</td>";
- }
- echo "</tr>";
- echo "</table>";
- echo "<br>";
- }
- else{
- echo "<font size=\"20\" color=\"#900020\" font-size:large>Please fill in all fields.</font>";
- }
- ?>
- <html>
- <head>
- <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
- <script type="text/javascript">
- google.charts.load('current', {'packages':['corechart']});
- google.charts.setOnLoadCallback(drawChart);
- function drawChart() {
- var data = new google.visualization.DataTable();
- data.addColumn('number', 'Year');
- data.addColumn('number', 'Sum');
- data.addRows([
- [0, <?php echo $sumst; ?>],
- <?php
- for ($i=1; $i<=$period; $i++){
- $sumst = $sumst * $percent + $sumst;
- echo "[".$i.", ".$sumst."],";
- }
- ?>
- ]);
- var options = {
- title: '<?php echo $name; ?>',
- subtitle: 'Investment calculator',
- curveType: 'function',
- legend: { position: 'bottom' }
- };
- var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
- chart.draw(data, options);
- }
- </script>
- </head>
- <body>
- <div id="curve_chart" style="width: 900px; height: 500px"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement