Example #1
1
 /**
  * Handle depreciation
  */
 public function depreciate()
 {
     $depreciation_id = Model::find($this->model_id)->depreciation_id;
     if ($depreciation_id) {
         $depreciation_term = Depreciation::find($depreciation_id)->months;
         if ($depreciation_term > 0) {
             $purchase_date = strtotime($this->purchase_date);
             $todaymonthnumber = date("Y") * 12 + (date("m") - 1);
             //calculate the month number for today as YEAR*12 + (months-1) - number of months since January year 0
             $purchasemonthnumber = date("Y", $purchase_date) * 12 + (date("m", $purchase_date) - 1);
             //purchase date calculated similarly
             $diff_months = $todaymonthnumber - $purchasemonthnumber;
             // fraction of value left
             $current_value = round(($depreciation_term - $diff_months) / $depreciation_term * $this->purchase_cost, 2);
             if ($current_value < 0) {
                 $current_value = 0;
             }
             return $current_value;
         } else {
             return $this->purchase_cost;
         }
     } else {
         return $this->purchase_cost;
     }
 }
Example #2
1
function depreciationList()
{
    $depreciation_list = array('' => 'Do Not Depreciate') + Depreciation::orderBy('name', 'asc')->lists('name', 'id');
    return $depreciation_list;
}
 public function run()
 {
     // Initialize empty array
     $depreciation = array();
     $date = new DateTime();
     $depreciation[] = array('name' => 'Computers', 'months' => '36', 'created_at' => $date->modify('-10 day'), 'updated_at' => $date->modify('-3 day'), 'user_id' => 1);
     $date = new DateTime();
     $depreciation[] = array('name' => 'Software', 'months' => '36', 'created_at' => $date->modify('-10 day'), 'updated_at' => $date->modify('-3 day'), 'user_id' => 1);
     $date = new DateTime();
     $depreciation[] = array('name' => 'Office Equipment', 'months' => '36', 'created_at' => $date->modify('-10 day'), 'updated_at' => $date->modify('-3 day'), 'user_id' => 1);
     // Delete all the old data
     DB::table('depreciations')->truncate();
     // Insert the new data
     Depreciation::insert($depreciation);
 }