Posted by: Zeeshan Amjad | November 24, 2009

Depreciation using Declining Balance Method


We just saw how to calculate the depreciation using straight line method, now we are going to calculate depreciation using another method, i.e. Decline Balance method. This is also known as double declining balance method. Here are are again going to use progress bar in the list control.

Here is a code to calculate the depreciation using declining balance method.

  1: for (int iIndex = 0; iIndex < year; iIndex++)
  2: {
  3: 	depExpense = bookValue * percentage * 2;
  4: 				  
  5: 	if (bookValue - depExpense < scrap)
  6: 	{
  7: 		depExpense = bookValue - scrap;
  8: 		bookValue = scrap;
  9: 	}
 10: 	else
 11: 	{
 12: 		bookValue -= depExpense;
 13: 	}
 14: 
 15: 	accDepreciation += depExpense;
 16: 
 17: 	DepreciationInfo dpInfo = new DepreciationInfo();
 18: 	dpInfo.Year = (iIndex + 1);
 19: 	dpInfo.Depreciation = depExpense;
 20: 	dpInfo.AccDepreciation = accDepreciation;
 21: 	dpInfo.BookValue = bookValue;
 22: 	dpInfo.Percentage = (bookValue * 100) / cost; ;
 23: 
 24: 	depreciation.Add(dpInfo);
 25: }
 26: 

Here is a complete XAML code of the project.

  1: <Window x:Class="Depreciation.Window1"
  2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4:     Title="Depreciation" Height="400" Width="600">
  5:     
  6:     <Grid Background="AliceBlue">
  7:         <Grid.RowDefinitions>
  8:             <RowDefinition/>
  9:             <RowDefinition/>
 10:             <RowDefinition/>
 11:             <RowDefinition Height="4*"/>
 12:             <RowDefinition/>
 13:         </Grid.RowDefinitions>
 14: 
 15:         <Grid.ColumnDefinitions>
 16:             <ColumnDefinition/>
 17:             <ColumnDefinition/>
 18:         </Grid.ColumnDefinitions>
 19:         <TextBlock Grid.Column="0" Grid.Row="0" Margin="5" VerticalAlignment="Center">Enter Cost of Fixed Asset</TextBlock>
 20:         <TextBox Grid.Column="1" Grid.Row="0" Margin="5" VerticalAlignment="Center" Name="txtCost"></TextBox>
 21:         <TextBlock Grid.Column="0" Grid.Row="1" Margin="5" VerticalAlignment="Center">Enter life Span</TextBlock>
 22:         <TextBox Grid.Column="1" Grid.Row="1" Margin="5" VerticalAlignment="Center" Name="txtYear"></TextBox>
 23:         <TextBlock Grid.Column="0" Grid.Row="2" Margin="5" VerticalAlignment="Center">Enter Scrap Value</TextBlock>
 24:         <TextBox Grid.Column="1" Grid.Row="2" Margin="5" VerticalAlignment="Center" Name="txtScrapValue"></TextBox>
 25: 
 26:         <ListView Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2" Name="list" Margin="5" HorizontalContentAlignment="Stretch">
 27:             <ListView.View>
 28:                 <GridView>
 29:                     <GridView.ColumnHeaderTemplate>
 30:                         <DataTemplate>
 31:                             <Border BorderBrush="Brown" BorderThickness="2" CornerRadius="5">
 32:                                 <Border.Background>
 33:                                     <LinearGradientBrush>
 34:                                         <GradientStop Offset="0" Color="Wheat"/>
 35:                                         <GradientStop Offset="1" Color="LightCoral"/>
 36:                                     </LinearGradientBrush>
 37:                                 </Border.Background>
 38:                                 <TextBlock Foreground="Blue" FontSize="14" FontWeight="Bold" Margin="5" Text="{Binding}" Width="Auto"/>
 39:                             </Border>
 40:                         </DataTemplate>
 41:                     </GridView.ColumnHeaderTemplate>
 42:                     <GridViewColumn Width="Auto" Header="Year" DisplayMemberBinding="{Binding Path=Year}"/>
 43:                     <GridViewColumn Width="Auto" Header="Depreciation" DisplayMemberBinding="{Binding Path=Depreciation}"/>
 44:                     <GridViewColumn Width="Auto" Header="Accumulated Depreciation" DisplayMemberBinding="{Binding Path=AccDepreciation}"/>
 45:                     <GridViewColumn Width="Auto" Header="Book Value" DisplayMemberBinding="{Binding Path=BookValue}"/>
 46:                     <GridViewColumn Width="Auto" Header="Percentage">
 47:                         <GridViewColumn.CellTemplate>
 48:                             <DataTemplate>
 49:                                 <ProgressBar Width="50" Height="20" Margin="5" Minimum="0" Maximum="100" Value="{Binding Percentage}"/>
 50:                             </DataTemplate>
 51:                         </GridViewColumn.CellTemplate>
 52:                     </GridViewColumn>
 53:                 </GridView>
 54:             </ListView.View>
 55:         </ListView>
 56:         <Button Grid.Column="0" Grid.Row="4" Margin="10" Width="75" Name="btnCalculate" Click="btnCalculate_Click">Calculate</Button>
 57:         <Button Grid.Column="1" Grid.Row="4" Margin="10" Width="75" Name="btnExit" Click="btnExit_Click">Exit</Button>
 58:     </Grid>
 59: </Window>
 60: 

