html - Accumulated Depreciation of Assets on php -
i have problem table print out asset accumulated depreciation on php, stright line method.
$query = mysqli_query($connect, "select current_value, salvage_value, useful_life, placed_service assets"); if(!$query){ echo 'could not run query b: ' . mysqli_error($connect); exit; } while($asset = mysqli_fetch_row($query)){ echo "assets :"; print_r($asset); $month = 12; $year = date('y',strtotime($asset[3])); $first_year = $month - ((int)date('m',strtotime($asset[3]))-1); $last_year = $month - $first_year; $first = round((($asset[0] - $asset[1])/$asset[2])*(($first_year)/12),0); $last = round((($asset[0] - $asset[1])/$asset[2])*(($last_year)/12),0); $others = ($asset[0] - $asset[1])/$asset[2]; echo "<table border=1>"; echo "<tr><th>year</th><th>book value year start</th><th>depreciation expense</th><th>accumulated depreciation</th><th>book value year end</th></tr>; for($i=$year;$i<=$year+$asset[2];$i++){ //echo "<tr><td>".$i."</td>"; if ($i == $year){ //echo "<td>".$first."</td>"; $aset = $first; } elseif ($i == $year+$asset[2]){ //echo "<td>".$last."</td>"; $aset = $last; } else { //echo "<td>".$others."</td>"; $aset = $others; } } $current = $asset[0]; $total = 0; $assets = array(array($i,$aset)); foreach($assets $asets){ echo "<tr><td>".$asets[0]."</td>"; echo "<td>".number_format($current, 2, '.', ',')."</td>"; echo "<td>".number_format($asets[1], 2, '.', ',')."</td>"; $total += $asets[1]; echo "<td>".number_format($total, 2, '.', ',')."</td>"; $current -= $asets[1]; echo "<td>".number_format($current, 2, '.', ',')."</td>"; } } echo "</tr>"; echo "</table>"; }
here result @sean :
year book value year start depreciation expense accumulated depreciation book value year end 2014 100,000,000.00 8,250,000.00 8,250,000.00 91,750,000.00 2015 100,000,000.00 9,900,000.00 18,150,000.00 90,100,000.00 2016 100,000,000.00 9,900,000.00 28,050,000.00 90,100,000.00 2017 100,000,000.00 9,900,000.00 37,950,000.00 90,100,000.00 2018 100,000,000.00 9,900,000.00 47,850,000.00 90,100,000.00 2019 100,000,000.00 9,900,000.00 57,750,000.00 90,100,000.00 2020 100,000,000.00 9,900,000.00 67,650,000.00 90,100,000.00 2021 100,000,000.00 9,900,000.00 77,550,000.00 90,100,000.00 2022 100,000,000.00 9,900,000.00 87,450,000.00 90,100,000.00 2023 100,000,000.00 9,900,000.00 97,350,000.00 90,100,000.00 2024 100,000,000.00 1,650,000.00 99,000,000.00 98,350,000.00
does how create accumulated depreciation table below,
year book value depreciation depreciation book value year start expense accumulated year end 2014 100,000,000.000 8,250,000.00 8,250,000.00 91,750,000.00 2015 91,750,000.00 9,900,000.00 18,150,000.00 81,850,000.00 2016 81,850,000.00 9,900,000.00 28,050,000.00 71,950,000.00 2017 71,950,000.00 9,900,000.00 37,950,000.00 62,050,000.00 2018 62,050,000.00 9,900,000.00 47,850,000.00 52,150,000.00 2019 52,150,000.00 9,900,000.00 57,750,000.00 42,250,000.00 2020 42,250,000.00 9,900,000.00 67,650,000.00 32,350,000.00 2021 32,350,000.00 9,900,000.00 77,550,000.00 22,450,000.00 2022 22,450,000.00 9,900,000.00 87,450,000.00 12,550,000.00 2023 12,550,000.00 9,900,000.00 97,350,000.00 2,650,000.00 2024 2,650,000.00 1,650,000.00 99,000,000.00 1,000,000.00
i'am appreciated if know how make on php code.
i don't follow logic, looks need add 2 counter variables - (1) current value, , (2) accumulated depreciation.
here sample example -
$assets = array( array(2014,8250000), array(2015,9900000), array(2016,9900000), array(2017,9900000), array(2018,9900000), array(2019,9900000), array(2020,9900000), array(2021,9900000), array(2022,9900000), array(2023,9900000), array(2024,1650000)); $current = 100000000; $total = 0; echo "<table border=1>"; echo "<tr><th>year</th><th>book value<br />year start</th><th>depreciation<br />expense</th><th>depreciation<br />accumulated</th><th>book value<br />year end</th></tr>"; foreach($assets $asset){ echo "<tr><td>".$asset[0]."</td>"; echo "<td>".number_format($current, 2, '.', ',')."</td>"; echo "<td>".number_format($asset[1], 2, '.', ',')."</td>"; $total += $asset[1]; echo "<td>".number_format($total, 2, '.', ',')."</td>"; $current -= $asset[1]; echo "<td>".number_format($current, 2, '.', ',')."</td></tr>"; } echo "</table>";
based on updated code try changing
$current = $asset[0];
to
if(!isset($current)) {$current = $asset[0];}
this way $current
set on 1st time in loop, , not reset on each time through.
Comments
Post a Comment