A free open source IT asset/license management system
Add model_no, item_no, and manufacturer to consumables
snipee552c36a0a21
diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.phpindex 23bc39057e..a3a3899192 100644--- a/app/Http/Controllers/ConsumablesController.php+++ b/app/Http/Controllers/ConsumablesController.php@@ -55,12 +55,14 @@ class ConsumablesController extends Controller$category_list = array('' => '') + DB::table('categories')->where('category_type', '=', 'consumable')->whereNull('deleted_at')->orderBy('name', 'ASC')->lists('name', 'id');$company_list = Helper::companyList();$location_list = Helper::locationsList();+ $manufacturer_list = Helper::manufacturerList();return View::make('consumables/edit')->with('consumable', new Consumable)->with('category_list', $category_list)->with('company_list', $company_list)- ->with('location_list', $location_list);+ ->with('location_list', $location_list)+ ->with('manufacturer_list', $manufacturer_list);}@@ -81,6 +83,9 @@ class ConsumablesController extends Controller$consumable->company_id = Company::getIdForCurrentUser(Input::get('company_id'));$consumable->order_number = e(Input::get('order_number'));$consumable->min_amt = e(Input::get('min_amt'));+ $consumable->manufacturer_id = e(Input::get('manufacturer_id'));+ $consumable->model_no = e(Input::get('model_no'));+ $consumable->item_no = e(Input::get('item_no'));if (e(Input::get('purchase_date')) == '') {$consumable->purchase_date = null;@@ -130,11 +135,13 @@ class ConsumablesController extends Controller$category_list = Helper::categoryList();$company_list = Helper::companyList();$location_list = Helper::locationsList();+ $manufacturer_list = Helper::manufacturerList();return View::make('consumables/edit', compact('consumable'))->with('category_list', $category_list)->with('company_list', $company_list)- ->with('location_list', $location_list);+ ->with('location_list', $location_list)+ ->with('manufacturer_list', $manufacturer_list);}@@ -161,6 +168,9 @@ class ConsumablesController extends Controller$consumable->company_id = Company::getIdForCurrentUser(Input::get('company_id'));$consumable->order_number = e(Input::get('order_number'));$consumable->min_amt = e(Input::get('min_amt'));+ $consumable->manufacturer_id = e(Input::get('manufacturer_id'));+ $consumable->model_no = e(Input::get('model_no'));+ $consumable->item_no = e(Input::get('item_no'));if (e(Input::get('purchase_date')) == '') {$consumable->purchase_date = null;@@ -407,7 +417,7 @@ class ConsumablesController extends Controller$limit = 50;}- $allowed_columns = ['id','name','order_number','min_amt','purchase_date','purchase_cost','companyName','category'];+ $allowed_columns = ['id','name','order_number','min_amt','purchase_date','purchase_cost','companyName','category','model_no', 'item_no', 'manufacturer'];$order = Input::get('order') === 'asc' ? 'asc' : 'desc';$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';@@ -418,6 +428,9 @@ class ConsumablesController extends Controllercase 'location':$consumables = $consumables->OrderLocation($order);break;+ case 'manufacturer':+ $consumables = $consumables->OrderManufacturer($order);+ break;case 'companyName':$consumables = $consumables->OrderCompany($order);break;@@ -441,6 +454,9 @@ class ConsumablesController extends Controller'location' => ($consumable->location) ? e($consumable->location->name) : '','min_amt' => e($consumable->min_amt),'qty' => e($consumable->qty),+ 'manufacturer' => ($consumable->manufacturer) ? e($consumable->manufacturer->name) : '',+ 'model_no' => e($consumable->model_no),+ 'item_no' => e($consumable->item_no),'category' => ($consumable->category) ? e($consumable->category->name) : 'Missing category','order_number' => e($consumable->order_number),'purchase_date' => e($consumable->purchase_date),diff --git a/app/Models/Consumable.php b/app/Models/Consumable.phpindex 965e5ce5ef..3b89592875 100644--- a/app/Models/Consumable.php+++ b/app/Models/Consumable.php@@ -64,6 +64,11 @@ class Consumable extends Modelreturn $this->belongsTo('\App\Models\Company', 'company_id');}+ public function manufacturer()+ {+ return $this->belongsTo('\App\Models\Manufacturer', 'manufacturer_id');+ }+public function location(){return $this->belongsTo('\App\Models\Location', 'location_id');@@ -155,6 +160,10 @@ class Consumable extends Model$query->whereHas('location', function ($query) use ($search) {$query->where('locations.name', 'LIKE', '%'.$search.'%');});+ })->orWhere(function ($query) use ($search) {+ $query->whereHas('manufacturer', function ($query) use ($search) {+ $query->where('manufacturers.name', 'LIKE', '%'.$search.'%');+ });})->orWhere('consumables.name', 'LIKE', '%'.$search.'%')->orWhere('consumables.order_number', 'LIKE', '%'.$search.'%')->orWhere('consumables.purchase_cost', 'LIKE', '%'.$search.'%')@@ -177,7 +186,7 @@ class Consumable extends Model}/**- * Query builder scope to order on company+ * Query builder scope to order on location** @param Illuminate\Database\Query\Builder $query Query builder instance* @param text $order Order@@ -189,6 +198,19 @@ class Consumable extends Modelreturn $query->leftJoin('locations', 'consumables.location_id', '=', 'locations.id')->orderBy('locations.name', $order);}+ /**+ * Query builder scope to order on manufacturer+ *+ * @param Illuminate\Database\Query\Builder $query Query builder instance+ * @param text $order Order+ *+ * @return Illuminate\Database\Query\Builder Modified query builder+ */+ public function scopeOrderManufacturer($query, $order)+ {+ return $query->leftJoin('manufacturers', 'consumables.manufacturer_id', '=', 'manufacturers.id')->orderBy('manufacturers.name', $order);+ }+/*** Query builder scope to order on companydiff --git a/database/migrations/2016_05_16_164733_add_model_mfg_to_consumable.php b/database/migrations/2016_05_16_164733_add_model_mfg_to_consumable.phpnew file mode 100644index 0000000000..182eedae49--- /dev/null+++ b/database/migrations/2016_05_16_164733_add_model_mfg_to_consumable.php@@ -0,0 +1,37 @@+<?php++use Illuminate\Database\Schema\Blueprint;+use Illuminate\Database\Migrations\Migration;++class AddModelMfgToConsumable extends Migration+{+ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {+ Schema::table('consumables', function (Blueprint $table) {+ $table->integer('model_no')->nullable()->default(NULL);+ $table->integer('manufacturer_id')->nullable()->default(NULL);+ $table->string('item_no')->nullable()->default(NULL);+ });+ }++ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ Schema::table('consumables', function ($table) {+ $table->dropColumn(+ 'model_no',+ 'manufacturer_id',+ 'item_no'+ );+ });+ }+}diff --git a/resources/lang/en/admin/consumables/general.php b/resources/lang/en/admin/consumables/general.phpindex b29947f13a..8fd9d4f97f 100644--- a/resources/lang/en/admin/consumables/general.php+++ b/resources/lang/en/admin/consumables/general.php@@ -7,6 +7,7 @@ return array('cost' => 'Purchase Cost','create' => 'Create Consumable','date' => 'Purchase Date',+ 'item_no' => 'Item No.','order' => 'Order Number','remaining' => 'Remaining','total' => 'Total',diff --git a/resources/views/consumables/edit.blade.php b/resources/views/consumables/edit.blade.phpindex e6689e681d..9e00195c4f 100644--- a/resources/views/consumables/edit.blade.php+++ b/resources/views/consumables/edit.blade.php@@ -79,6 +79,18 @@</div></div>+ <!-- Manufacturer -->+ <div class="form-group {{ $errors->has('manufacturer_id') ? ' has-error' : '' }}">+ <div class="col-md-3">+ {{ Form::label('manufacturer_id', trans('general.manufacturer')) }}++ </div>+ <div class="col-md-7">+ {{ Form::select('manufacturer_id', $manufacturer_list , Input::old('manufacturer_id', $consumable->manufacturer_id), array('class'=>'select2', 'style'=>'width:100%')) }}+ {!! $errors->first('manufacturer_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}+ </div>+ </div>+<!-- Location --><div class="form-group {{ $errors->has('location_id') ? ' has-error' : '' }}"><div class="col-md-3">@@ -91,6 +103,28 @@</div></div>+ <!-- Model Number -->+ <div class="form-group {{ $errors->has('model_no') ? ' has-error' : '' }}">+ <div class="col-md-3">+ {{ Form::label('model_no', trans('general.model_no')) }}+ </div>+ <div class="col-md-3">+ <input class="form-control" type="text" name="model_no" id="model_no" value="{{ Input::old('model_no', $consumable->model_no) }}" />+ {!! $errors->first('model_no', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}+ </div>+ </div>++ <!-- Item Number -->+ <div class="form-group {{ $errors->has('item_no') ? ' has-error' : '' }}">+ <div class="col-md-3">+ {{ Form::label('item_no', trans('admin/consumables/general.item_no')) }}+ </div>+ <div class="col-md-3">+ <input class="form-control" type="text" name="item_no" id="item_no" value="{{ Input::old('item_no', $consumable->item_no) }}" />+ {!! $errors->first('item_no', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}+ </div>+ </div>+<!-- Order Number --><div class="form-group {{ $errors->has('order_number') ? ' has-error' : '' }}">diff --git a/resources/views/consumables/index.blade.php b/resources/views/consumables/index.blade.phpindex 067a4e1852..91814f7cc9 100644--- a/resources/views/consumables/index.blade.php+++ b/resources/views/consumables/index.blade.php@@ -37,6 +37,9 @@<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="qty"> {{ trans('admin/consumables/general.total') }}</th><th data-switchable="false" data-searchable="false" data-sortable="false" data-field="numRemaining"> {{ trans('admin/consumables/general.remaining') }}</th><th data-switchable="false" data-searchable="false" data-sortable="true" data-field="min_amt"> {{ trans('general.min_amt') }}</th>+ <th data-sortable="true" data-field="manufacturer" data-visible="false">{{ trans('general.manufacturer') }}</th>+ <th data-sortable="true" data-field="model_no" data-visible="false">{{ trans('general.model_no') }}</th>+ <th data-sortable="true" data-field="item_no" data-visible="false">{{ trans('admin/consumables/general.item_no') }}</th><th data-sortable="true" data-searchable="true" data-field="order_number" data-visible="false">{{ trans('admin/consumables/general.order') }}</th><th data-sortable="true" data-searchable="true" data-field="purchase_date" data-visible="false">{{ trans('admin/consumables/general.date') }}</th><th data-sortable="true" data-searchable="true" data-field="purchase_cost" data-visible="false">{{ trans('admin/consumables/general.cost') }}</th>diff --git a/resources/views/consumables/view.blade.php b/resources/views/consumables/view.blade.phpindex 2c7c6593fd..5e99b4fbbd 100644--- a/resources/views/consumables/view.blade.php+++ b/resources/views/consumables/view.blade.php@@ -51,12 +51,18 @@</thead></table></div>+ </div></div></div></div></div><div class="col-md-3">++ <h4>{{ trans('admin/consumables/general.about_consumables_title') }}</h4>+ <p>{{ trans('admin/consumables/general.about_consumables_text') }} </p>++@if ($consumable->purchase_date)<div class="col-md-12" style="padding-bottom: 5px;"><strong>{{ trans('admin/consumables/general.date') }}: </strong>{{ $consumable->purchase_date }} </div>@@ -69,6 +75,21 @@{{ number_format($consumable->purchase_cost,2) }} </div>@endif+ @if ($consumable->item_no)+ <div class="col-md-12" style="padding-bottom: 5px;"><strong>{{ trans('admin/consumables/general.item_no') }}:</strong>+ {{ $consumable->item_no }} </div>+ @endif++ @if ($consumable->model_no)+ <div class="col-md-12" style="padding-bottom: 5px;"><strong>{{ trans('general.model_no') }}:</strong>+ {{ $consumable->model_no }} </div>+ @endif++ @if ($consumable->manufacturer)+ <div class="col-md-12" style="padding-bottom: 5px;"><strong>{{ trans('general.manufacturer') }}:</strong>+ {{ $consumable->manufacturer->name }} </div>+ @endif+@if ($consumable->order_number)<div class="col-md-12" style="padding-bottom: 5px;"><strong>{{ trans('admin/consumables/general.order') }}:</strong>{{ $consumable->order_number }} </div>@@ -78,14 +99,6 @@--<!-- side address column -->-<div class="col-md-3">- <h4>{{ trans('admin/consumables/general.about_consumables_title') }}</h4>- <p>{{ trans('admin/consumables/general.about_consumables_text') }} </p>--</div>-@section('moar_scripts')<script src="{{ asset('assets/js/bootstrap-table.js') }}"></script><script src="{{ asset('assets/js/extensions/cookie/bootstrap-table-cookie.js') }}"></script>