Added depreciations

This commit is contained in:
snipe
2013-11-15 23:46:03 -05:00
parent 31b90cf2a3
commit 32eb9d1d30
16 changed files with 512 additions and 14 deletions
+11 -8
View File
@@ -7,6 +7,7 @@ use Asset;
use Redirect;
use DB;
use Model;
use Depreciation;
use Sentry;
use Str;
use Validator;
@@ -39,7 +40,8 @@ class AssetsController extends AdminController {
{
// Grab the dropdown list of models
$model_list = array('0' => 'Select') + Model::lists('name', 'id');
return View::make('backend/assets/create')->with('model_list',$model_list);
$depreciation_list = array('' => 'Do Not Depreciate') + Depreciation::lists('name', 'id');
return View::make('backend/assets/create')->with('model_list',$model_list)->with('depreciation_list',$depreciation_list);
}
@@ -77,11 +79,11 @@ class AssetsController extends AdminController {
$asset->name = e(Input::get('name'));
$asset->serial = e(Input::get('serial'));
$asset->model_id = e(Input::get('model_id'));
$asset->purchase_date = e(Input::get('purchase_date'));
$asset->purchase_cost = e(Input::get('purchase_cost'));
$asset->purchase_date = e(Input::get('purchase_date'));
$asset->purchase_cost = e(Input::get('purchase_cost'));
$asset->order_number = e(Input::get('order_number'));
$asset->notes = e(Input::get('notes'));
$asset->asset_tag = e(Input::get('asset_tag'));
$asset->asset_tag = e(Input::get('asset_tag'));
$asset->user_id = Sentry::getId();
@@ -113,7 +115,8 @@ class AssetsController extends AdminController {
// Grab the dropdown list of models
$model_list = array('0' => 'Select') + Model::lists('name', 'id');
return View::make('backend/assets/edit', compact('asset'))->with('model_list',$model_list);
$depreciation_list = array('' => 'Do Not Depreciate') + Depreciation::lists('name', 'id');
return View::make('backend/assets/edit', compact('asset'))->with('model_list',$model_list)->with('depreciation_list',$depreciation_list);
}
@@ -154,10 +157,10 @@ class AssetsController extends AdminController {
$asset->name = e(Input::get('name'));
$asset->serial = e(Input::get('serial'));
$asset->model_id = e(Input::get('model_id'));
$asset->purchase_date = e(Input::get('purchase_date'));
$asset->purchase_cost = e(Input::get('purchase_cost'));
$asset->purchase_date = e(Input::get('purchase_date'));
$asset->purchase_cost = e(Input::get('purchase_cost'));
$asset->order_number = e(Input::get('order_number'));
$asset->asset_tag = e(Input::get('asset_tag'));
$asset->asset_tag = e(Input::get('asset_tag'));
$asset->notes = e(Input::get('notes'));
@@ -0,0 +1,178 @@
<?php namespace Controllers\Admin;
use AdminController;
use Input;
use Lang;
use Depreciation;
use Redirect;
use DB;
use Sentry;
use Str;
use Validator;
use View;
class DepreciationsController extends AdminController {
/**
* Show a list of all the depreciations.
*
* @return View
*/
public function getIndex()
{
// Grab all the depreciations
$depreciations = Depreciation::orderBy('created_at', 'DESC')->paginate(10);
// Show the page
return View::make('backend/depreciations/index', compact('depreciations'));
}
/**
* Depreciation create.
*
* @return View
*/
public function getCreate()
{
// Show the page
$depreciation_options = array('0' => 'Top Level') + Depreciation::lists('name', 'id');
return View::make('backend/depreciations/create')->with('depreciation_options',$depreciation_options);
}
/**
* Depreciation create form processing.
*
* @return Redirect
*/
public function postCreate()
{
// Declare the rules for the form validation
$rules = array(
'name' => 'required|min:3',
);
// Create a new validator instance from our validation rules
$validator = Validator::make(Input::all(), $rules);
// If validation fails, we'll exit the operation now.
if ($validator->fails())
{
// Ooops.. something went wrong
return Redirect::back()->withInput()->withErrors($validator);
}
// Create a new depreciation
$depreciation = new Depreciation;
// Update the depreciation data
$depreciation->name = e(Input::get('name'));
$depreciation->months = e(Input::get('months'));
$depreciation->user_id = Sentry::getId();
// Was the depreciation created?
if($depreciation->save())
{
// Redirect to the new depreciation page
return Redirect::to("admin/settings/depreciations")->with('success', Lang::get('admin/depreciations/message.create.success'));
}
// Redirect to the depreciation create page
return Redirect::to('admin/settings/depreciations/create')->with('error', Lang::get('admin/depreciations/message.create.error'));
}
/**
* Depreciation update.
*
* @param int $depreciationId
* @return View
*/
public function getEdit($depreciationId = null)
{
// Check if the depreciation exists
if (is_null($depreciation = Depreciation::find($depreciationId)))
{
// Redirect to the blogs management page
return Redirect::to('admin/settings/depreciations')->with('error', Lang::get('admin/depreciations/message.does_not_exist'));
}
// Show the page
//$depreciation_options = array('' => 'Top Level') + Depreciation::lists('name', 'id');
$depreciation_options = array('' => 'Top Level') + DB::table('depreciations')->where('id', '!=', $depreciationId)->lists('name', 'id');
return View::make('backend/depreciations/edit', compact('depreciation'))->with('depreciation_options',$depreciation_options);
}
/**
* Depreciation update form processing page.
*
* @param int $depreciationId
* @return Redirect
*/
public function postEdit($depreciationId = null)
{
// Check if the blog post exists
if (is_null($depreciation = Depreciation::find($depreciationId)))
{
// Redirect to the blogs management page
return Redirect::to('admin/settings/depreciations')->with('error', Lang::get('admin/depreciations/message.does_not_exist'));
}
// Declare the rules for the form validation
$rules = array(
'name' => 'required|min:3',
);
// Create a new validator instance from our validation rules
$validator = Validator::make(Input::all(), $rules);
// If validation fails, we'll exit the operation now.
if ($validator->fails())
{
// Ooops.. something went wrong
return Redirect::back()->withInput()->withErrors($validator);
}
// Update the depreciation data
$depreciation->name = e(Input::get('name'));
$depreciation->months = e(Input::get('months'));
// Was the depreciation updated?
if($depreciation->save())
{
// Redirect to the new depreciation page
return Redirect::to("admin/settings/depreciations/$depreciationId/edit")->with('success', Lang::get('admin/depreciations/message.update.success'));
}
// Redirect to the depreciation management page
return Redirect::to("admin/settings/depreciations/$depreciationID/edit")->with('error', Lang::get('admin/depreciations/message.update.error'));
}
/**
* Delete the given depreciation.
*
* @param int $depreciationId
* @return Redirect
*/
public function getDelete($depreciationId)
{
// Check if the blog post exists
if (is_null($depreciation = Depreciation::find($depreciationId)))
{
// Redirect to the blogs management page
return Redirect::to('admin/settings/depreciations')->with('error', Lang::get('admin/depreciations/message.not_found'));
}
// Delete the blog post
$depreciation->delete();
// Redirect to the blog posts management page
return Redirect::to('admin/settings/depreciations')->with('success', Lang::get('admin/depreciations/message.delete.success'));
}
}
@@ -18,6 +18,7 @@ class CreateLicensesTable extends Migration {
$table->integer('model_id');
$table->string('serial');
$table->string('license_email');
$table->string('license_name');
$table->date('purchase_date')->nullable();
$table->decimal('purchase_cost', 8, 2)->nullable();
$table->string('order_number');
@@ -11,10 +11,7 @@ class AddLicenseNameToLicenses extends Migration {
*/
public function up()
{
Schema::table('licenses', function($table)
{
$table->string('license_name');
});
}
/**
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
class CreateDepreciationsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('depreciations', function($table)
{
$table->increments('id');
$table->string('name');
$table->integer('months');
$table->timestamps();
$table->integer('user_id');
//$table->foreign('user_id')->references('id')->on('users');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('depreciations');
}
}
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
class AddDepreciationIdToModels extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('models', function($table)
{
$table->integer('depreciation_id')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
return array(
'does_not_exist' => 'Depreciation class does not exist.',
'create' => array(
'error' => 'Depreciation class was not created, please try again. :(',
'success' => 'Depreciation class created successfully. :)'
),
'update' => array(
'error' => 'Depreciation class was not updated, please try again',
'success' => 'Depreciation class updated successfully.'
),
'delete' => array(
'error' => 'There was an issue deleting the depreciation class. Please try again.',
'success' => 'The depreciation class was deleted successfully.'
)
);
+10
View File
@@ -0,0 +1,10 @@
<?php
return array(
'id' => 'ID',
'title' => 'Name ',
'months' => 'Months',
'term' => 'Term',
);
+23
View File
@@ -0,0 +1,23 @@
<?php
class Depreciation extends Eloquent {
/**
* Deletes a depreciation
*
* @return bool
*/
protected $table = 'depreciations';
public function delete()
{
// Delete the depreciation
return parent::delete();
}
}
+12
View File
@@ -99,6 +99,18 @@ Route::group(array('prefix' => 'admin'), function()
Route::get('{categoryId}/delete', array('as' => 'delete/category', 'uses' => 'Controllers\Admin\CategoriesController@getDelete'));
});
# Depreciations
Route::group(array('prefix' => 'depreciations'), function()
{
Route::get('/', array('as' => 'depreciations', 'uses' => 'Controllers\Admin\DepreciationsController@getIndex'));
Route::get('create', array('as' => 'create/depreciations', 'uses' => 'Controllers\Admin\DepreciationsController@getCreate'));
Route::post('create', 'Controllers\Admin\DepreciationsController@postCreate');
Route::get('{depreciationId}/edit', array('as' => 'update/depreciations', 'uses' => 'Controllers\Admin\DepreciationsController@getEdit'));
Route::post('{depreciationId}/edit', 'Controllers\Admin\DepreciationsController@postEdit');
Route::get('{depreciationId}/delete', array('as' => 'delete/depreciations', 'uses' => 'Controllers\Admin\DepreciationsController@getDelete'));
});
@@ -89,6 +89,15 @@ Create a New Asset ::
</div>
</div>
<!-- Depreciation -->
<div class="control-group {{ $errors->has('depreciation_id') ? 'error' : '' }}">
<label class="control-label" for="parent">Depreciation</label>
<div class="controls">
{{ Form::select('depreciation_id', $model_list , Input::old('depreciation_id')) }}
{{ $errors->first('depreciation_id', '<span class="help-inline">:message</span>') }}
</div>
</div>
<!-- Notes -->
<div class="control-group {{ $errors->has('notes') ? 'error' : '' }}">
<label class="control-label" for="notes">Notes</label>
+9
View File
@@ -93,6 +93,15 @@ Asset Update ::
</div>
</div>
<!-- Depreciation -->
<div class="control-group {{ $errors->has('depreciation_id') ? 'error' : '' }}">
<label class="control-label" for="parent">Depreciation</label>
<div class="controls">
{{ Form::select('depreciation_id', $depreciation_list , Input::old('depreciation_id', $asset->depreciation_id)) }}
{{ $errors->first('depreciation_id', '<span class="help-inline">:message</span>') }}
</div>
</div>
<!-- Notes -->
<div class="control-group {{ $errors->has('notes') ? 'error' : '' }}">
<label class="control-label" for="notes">Notes</label>
+2 -2
View File
@@ -23,8 +23,8 @@ Assets ::
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th class="span4">@lang('admin/assets/table.title')</th>
<th class="span2">@lang('admin/assets/table.asset_tag')</th>
<th class="span4">@lang('admin/assets/table.title')</th>
<th class="span2">@lang('admin/assets/table.serial')</th>
<th class="span2">@lang('admin/assets/table.status')</th>
<th class="span2">@lang('admin/assets/table.purchase_date')</th>
@@ -36,8 +36,8 @@ Assets ::
<tbody>
@foreach ($assets as $asset)
<tr>
<td>{{ $asset->name }}</td>
<td>{{ $asset->asset_tag }}</td>
<td>{{ $asset->name }}</td>
<td>{{ $asset->serial }}</td>
<td>{{ $asset->status }}</td>
<td>{{ $asset->purchase_date }}</td>
+58
View File
@@ -0,0 +1,58 @@
@extends('backend/layouts/default')
{{-- Page title --}}
@section('title')
Create a New Depreciation Class ::
@parent
@stop
{{-- Page content --}}
@section('content')
<div class="page-header">
<h3>
Create a Depreciation Class
<div class="pull-right">
<a href="{{ route('depreciations') }}" class="btn btn-small btn-inverse"><i class="icon-circle-arrow-left icon-white"></i> Back</a>
</div>
</h3>
</div>
<form class="form-horizontal" method="post" action="" autocomplete="off">
<!-- CSRF Token -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<!-- Tabs Content -->
<div class="tab-content">
<div class="tab-pane active" id="tab-general">
<!-- Class Title -->
<div class="control-group {{ $errors->has('name') ? 'error' : '' }}">
<label class="control-label" for="name">Depreciation Class Name</label>
<div class="controls">
<input class="span6" type="text" name="name" id="name" value="{{ Input::old('name') }}" />
{{ $errors->first('name', '<span class="help-inline">:message</span>') }}
</div>
</div>
<!-- Months -->
<div class="control-group {{ $errors->has('months') ? 'error' : '' }}">
<label class="control-label" for="name">Number of Months</label>
<div class="controls">
<input class="span6" type="text" name="months" id="months" value="{{ Input::old('months') }}" />
{{ $errors->first('months', '<span class="help-inline">:message</span>') }}
</div>
</div>
</div>
<!-- Form actions -->
<div class="control-group">
<div class="controls">
<a class="btn btn-link" href="{{ route('depreciations') }}">Cancel</a>
<button type="submit" class="btn btn-success">Save</button>
</div>
</div>
</form>
@stop
+60
View File
@@ -0,0 +1,60 @@
@extends('backend/layouts/default')
{{-- Page title --}}
@section('title')
Update Depreciation Class ::
@parent
@stop
{{-- Page content --}}
@section('content')
<div class="page-header">
<h3>
Update Depreciation Class
<div class="pull-right">
<a href="{{ route('depreciations') }}" class="btn btn-small btn-inverse"><i class="icon-circle-arrow-left icon-white"></i> Back</a>
</div>
</h3>
</div>
<form class="form-horizontal" method="post" action="" autocomplete="off">
<!-- CSRF Token -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<!-- Tabs Content -->
<div class="tab-content">
<div class="tab-pane active" id="tab-general">
<!-- Class Title -->
<div class="control-group {{ $errors->has('name') ? 'error' : '' }}">
<label class="control-label" for="name">Depreciation Class Name</label>
<div class="controls">
<input class="span6" type="text" name="name" id="name" value="{{ Input::old('name', $depreciation->name) }}" />
{{ $errors->first('name', '<span class="help-inline">:message</span>') }}
</div>
</div>
<!-- Months -->
<div class="control-group {{ $errors->has('months') ? 'error' : '' }}">
<label class="control-label" for="name">Number of Months</label>
<div class="controls">
<input class="span6" type="text" name="months" id="months" value="{{ Input::old('months', $depreciation->months) }}" />
{{ $errors->first('months', '<span class="help-inline">:message</span>') }}
</div>
</div>
</div>
<!-- Form actions -->
<div class="control-group">
<div class="controls">
<a class="btn btn-link" href="{{ route('depreciations') }}">Cancel</a>
<button type="submit" class="btn btn-success">Save</button>
</div>
</div>
</form>
@stop
+51
View File
@@ -0,0 +1,51 @@
@extends('backend/layouts/default')
{{-- Page title --}}
@section('title')
Asset Depreciations ::
@parent
@stop
{{-- Page content --}}
@section('content')
<div class="page-header">
<h3>
Asset Depreciations
<div class="pull-right">
<a href="{{ route('create/depreciations') }}" class="btn btn-small btn-info"><i class="icon-plus-sign icon-white"></i> Create</a>
</div>
</h3>
</div>
@if (count($depreciations) > 10)
{{ $depreciations->links() }}
@endif
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th class="span6">@lang('admin/depreciations/table.title')</th>
<th class="span6">@lang('admin/depreciations/table.term')</th>
<th class="span2">@lang('table.actions')</th>
</tr>
</thead>
<tbody>
@foreach ($depreciations as $depreciation)
<tr>
<td>{{ $depreciation->name }}</td>
<td>{{ $depreciation->months }} @lang('admin/depreciations/table.months') </td>
<td>
<a href="{{ route('update/depreciations', $depreciation->id) }}" class="btn btn-mini">@lang('button.edit')</a>
<a href="{{ route('delete/depreciations', $depreciation->id) }}" class="btn btn-mini btn-danger">@lang('button.delete')</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@if (count($depreciations) > 10)
{{ $depreciations->links() }}
@endif
@stop