Home

F# Example Application: Depreciation - Units of Production

   

Introduction

The units-of-production method is a technique to calculate the depreciation of a machine used to conduct business. This method uses some primiary criteria based on the type of the machine or how the machine is used. Factors could include the number of products manufactured using the machine, of the number of miles driven using the machine, of the number of hours the machine operated, etc.

Here is an example application that calculates the depreciation using the units-of-production method:

open System
open System.Drawing
open System.Windows.Forms 

let mutable temporary = []

type MachineUsageDepreciation(cost, salvage, life, usage : int array) =
    let mutable hrs : int array = usage
    let mutable counter = 0

    member this.HourlyDepreciation with get() = (cost - salvage) / life
    member this.Operations with get() = hrs and set(hours) = hrs <- hours
    member this.YearlyDepreciation with get() = [| for nbr in hrs do yield float nbr * this.HourlyDepreciation |]
    member this.DepreciationSchedule with get() =
                                        [| for n in hrs do yield (float n, float n * this.HourlyDepreciation) |]

    new(cost, salvage, life) = MachineUsageDepreciation(cost, salvage, life, [||])

let unitsOfProduction : Form = new Form(MaximizeBox = false, Text = "Depreciation: Units of Production", ClientSize = new System.Drawing.Size(325, 370), StartPosition = FormStartPosition.CenterScreen)

unitsOfProduction.Controls.Add(new Label(Location = new Point(21, 25), AutoSize = true, Text = "Machine Cost:"))
let txtMachineCost : TextBox = new TextBox(Location = new Point(130, 22), Text = "0.00", TextAlign = HorizontalAlignment.Right, Width = 75)
unitsOfProduction.Controls.Add txtMachineCost

unitsOfProduction.Controls.Add(new Label(Location = new Point(21, 54), AutoSize = true, Text = "Salvage Value:"))
let txtSalvageValue : TextBox = new TextBox(Location = new Point(130, 51), Text = "0.00", TextAlign = HorizontalAlignment.Right, Width = 75)
unitsOfProduction.Controls.Add txtSalvageValue

unitsOfProduction.Controls.Add(new Label(Location = new Point(21, 83), AutoSize = true, Text = "Estimated Life:"))
let txtEstimatedLife : TextBox = new TextBox(Location = new Point(130, 80), Text = "0.00", TextAlign = HorizontalAlignment.Right, Width = 52)
unitsOfProduction.Controls.Add txtEstimatedLife
unitsOfProduction.Controls.Add(new Label(Location = new Point(187, 83), AutoSize = true, Text = "Hours"))

let lblLine = new Label(Location = new Point(21, 105), AutoSize = true)
lblLine.Text <- "Yearly Operations ________________________________"
unitsOfProduction.Controls.Add lblLine

unitsOfProduction.Controls.Add(new Label(Location = new Point(21, 135), AutoSize = true, Text = "Year:"))
let txtYearlyHours : TextBox = new TextBox(Location = new Point(130, 132), Text = "0.00", TextAlign = HorizontalAlignment.Right, Width = 52)
unitsOfProduction.Controls.Add txtYearlyHours
unitsOfProduction.Controls.Add(new Label(Location = new Point(187, 135), AutoSize = true, Text = "Hours/Year"))

unitsOfProduction.Controls.Add(new Label(Location = new Point(21, 83), AutoSize = true, Text = "Estimated Life:"))

unitsOfProduction.Controls.Add(new Label(Location = new Point(21, 209), AutoSize = true, Text = "Hourly Depreciation:"))
let txtHourlyDepreciation : TextBox = new TextBox(Location = new Point(130, 206), Text = "0.00", TextAlign = HorizontalAlignment.Right, Width = 52)
unitsOfProduction.Controls.Add txtHourlyDepreciation
unitsOfProduction.Controls.Add(new Label(Location = new Point(187, 209), AutoSize = true, Text = "/Hour"))

unitsOfProduction.Controls.Add(new Label(Location = new Point(55, 240), AutoSize = true, Text = "Depreciation Schedule:"))

let lvwDepreciationSchedule : ListView = new ListView(Location = new Point(50, 258), Size = new System.Drawing.Size(225, 95), GridLines = true, View = View.Details, FullRowSelect = true)
lvwDepreciationSchedule.Columns.Add("Year", 40) |> ignore
lvwDepreciationSchedule.Columns.Add("Usage", 95, HorizontalAlignment.Center) |> ignore
lvwDepreciationSchedule.Columns.Add("Depreciation", 85, HorizontalAlignment.Right) |> ignore

unitsOfProduction.Controls.Add lvwDepreciationSchedule

let btnAdd : Button = new Button(Location = new Point(255, 130), Width = 50, Text = "Add")
let btnAddClick e =
    temporary <- temporary @ [ int txtYearlyHours.Text ]

    txtYearlyHours.Text <- "0.00"
    txtYearlyHours.Focus() |> ignore

btnAdd.Click.Add btnAddClick
unitsOfProduction.Controls.Add btnAdd

let btnCalculate : Button = new Button(Location = new Point(24, 163), Size = new System.Drawing.Size(280, 31), Text = "Calculate")
let btnCalculateClick e =
    let machineCost   = float txtMachineCost.Text
    let salvageValue  = float txtSalvageValue.Text
    let estimatedLife = float txtEstimatedLife.Text

    let timesUsed = List.toArray temporary

    let depreciation = new MachineUsageDepreciation(machineCost, salvageValue, estimatedLife, timesUsed)
    txtHourlyDepreciation.Text <- sprintf "%0.03f" depreciation.HourlyDepreciation

    lvwDepreciationSchedule.Items.Clear()

    let mutable year = 1
    for usage in depreciation.DepreciationSchedule do
        let (hour, depreciation) = usage

        let lviDepreciation = new ListViewItem(sprintf "%i" year)
        lviDepreciation.SubItems.Add(sprintf "%0.0f Hours/Year" hour) |> ignore
        lviDepreciation.SubItems.Add(sprintf "$%0.0f" depreciation) |> ignore
        lvwDepreciationSchedule.Items.Add lviDepreciation |> ignore
        year <- year + 1
btnCalculate.Click.Add btnCalculateClick
unitsOfProduction.Controls.Add btnCalculate

[<EntryPoint>]
let main argv =
    Application.Run unitsOfProduction
     
 

Here is an example of testing the program:

A List as a Property A List as a Property
A List as a Property A List as a Property
A List as a Property A List as a Property
A List as a Property
   
   
   
 

Home Copyright © 2015, FunctionX Home