From e552c36a0a21a4da3285b6354a7ab42b5f728abe Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 16 May 2016 17:11:31 -0700 Subject: [PATCH] Add model_no, item_no, and manufacturer to consumables --- .../Controllers/ConsumablesController.php | 22 +++++++++-- app/Models/Consumable.php | 24 +++++++++++- ..._16_164733_add_model_mfg_to_consumable.php | 37 +++++++++++++++++++ .../lang/en/admin/consumables/general.php | 1 + resources/views/consumables/edit.blade.php | 34 +++++++++++++++++ resources/views/consumables/index.blade.php | 3 ++ resources/views/consumables/view.blade.php | 29 +++++++++++---- 7 files changed, 138 insertions(+), 12 deletions(-) create mode 100644 database/migrations/2016_05_16_164733_add_model_mfg_to_consumable.php diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php index 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 Controller case '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.php index 965e5ce5ef..3b89592875 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -64,6 +64,11 @@ class Consumable extends Model return $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 Model return $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 company diff --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.php new file mode 100644 index 0000000000..182eedae49 --- /dev/null +++ b/database/migrations/2016_05_16_164733_add_model_mfg_to_consumable.php @@ -0,0 +1,37 @@ +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.php index 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.php index e6689e681d..9e00195c4f 100644 --- a/resources/views/consumables/edit.blade.php +++ b/resources/views/consumables/edit.blade.php @@ -79,6 +79,18 @@ + +
+
+ {{ Form::label('manufacturer_id', trans('general.manufacturer')) }} + +
+
+ {{ Form::select('manufacturer_id', $manufacturer_list , Input::old('manufacturer_id', $consumable->manufacturer_id), array('class'=>'select2', 'style'=>'width:100%')) }} + {!! $errors->first('manufacturer_id', ' :message') !!} +
+
+
@@ -91,6 +103,28 @@
+ +
+
+ {{ Form::label('model_no', trans('general.model_no')) }} +
+
+ + {!! $errors->first('model_no', ' :message') !!} +
+
+ + +
+
+ {{ Form::label('item_no', trans('admin/consumables/general.item_no')) }} +
+
+ + {!! $errors->first('item_no', ' :message') !!} +
+
+
diff --git a/resources/views/consumables/index.blade.php b/resources/views/consumables/index.blade.php index 067a4e1852..91814f7cc9 100644 --- a/resources/views/consumables/index.blade.php +++ b/resources/views/consumables/index.blade.php @@ -37,6 +37,9 @@ {{ trans('admin/consumables/general.total') }} {{ trans('admin/consumables/general.remaining') }} {{ trans('general.min_amt') }} + {{ trans('general.manufacturer') }} + {{ trans('general.model_no') }} + {{ trans('admin/consumables/general.item_no') }} {{ trans('admin/consumables/general.order') }} {{ trans('admin/consumables/general.date') }} {{ trans('admin/consumables/general.cost') }} diff --git a/resources/views/consumables/view.blade.php b/resources/views/consumables/view.blade.php index 2c7c6593fd..5e99b4fbbd 100644 --- a/resources/views/consumables/view.blade.php +++ b/resources/views/consumables/view.blade.php @@ -51,12 +51,18 @@
+
+ +

{{ trans('admin/consumables/general.about_consumables_title') }}

+

{{ trans('admin/consumables/general.about_consumables_text') }}

+ + @if ($consumable->purchase_date)
{{ trans('admin/consumables/general.date') }}: {{ $consumable->purchase_date }}
@@ -69,6 +75,21 @@ {{ number_format($consumable->purchase_cost,2) }}
@endif + @if ($consumable->item_no) +
{{ trans('admin/consumables/general.item_no') }}: + {{ $consumable->item_no }}
+ @endif + + @if ($consumable->model_no) +
{{ trans('general.model_no') }}: + {{ $consumable->model_no }}
+ @endif + + @if ($consumable->manufacturer) +
{{ trans('general.manufacturer') }}: + {{ $consumable->manufacturer->name }}
+ @endif + @if ($consumable->order_number)
{{ trans('admin/consumables/general.order') }}: {{ $consumable->order_number }}
@@ -78,14 +99,6 @@ - - -
-

{{ trans('admin/consumables/general.about_consumables_title') }}

-

{{ trans('admin/consumables/general.about_consumables_text') }}

- -
- @section('moar_scripts')