Here is complete C# code of the project.

  1: using System;
  2: using System.Collections.Generic;
  3: using System.Linq;
  4: using System.Text;
  5: using System.Windows;
  6: using System.Windows.Controls;
  7: using System.Windows.Data;
  8: using System.Windows.Documents;
  9: using System.Windows.Input;
 10: using System.Windows.Media;
 11: using System.Windows.Media.Imaging;
 12: using System.Windows.Navigation;
 13: using System.Windows.Shapes;
 14: 
 15: namespace Depreciation
 16: {
 17:     /// <summary>
 18:     /// Interaction logic for Window1.xaml
 19:     /// </summary>
 20:     public partial class Window1 : Window
 21:     {
 22:         List<DepreciationInfo> depreciation;
 23:         private int year;
 24:         private double cost;
 25:         private double scrap;
 26: 
 27:         public Window1()
 28:         {
 29:             InitializeComponent();
 30: 
 31:             depreciation = new List<DepreciationInfo>();
 32:         }
 33: 
 34:         private void btnExit_Click(object sender, RoutedEventArgs e)
 35:         {
 36:             Close();
 37:         }
 38: 
 39:         private void btnCalculate_Click(object sender, RoutedEventArgs e)
 40:         {
 41:             depreciation.Clear();
 42: 
 43:             year = Convert.ToInt32(txtYear.Text);
 44:             cost = Convert.ToDouble(txtCost.Text);
 45:             scrap = Convert.ToDouble(txtScrapValue.Text);
 46: 
 47:             if (year <= 0)
 48:             {
 49:                 MessageBox.Show("Number of years can not be zero or negative.");
 50:                 return;
 51:             }
 52: 
 53:             if (cost <= 0 || scrap <= 0)
 54:             {
 55:                 MessageBox.Show("Either Cost or Scrap value is not correct.");
 56:                 return;
 57:             }
 58: 
 59:             double percentage = 100 / year;
 60:             percentage /= 100;
 61:             double accDepreciation = 0;
 62:             double bookValue = cost;
 63:             double depExpense = 0;
 64: 
 65:             for (int iIndex = 0; iIndex < year; iIndex++)
 66:             {
 67:                 depExpense = bookValue * percentage * 2;
 68:                               
 69:                 if (bookValue - depExpense < scrap)
 70:                 {
 71:                     depExpense = bookValue - scrap;
 72:                     bookValue = scrap;
 73:                 }
 74:                 else
 75:                 {
 76:                     bookValue -= depExpense;
 77:                 }
 78: 
 79:                 accDepreciation += depExpense;
 80: 
 81:                 DepreciationInfo dpInfo = new DepreciationInfo();
 82:                 dpInfo.Year = (iIndex + 1);
 83:                 dpInfo.Depreciation = depExpense;
 84:                 dpInfo.AccDepreciation = accDepreciation;
 85:                 dpInfo.BookValue = bookValue;
 86:                 dpInfo.Percentage = (bookValue * 100) / cost; ;
 87: 
 88:                 depreciation.Add(dpInfo);
 89:             }
 90: 
 91:             list.ItemsSource = depreciation;
 92:         }
 93:     }
 94: 
 95:     public class DepreciationInfo
 96:     {
 97:         public int Year
 98:         { get; set; }
 99: 
100:         public double Depreciation
101:         { get; set; }
102: 
103:         public double AccDepreciation
104:         { get; set; }
105: 
106:         public double BookValue
107:         { get; set; }
108: 
109:         public double Percentage
110:         { get; set; }
111:     }
112: }
113: 

Here is the output of the program.

DepreciationOutput

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: