From 0c912bcf4906de204345366099032ade9a9fe39d Mon Sep 17 00:00:00 2001 From: Daniel Meltzer Date: Mon, 15 Aug 2016 21:57:34 -0500 Subject: [PATCH 01/12] Fix more number_format madness. This does two main things: 1) The importer now imports as numbers, not parsed strings. This allows is to format values on output instead of input, which is what was happening in most places. 2) Add a Helper::parseCurrencyString method and port everything to use this. This checks to see if the value is numeric or empty, and returns the appropriate value in all cases. Should fix all known occurances of number_format expections. --- app/Helpers/Helper.php | 11 ++++++ .../Controllers/AccessoriesController.php | 2 +- app/Http/Controllers/AssetsController.php | 8 +--- app/Http/Controllers/ComponentsController.php | 2 +- .../Controllers/ConsumablesController.php | 2 +- app/Http/Controllers/LicensesController.php | 2 +- app/Http/Controllers/ReportsController.php | 37 ++++++++++--------- resources/views/accessories/edit.blade.php | 2 +- .../views/asset_maintenances/edit.blade.php | 2 +- resources/views/components/edit.blade.php | 2 +- resources/views/components/view.blade.php | 2 +- resources/views/consumables/edit.blade.php | 2 +- resources/views/consumables/view.blade.php | 2 +- resources/views/hardware/edit.blade.php | 2 +- resources/views/hardware/view.blade.php | 2 +- resources/views/licenses/edit.blade.php | 2 +- resources/views/licenses/view.blade.php | 2 +- resources/views/reports/asset.blade.php | 2 +- .../views/reports/depreciation.blade.php | 6 +-- resources/views/reports/index.blade.php | 2 +- 20 files changed, 51 insertions(+), 43 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index b6ce18c16..7ddab7532 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -43,6 +43,17 @@ class Helper return array_walk($emails_array, 'trim_value'); } + public static function parseCurrencyString($cost) + { + // The importer has formatted number strings since v3, so the value might be a string, or an integer. + // If it's a number, format it as a string + if (is_numeric($cost)) { + return number_format($cost, 2, '.', ''); + } + // It's already been parsed. + return $cost; + } + // This doesn't do anything yet public static function trim_value(&$value) { diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index 6c079345d..5f943a48f 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -617,7 +617,7 @@ class AccessoriesController extends Controller 'min_amt' => e($accessory->min_amt), 'location' => ($accessory->location) ? e($accessory->location->name): '', 'purchase_date' => e($accessory->purchase_date), - 'purchase_cost' => number_format($accessory->purchase_cost, 2), + 'purchase_cost' => Helper::parseCurrencyString($accessory->purchase_cost), 'numRemaining' => $accessory->numRemaining(), 'actions' => $actions, 'companyName' => is_null($company) ? '' : e($company->name) diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index 0358040d6..92aaa8f60 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -354,7 +354,7 @@ class AssetsController extends Controller } if ($request->has('purchase_cost')) { - $asset->purchase_cost = e(number_format($request->input('purchase_cost'), 2, '.', '')); + $asset->purchase_cost = e(Helper::parseCurrencyString($request->input('purchase_cost'))); } else { $asset->purchase_cost = null; } @@ -1741,11 +1741,7 @@ class AssetsController extends Controller } } - // Lots going on here. Importer has parsed numbers before importing, so we need to check and see if it's a number before trying to parse. - $purchase_cost = $asset->purchase_cost ?: ''; - if (is_numeric($purchase_cost)) { - $purchase_cost = number_format($purchase_cost, 2); - } + $purchase_cost = Helper::parseCurrencyString($asset->purchase_cost); $row = array( 'checkbox' =>'
', diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.php index 128b61709..57ba37eb7 100644 --- a/app/Http/Controllers/ComponentsController.php +++ b/app/Http/Controllers/ComponentsController.php @@ -484,7 +484,7 @@ class ComponentsController extends Controller 'category' => ($component->category) ? e($component->category->name) : 'Missing category', 'order_number' => e($component->order_number), 'purchase_date' => e($component->purchase_date), - 'purchase_cost' => ($component->purchase_cost!='') ? number_format($component->purchase_cost, 2): '' , + 'purchase_cost' => Helper::parseCurrencyString($component->purchase_cost), 'numRemaining' => $component->numRemaining(), 'actions' => $actions, 'companyName' => is_null($company) ? '' : e($company->name), diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php index 11f6a7812..096889a80 100644 --- a/app/Http/Controllers/ConsumablesController.php +++ b/app/Http/Controllers/ConsumablesController.php @@ -476,7 +476,7 @@ class ConsumablesController extends Controller 'category' => ($consumable->category) ? e($consumable->category->name) : 'Missing category', 'order_number' => e($consumable->order_number), 'purchase_date' => e($consumable->purchase_date), - 'purchase_cost' => ($consumable->purchase_cost!='') ? number_format($consumable->purchase_cost, 2): '' , + 'purchase_cost' => Helper::parseCurrencyString($consumable->purchase_cost), 'numRemaining' => $consumable->numRemaining(), 'actions' => $actions, 'companyName' => is_null($company) ? '' : e($company->name), diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php index bfd46a190..5606675da 100755 --- a/app/Http/Controllers/LicensesController.php +++ b/app/Http/Controllers/LicensesController.php @@ -1015,7 +1015,7 @@ class LicensesController extends Controller 'license_email' => e($license->license_email), 'purchase_date' => ($license->purchase_date) ? $license->purchase_date : '', 'expiration_date' => ($license->expiration_date) ? $license->expiration_date : '', - 'purchase_cost' => ($license->purchase_cost) ? number_format($license->purchase_cost, 2) : '', + 'purchase_cost' => Helper::parseCurrencyString($license->purchase_cost), 'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : '', 'order_number' => ($license->order_number) ? e($license->order_number) : '', 'notes' => ($license->notes) ? e($license->notes) : '', diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 624a4da75..9e0c6ef6d 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -1,25 +1,26 @@ purchase_date; - $row[] = '"' . number_format($asset->purchase_cost, 2) . '"'; + $row[] = '"' . Helper::parsePurchasedCost($asset->purchase_cost) . '"'; if ($asset->order_number) { $row[] = e($asset->order_number); } else { @@ -308,9 +309,9 @@ class ReportsController extends Controller } $row[] = $asset->purchase_date; - $row[] = $currency . number_format($asset->purchase_cost, 2); - $row[] = $currency . number_format($asset->getDepreciatedValue(), 2); - $row[] = $currency . number_format(( $asset->purchase_cost - $asset->getDepreciatedValue() ), 2); + $row[] = $currency . Helper::parseCurrencyString($asset->purchase_cost); + $row[] = $currency . Helper::parseCurrencyString($asset->getDepreciatedValue()); + $row[] = $currency . Helper::parseCurrencyString(( $asset->purchase_cost - $asset->getDepreciatedValue() )); $csv->insertOne($row); } @@ -392,7 +393,7 @@ class ReportsController extends Controller $row[] = $license->remaincount(); $row[] = $license->expiration_date; $row[] = $license->purchase_date; - $row[] = '"' . number_format($license->purchase_cost, 2) . '"'; + $row[] = '"' . Helper::parseCurrencyString($license->purchase_cost) . '"'; $rows[] = implode($row, ','); } @@ -416,7 +417,7 @@ class ReportsController extends Controller public function getCustomReport() { $customfields = CustomField::get(); - return View::make('reports/custom')->with('customfields',$customfields); + return View::make('reports/custom')->with('customfields', $customfields); } /** @@ -528,7 +529,7 @@ class ReportsController extends Controller $row[] = e($asset->purchase_date); } if (e(Input::get('purchase_cost')) == '1' && ( e(Input::get('depreciation')) != '1' )) { - $row[] = '"' . number_format($asset->purchase_cost, 2) . '"'; + $row[] = '"' . Helper::parseCurrencyString($asset->purchase_cost) . '"'; } if (e(Input::get('order')) == '1') { if ($asset->order_number) { @@ -605,9 +606,9 @@ class ReportsController extends Controller } if (e(Input::get('depreciation')) == '1') { $depreciation = $asset->getDepreciatedValue(); - $row[] = '"' . number_format($asset->purchase_cost, 2) . '"'; - $row[] = '"' . number_format($depreciation, 2) . '"'; - $row[] = '"' . number_format($asset->purchase_cost - $depreciation, 2) . '"'; + $row[] = '"' . Helper::parseCurrencyString($asset->purchase_cost) . '"'; + $row[] = '"' . Helper::parseCurrencyString($depreciation) . '"'; + $row[] = '"' . Helper::parseCurrencyString($asset->purchase_cost) . '"'; } foreach ($customfields as $customfield) { @@ -698,7 +699,7 @@ class ReportsController extends Controller $improvementTime = intval($assetMaintenance->asset_maintenance_time); } $row[] = $improvementTime; - $row[] = trans('general.currency') . number_format($assetMaintenance->cost, 2); + $row[] = trans('general.currency') . Helper::parseCurrencyString($assetMaintenance->cost); $rows[] = implode($row, ','); } diff --git a/resources/views/accessories/edit.blade.php b/resources/views/accessories/edit.blade.php index 99f2cd5ed..361fa4cce 100755 --- a/resources/views/accessories/edit.blade.php +++ b/resources/views/accessories/edit.blade.php @@ -132,7 +132,7 @@ {{ \App\Models\Setting::first()->default_currency }} - + {!! $errors->first('purchase_cost', ' :message') !!} diff --git a/resources/views/asset_maintenances/edit.blade.php b/resources/views/asset_maintenances/edit.blade.php index 31d6caa70..d13b01bba 100644 --- a/resources/views/asset_maintenances/edit.blade.php +++ b/resources/views/asset_maintenances/edit.blade.php @@ -122,7 +122,7 @@
{{ \App\Models\Setting::first()->default_currency }} - + {!! $errors->first('cost', ' :message') !!}
diff --git a/resources/views/components/edit.blade.php b/resources/views/components/edit.blade.php index c4e65ac48..7cab993f0 100644 --- a/resources/views/components/edit.blade.php +++ b/resources/views/components/edit.blade.php @@ -156,7 +156,7 @@ {{ \App\Models\Setting::first()->default_currency }} - + {!! $errors->first('purchase_cost', ' :message') !!} diff --git a/resources/views/components/view.blade.php b/resources/views/components/view.blade.php index 8c3454bd6..74feb7898 100644 --- a/resources/views/components/view.blade.php +++ b/resources/views/components/view.blade.php @@ -83,7 +83,7 @@
{{ trans('admin/components/general.cost') }}: {{ \App\Models\Setting::first()->default_currency }} - {{ number_format($component->purchase_cost,2) }}
+ {{ \App\Helpers\Helper::parseCurrencyString($component->purchase_cost) }} @endif @if ($component->order_number) diff --git a/resources/views/consumables/edit.blade.php b/resources/views/consumables/edit.blade.php index 9e00195c4..2080e122e 100644 --- a/resources/views/consumables/edit.blade.php +++ b/resources/views/consumables/edit.blade.php @@ -159,7 +159,7 @@ {{ \App\Models\Setting::first()->default_currency }} - + {!! $errors->first('purchase_cost', ' :message') !!} diff --git a/resources/views/consumables/view.blade.php b/resources/views/consumables/view.blade.php index 5e99b4fbb..368f84be2 100644 --- a/resources/views/consumables/view.blade.php +++ b/resources/views/consumables/view.blade.php @@ -72,7 +72,7 @@
{{ trans('admin/consumables/general.cost') }}: {{ \App\Models\Setting::first()->default_currency }} - {{ number_format($consumable->purchase_cost,2) }}
+ {{ \App\Helpers\Helper::parseCurrencyString($consumable->purchase_cost) }} @endif @if ($consumable->item_no) diff --git a/resources/views/hardware/edit.blade.php b/resources/views/hardware/edit.blade.php index 0b9190c18..357372c08 100755 --- a/resources/views/hardware/edit.blade.php +++ b/resources/views/hardware/edit.blade.php @@ -215,7 +215,7 @@ - + {!! $errors->first('purchase_cost', ' :message') !!} diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 302e255e1..6442cfa9c 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -154,7 +154,7 @@ @else {{ \App\Models\Setting::first()->default_currency }} @endif - {{ number_format($asset->purchase_cost,2) }} + {{ \App\Helpers\Helper::parseCurrencyString($asset->purchase_cost)}} @if ($asset->order_number) (Order #{{ $asset->order_number }}) diff --git a/resources/views/licenses/edit.blade.php b/resources/views/licenses/edit.blade.php index 46994e8e5..47306e5c2 100755 --- a/resources/views/licenses/edit.blade.php +++ b/resources/views/licenses/edit.blade.php @@ -139,7 +139,7 @@
{{ \App\Models\Setting::first()->default_currency }} - + {!! $errors->first('purchase_cost', ' :message') !!}
diff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.php index 3f1fca4e4..b19aa47ea 100755 --- a/resources/views/licenses/view.blade.php +++ b/resources/views/licenses/view.blade.php @@ -246,7 +246,7 @@ {{ \App\Models\Setting::first()->default_currency }} - {{ number_format($license->purchase_cost,2) }} + {{ \App\Helpers\Helper::parseCurrencyString($license->purchase_cost) }} @endif diff --git a/resources/views/reports/asset.blade.php b/resources/views/reports/asset.blade.php index 0aee0e7ab..5acef07f5 100644 --- a/resources/views/reports/asset.blade.php +++ b/resources/views/reports/asset.blade.php @@ -77,7 +77,7 @@ {{ $asset->purchase_date }} {{ $settings->default_currency }} - {{ number_format($asset->purchase_cost) }} + {{ \App\Helpers\Helper::parseCurrencyString($asset->purchase_cost) }} @if ($asset->order_number) diff --git a/resources/views/reports/depreciation.blade.php b/resources/views/reports/depreciation.blade.php index 8607d7da3..657706eda 100644 --- a/resources/views/reports/depreciation.blade.php +++ b/resources/views/reports/depreciation.blade.php @@ -111,7 +111,7 @@ @else {{ \App\Models\Setting::first()->default_currency }} @endif - {{ number_format($asset->purchase_cost) }} + {{ \App\Helpers\Helper::parseCurrencyString($asset->purchase_cost) }} @if ($asset->assetloc ) {{ $asset->assetloc->currency }} @@ -119,7 +119,7 @@ {{ \App\Models\Setting::first()->default_currency }} @endif - {{ number_format($asset->getDepreciatedValue()) }} + {{ \App\Helpers\Helper::parseCurrencyString($asset->getDepreciatedValue()) }} @if ($asset->assetloc) {{ $asset->assetloc->currency }} @@ -127,7 +127,7 @@ {{ \App\Models\Setting::first()->default_currency }} @endif - -{{ number_format(($asset->purchase_cost - $asset->getDepreciatedValue())) }} + -{{ \App\Helpers\Helper::parseCurrencyString(($asset->purchase_cost - $asset->getDepreciatedValue())) }} @else diff --git a/resources/views/reports/index.blade.php b/resources/views/reports/index.blade.php index b166b2dc7..e6616d1cd 100755 --- a/resources/views/reports/index.blade.php +++ b/resources/views/reports/index.blade.php @@ -74,7 +74,7 @@ @if ($asset->purchase_cost > 0) {{ \App\Models\Setting::first()->default_currency }} - {{ number_format($asset->purchase_cost) }} + {{ \App\Helpers\Helper::parseCurrencyString($asset->purchase_cost) }} {{ \App\Models\Setting::first()->default_currency }} From 5959f83de3d248a705b7e832c0059772f084c68b Mon Sep 17 00:00:00 2001 From: Daniel Meltzer Date: Tue, 16 Aug 2016 20:47:53 -0500 Subject: [PATCH 02/12] Rename parseCurrencyString to formatCurrencyOutput to clarify what it does better. --- app/Helpers/Helper.php | 2 +- app/Http/Controllers/AccessoriesController.php | 2 +- app/Http/Controllers/AssetsController.php | 4 ++-- app/Http/Controllers/ComponentsController.php | 2 +- app/Http/Controllers/ConsumablesController.php | 2 +- app/Http/Controllers/LicensesController.php | 2 +- app/Http/Controllers/ReportsController.php | 18 +++++++++--------- resources/views/accessories/edit.blade.php | 2 +- .../views/asset_maintenances/edit.blade.php | 2 +- resources/views/components/edit.blade.php | 2 +- resources/views/components/view.blade.php | 2 +- resources/views/consumables/edit.blade.php | 2 +- resources/views/consumables/view.blade.php | 2 +- resources/views/hardware/edit.blade.php | 2 +- resources/views/hardware/view.blade.php | 2 +- resources/views/licenses/edit.blade.php | 2 +- resources/views/licenses/view.blade.php | 2 +- resources/views/reports/asset.blade.php | 2 +- resources/views/reports/depreciation.blade.php | 6 +++--- resources/views/reports/index.blade.php | 2 +- 20 files changed, 31 insertions(+), 31 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 7ddab7532..b0fc90551 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -43,7 +43,7 @@ class Helper return array_walk($emails_array, 'trim_value'); } - public static function parseCurrencyString($cost) + public static function formatCurrencyOutput($cost) { // The importer has formatted number strings since v3, so the value might be a string, or an integer. // If it's a number, format it as a string diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index 5f943a48f..4aab46efb 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -617,7 +617,7 @@ class AccessoriesController extends Controller 'min_amt' => e($accessory->min_amt), 'location' => ($accessory->location) ? e($accessory->location->name): '', 'purchase_date' => e($accessory->purchase_date), - 'purchase_cost' => Helper::parseCurrencyString($accessory->purchase_cost), + 'purchase_cost' => Helper::formatCurrencyOutput($accessory->purchase_cost), 'numRemaining' => $accessory->numRemaining(), 'actions' => $actions, 'companyName' => is_null($company) ? '' : e($company->name) diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index 92aaa8f60..92f4997d5 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -354,7 +354,7 @@ class AssetsController extends Controller } if ($request->has('purchase_cost')) { - $asset->purchase_cost = e(Helper::parseCurrencyString($request->input('purchase_cost'))); + $asset->purchase_cost = e(Helper::formatCurrencyOutput($request->input('purchase_cost'))); } else { $asset->purchase_cost = null; } @@ -1741,7 +1741,7 @@ class AssetsController extends Controller } } - $purchase_cost = Helper::parseCurrencyString($asset->purchase_cost); + $purchase_cost = Helper::formatCurrencyOutput($asset->purchase_cost); $row = array( 'checkbox' =>'
', diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.php index 57ba37eb7..e3e754383 100644 --- a/app/Http/Controllers/ComponentsController.php +++ b/app/Http/Controllers/ComponentsController.php @@ -484,7 +484,7 @@ class ComponentsController extends Controller 'category' => ($component->category) ? e($component->category->name) : 'Missing category', 'order_number' => e($component->order_number), 'purchase_date' => e($component->purchase_date), - 'purchase_cost' => Helper::parseCurrencyString($component->purchase_cost), + 'purchase_cost' => Helper::formatCurrencyOutput($component->purchase_cost), 'numRemaining' => $component->numRemaining(), 'actions' => $actions, 'companyName' => is_null($company) ? '' : e($company->name), diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php index 096889a80..f4f8be380 100644 --- a/app/Http/Controllers/ConsumablesController.php +++ b/app/Http/Controllers/ConsumablesController.php @@ -476,7 +476,7 @@ class ConsumablesController extends Controller 'category' => ($consumable->category) ? e($consumable->category->name) : 'Missing category', 'order_number' => e($consumable->order_number), 'purchase_date' => e($consumable->purchase_date), - 'purchase_cost' => Helper::parseCurrencyString($consumable->purchase_cost), + 'purchase_cost' => Helper::formatCurrencyOutput($consumable->purchase_cost), 'numRemaining' => $consumable->numRemaining(), 'actions' => $actions, 'companyName' => is_null($company) ? '' : e($company->name), diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php index 5606675da..fe668c760 100755 --- a/app/Http/Controllers/LicensesController.php +++ b/app/Http/Controllers/LicensesController.php @@ -1015,7 +1015,7 @@ class LicensesController extends Controller 'license_email' => e($license->license_email), 'purchase_date' => ($license->purchase_date) ? $license->purchase_date : '', 'expiration_date' => ($license->expiration_date) ? $license->expiration_date : '', - 'purchase_cost' => Helper::parseCurrencyString($license->purchase_cost), + 'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost), 'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : '', 'order_number' => ($license->order_number) ? e($license->order_number) : '', 'notes' => ($license->notes) ? e($license->notes) : '', diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 9e0c6ef6d..f7dc09168 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -309,9 +309,9 @@ class ReportsController extends Controller } $row[] = $asset->purchase_date; - $row[] = $currency . Helper::parseCurrencyString($asset->purchase_cost); - $row[] = $currency . Helper::parseCurrencyString($asset->getDepreciatedValue()); - $row[] = $currency . Helper::parseCurrencyString(( $asset->purchase_cost - $asset->getDepreciatedValue() )); + $row[] = $currency . Helper::formatCurrencyOutput($asset->purchase_cost); + $row[] = $currency . Helper::formatCurrencyOutput($asset->getDepreciatedValue()); + $row[] = $currency . Helper::formatCurrencyOutput(( $asset->purchase_cost - $asset->getDepreciatedValue() )); $csv->insertOne($row); } @@ -393,7 +393,7 @@ class ReportsController extends Controller $row[] = $license->remaincount(); $row[] = $license->expiration_date; $row[] = $license->purchase_date; - $row[] = '"' . Helper::parseCurrencyString($license->purchase_cost) . '"'; + $row[] = '"' . Helper::formatCurrencyOutput($license->purchase_cost) . '"'; $rows[] = implode($row, ','); } @@ -529,7 +529,7 @@ class ReportsController extends Controller $row[] = e($asset->purchase_date); } if (e(Input::get('purchase_cost')) == '1' && ( e(Input::get('depreciation')) != '1' )) { - $row[] = '"' . Helper::parseCurrencyString($asset->purchase_cost) . '"'; + $row[] = '"' . Helper::formatCurrencyOutput($asset->purchase_cost) . '"'; } if (e(Input::get('order')) == '1') { if ($asset->order_number) { @@ -606,9 +606,9 @@ class ReportsController extends Controller } if (e(Input::get('depreciation')) == '1') { $depreciation = $asset->getDepreciatedValue(); - $row[] = '"' . Helper::parseCurrencyString($asset->purchase_cost) . '"'; - $row[] = '"' . Helper::parseCurrencyString($depreciation) . '"'; - $row[] = '"' . Helper::parseCurrencyString($asset->purchase_cost) . '"'; + $row[] = '"' . Helper::formatCurrencyOutput($asset->purchase_cost) . '"'; + $row[] = '"' . Helper::formatCurrencyOutput($depreciation) . '"'; + $row[] = '"' . Helper::formatCurrencyOutput($asset->purchase_cost) . '"'; } foreach ($customfields as $customfield) { @@ -699,7 +699,7 @@ class ReportsController extends Controller $improvementTime = intval($assetMaintenance->asset_maintenance_time); } $row[] = $improvementTime; - $row[] = trans('general.currency') . Helper::parseCurrencyString($assetMaintenance->cost); + $row[] = trans('general.currency') . Helper::formatCurrencyOutput($assetMaintenance->cost); $rows[] = implode($row, ','); } diff --git a/resources/views/accessories/edit.blade.php b/resources/views/accessories/edit.blade.php index 361fa4cce..c1b21ceb0 100755 --- a/resources/views/accessories/edit.blade.php +++ b/resources/views/accessories/edit.blade.php @@ -132,7 +132,7 @@ {{ \App\Models\Setting::first()->default_currency }} - + {!! $errors->first('purchase_cost', ' :message') !!} diff --git a/resources/views/asset_maintenances/edit.blade.php b/resources/views/asset_maintenances/edit.blade.php index d13b01bba..ea7b5a1ac 100644 --- a/resources/views/asset_maintenances/edit.blade.php +++ b/resources/views/asset_maintenances/edit.blade.php @@ -122,7 +122,7 @@
{{ \App\Models\Setting::first()->default_currency }} - + {!! $errors->first('cost', ' :message') !!}
diff --git a/resources/views/components/edit.blade.php b/resources/views/components/edit.blade.php index 7cab993f0..9e20716f5 100644 --- a/resources/views/components/edit.blade.php +++ b/resources/views/components/edit.blade.php @@ -156,7 +156,7 @@ {{ \App\Models\Setting::first()->default_currency }} - + {!! $errors->first('purchase_cost', ' :message') !!} diff --git a/resources/views/components/view.blade.php b/resources/views/components/view.blade.php index 74feb7898..e84fb34f3 100644 --- a/resources/views/components/view.blade.php +++ b/resources/views/components/view.blade.php @@ -83,7 +83,7 @@
{{ trans('admin/components/general.cost') }}: {{ \App\Models\Setting::first()->default_currency }} - {{ \App\Helpers\Helper::parseCurrencyString($component->purchase_cost) }}
+ {{ \App\Helpers\Helper::formatCurrencyOutput($component->purchase_cost) }} @endif @if ($component->order_number) diff --git a/resources/views/consumables/edit.blade.php b/resources/views/consumables/edit.blade.php index 2080e122e..2cf1ec654 100644 --- a/resources/views/consumables/edit.blade.php +++ b/resources/views/consumables/edit.blade.php @@ -159,7 +159,7 @@ {{ \App\Models\Setting::first()->default_currency }} - + {!! $errors->first('purchase_cost', ' :message') !!} diff --git a/resources/views/consumables/view.blade.php b/resources/views/consumables/view.blade.php index 368f84be2..afc2a3fea 100644 --- a/resources/views/consumables/view.blade.php +++ b/resources/views/consumables/view.blade.php @@ -72,7 +72,7 @@
{{ trans('admin/consumables/general.cost') }}: {{ \App\Models\Setting::first()->default_currency }} - {{ \App\Helpers\Helper::parseCurrencyString($consumable->purchase_cost) }}
+ {{ \App\Helpers\Helper::formatCurrencyOutput($consumable->purchase_cost) }} @endif @if ($consumable->item_no) diff --git a/resources/views/hardware/edit.blade.php b/resources/views/hardware/edit.blade.php index 357372c08..53a469ece 100755 --- a/resources/views/hardware/edit.blade.php +++ b/resources/views/hardware/edit.blade.php @@ -215,7 +215,7 @@ - + {!! $errors->first('purchase_cost', ' :message') !!} diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 6442cfa9c..d4e0b32a3 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -154,7 +154,7 @@ @else {{ \App\Models\Setting::first()->default_currency }} @endif - {{ \App\Helpers\Helper::parseCurrencyString($asset->purchase_cost)}} + {{ \App\Helpers\Helper::formatCurrencyOutput($asset->purchase_cost)}} @if ($asset->order_number) (Order #{{ $asset->order_number }}) diff --git a/resources/views/licenses/edit.blade.php b/resources/views/licenses/edit.blade.php index 47306e5c2..bd86990e7 100755 --- a/resources/views/licenses/edit.blade.php +++ b/resources/views/licenses/edit.blade.php @@ -139,7 +139,7 @@
{{ \App\Models\Setting::first()->default_currency }} - + {!! $errors->first('purchase_cost', ' :message') !!}
diff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.php index b19aa47ea..b0d2d4e65 100755 --- a/resources/views/licenses/view.blade.php +++ b/resources/views/licenses/view.blade.php @@ -246,7 +246,7 @@ {{ \App\Models\Setting::first()->default_currency }} - {{ \App\Helpers\Helper::parseCurrencyString($license->purchase_cost) }} + {{ \App\Helpers\Helper::formatCurrencyOutput($license->purchase_cost) }} @endif diff --git a/resources/views/reports/asset.blade.php b/resources/views/reports/asset.blade.php index 5acef07f5..97c31cb5b 100644 --- a/resources/views/reports/asset.blade.php +++ b/resources/views/reports/asset.blade.php @@ -77,7 +77,7 @@ {{ $asset->purchase_date }} {{ $settings->default_currency }} - {{ \App\Helpers\Helper::parseCurrencyString($asset->purchase_cost) }} + {{ \App\Helpers\Helper::formatCurrencyOutput($asset->purchase_cost) }} @if ($asset->order_number) diff --git a/resources/views/reports/depreciation.blade.php b/resources/views/reports/depreciation.blade.php index 657706eda..36cf1fd6f 100644 --- a/resources/views/reports/depreciation.blade.php +++ b/resources/views/reports/depreciation.blade.php @@ -111,7 +111,7 @@ @else {{ \App\Models\Setting::first()->default_currency }} @endif - {{ \App\Helpers\Helper::parseCurrencyString($asset->purchase_cost) }} + {{ \App\Helpers\Helper::formatCurrencyOutput($asset->purchase_cost) }} @if ($asset->assetloc ) {{ $asset->assetloc->currency }} @@ -119,7 +119,7 @@ {{ \App\Models\Setting::first()->default_currency }} @endif - {{ \App\Helpers\Helper::parseCurrencyString($asset->getDepreciatedValue()) }} + {{ \App\Helpers\Helper::formatCurrencyOutput($asset->getDepreciatedValue()) }} @if ($asset->assetloc) {{ $asset->assetloc->currency }} @@ -127,7 +127,7 @@ {{ \App\Models\Setting::first()->default_currency }} @endif - -{{ \App\Helpers\Helper::parseCurrencyString(($asset->purchase_cost - $asset->getDepreciatedValue())) }} + -{{ \App\Helpers\Helper::formatCurrencyOutput(($asset->purchase_cost - $asset->getDepreciatedValue())) }} @else diff --git a/resources/views/reports/index.blade.php b/resources/views/reports/index.blade.php index e6616d1cd..c84da3e1c 100755 --- a/resources/views/reports/index.blade.php +++ b/resources/views/reports/index.blade.php @@ -74,7 +74,7 @@ @if ($asset->purchase_cost > 0) {{ \App\Models\Setting::first()->default_currency }} - {{ \App\Helpers\Helper::parseCurrencyString($asset->purchase_cost) }} + {{ \App\Helpers\Helper::formatCurrencyOutput($asset->purchase_cost) }} {{ \App\Models\Setting::first()->default_currency }} From ac6364222478f4ad08a768efecf8085a7225508f Mon Sep 17 00:00:00 2001 From: Daniel Meltzer Date: Tue, 16 Aug 2016 20:49:54 -0500 Subject: [PATCH 03/12] Add manufacturer to licenses (#2436) * Add manufacturer to licenses. Shows in table and edit. Need to improve manufacturer view to show lists beyond assets still. * Remove extra closing tags, formatting * Work on making the manufacturer view show more options. Need to figure out how to change the table dynamically. * Cleanup formatting and fix a few weirdities in hardware/view.blade.php * Standardize on two-space tabs in this file, as it seems the most * common. * Fix a few places where we call number_format without guaranteeing the * item is a number and not a string. * Show a "No Results" message on components page if there are no * components. * Show table of licenses on manufacturer view page. This reworks the ManufacturersController::getDataView method to delegate the view to a sub method (currently assets or licenses, but plan to extend to consumables/accessories/components as well). We then put tabs at the top of the view to show multiple tables. This just duplicates the table layout from licenses/index.blade, but I wonder if theres a way to centralize that code, maybe through partials, over time.. The only known missing part of manufacturers for licenses would be adding it to the importer, but the license importer should probably migrate to object importer before doing too much more... * Add manufacturer to accessory. * Add consumables to the manufacturer view page. --- .../Controllers/AccessoriesController.php | 51 +- .../Controllers/ConsumablesController.php | 16 +- app/Http/Controllers/LicensesController.php | 68 +- .../Controllers/ManufacturersController.php | 233 +++++- app/Http/routes.php | 2 +- app/Models/Accessory.php | 5 + app/Models/License.php | 5 + app/Models/Manufacturer.php | 15 + ...09_002225_add_manufacturer_to_licenses.php | 32 + ..._add_manufacturer_to_accessories_table.php | 33 + resources/views/accessories/edit.blade.php | 12 + resources/views/accessories/index.blade.php | 1 + resources/views/hardware/view.blade.php | 723 +++++++++--------- resources/views/licenses/edit.blade.php | 9 + resources/views/licenses/index.blade.php | 1 + resources/views/licenses/view.blade.php | 7 + resources/views/manufacturers/view.blade.php | 167 +++- resources/views/models/edit.blade.php | 21 +- 18 files changed, 911 insertions(+), 490 deletions(-) create mode 100644 database/migrations/2016_08_09_002225_add_manufacturer_to_licenses.php create mode 100644 database/migrations/2016_08_12_121613_add_manufacturer_to_accessories_table.php diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index 6c079345d..d5e8dd7e7 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -53,14 +53,12 @@ class AccessoriesController extends Controller public function getCreate(Request $request) { // Show the page - $category_list = Helper::categoryList('accessory'); - $company_list = Helper::companyList(); - $location_list = Helper::locationsList(); return View::make('accessories/edit') ->with('accessory', new Accessory) - ->with('category_list', $category_list) - ->with('company_list', $company_list) - ->with('location_list', $location_list); + ->with('category_list', Helper::categoryList('accessory')) + ->with('company_list', Helper::companyList()) + ->with('location_list', Helper::locationsList()) + ->with('manufacturer_list', Helper::manufacturerList()); } @@ -77,12 +75,13 @@ class AccessoriesController extends Controller $accessory = new Accessory(); // Update the accessory data - $accessory->name = e(Input::get('name')); - $accessory->category_id = e(Input::get('category_id')); - $accessory->location_id = e(Input::get('location_id')); - $accessory->min_amt = e(Input::get('min_amt')); + $accessory->name = e(Input::get('name')); + $accessory->category_id = e(Input::get('category_id')); + $accessory->location_id = e(Input::get('location_id')); + $accessory->min_amt = e(Input::get('min_amt')); $accessory->company_id = Company::getIdForCurrentUser(Input::get('company_id')); $accessory->order_number = e(Input::get('order_number')); + $accessory->manufacturer_id = e(Input::get('manufacturer_id')); if (e(Input::get('purchase_date')) == '') { $accessory->purchase_date = null; @@ -96,8 +95,8 @@ class AccessoriesController extends Controller $accessory->purchase_cost = e(Input::get('purchase_cost')); } - $accessory->qty = e(Input::get('qty')); - $accessory->user_id = Auth::user()->id; + $accessory->qty = e(Input::get('qty')); + $accessory->user_id = Auth::user()->id; // Was the accessory created? if ($accessory->save()) { @@ -126,14 +125,11 @@ class AccessoriesController extends Controller return redirect()->to('admin/accessories')->with('error', trans('general.insufficient_permissions')); } - $category_list = Helper::categoryList('accessory'); - $company_list = Helper::companyList(); - $location_list = Helper::locationsList(); - return View::make('accessories/edit', compact('accessory')) - ->with('category_list', $category_list) - ->with('company_list', $company_list) - ->with('location_list', $location_list); + ->with('category_list', Helper::categoryList('accessory')) + ->with('company_list', Helper::companyList()) + ->with('location_list', Helper::locationsList()) + ->with('manufacturer_list', Helper::manufacturerList()); } @@ -146,9 +142,9 @@ class AccessoriesController extends Controller */ public function postEdit(Request $request, $accessoryId = null) { - // Check if the blog post exists + // Check if the accessory exists if (is_null($accessory = Accessory::find($accessoryId))) { - // Redirect to the blogs management page + // Redirect to the accessory index page return redirect()->to('admin/accessories')->with('error', trans('admin/accessories/message.does_not_exist')); } elseif (!Company::isCurrentUserHasAccess($accessory)) { return redirect()->to('admin/accessories')->with('error', trans('general.insufficient_permissions')); @@ -160,11 +156,12 @@ class AccessoriesController extends Controller if (e(Input::get('location_id')) == '') { $accessory->location_id = null; } else { - $accessory->location_id = e(Input::get('location_id')); + $accessory->location_id = e(Input::get('location_id')); } - $accessory->min_amt = e(Input::get('min_amt')); + $accessory->min_amt = e(Input::get('min_amt')); $accessory->category_id = e(Input::get('category_id')); $accessory->company_id = Company::getIdForCurrentUser(Input::get('company_id')); + $accessory->manufacturer_id = e(Input::get('manufacturer_id')); $accessory->order_number = e(Input::get('order_number')); if (e(Input::get('purchase_date')) == '') { @@ -181,9 +178,9 @@ class AccessoriesController extends Controller $accessory->qty = e(Input::get('qty')); - // Was the accessory created? + // Was the accessory updated? if ($accessory->save()) { - // Redirect to the new accessory page + // Redirect to the updated accessory page return redirect()->to("admin/accessories")->with('success', trans('admin/accessories/message.update.success')); } @@ -620,7 +617,9 @@ class AccessoriesController extends Controller 'purchase_cost' => number_format($accessory->purchase_cost, 2), 'numRemaining' => $accessory->numRemaining(), 'actions' => $actions, - 'companyName' => is_null($company) ? '' : e($company->name) + 'companyName' => is_null($company) ? '' : e($company->name), + 'manufacturer' => $accessory->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$accessory->manufacturer_id.'/view', $accessory->manufacturer->name) : '' + ); } diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php index 11f6a7812..1c9609d19 100644 --- a/app/Http/Controllers/ConsumablesController.php +++ b/app/Http/Controllers/ConsumablesController.php @@ -467,16 +467,16 @@ class ConsumablesController extends Controller $rows[] = array( 'id' => $consumable->id, 'name' => (string)link_to('admin/consumables/'.$consumable->id.'/view', e($consumable->name)), - 'location' => ($consumable->location) ? e($consumable->location->name) : '', - 'min_amt' => e($consumable->min_amt), + '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', + 'manufacturer' => ($consumable->manufacturer) ? (string) link_to('/admin/settings/manufacturers/'.$consumable->manufacturer_id.'/view', $consumable->manufacturer->name): '', + 'model_no' => e($consumable->model_no), + 'item_no' => e($consumable->item_no), + 'category' => ($consumable->category) ? (string) link_to('/admin/settings/categories/'.$consumable->category_id.'/view', $consumable->category->name) : 'Missing category', 'order_number' => e($consumable->order_number), - 'purchase_date' => e($consumable->purchase_date), - 'purchase_cost' => ($consumable->purchase_cost!='') ? number_format($consumable->purchase_cost, 2): '' , + 'purchase_date' => e($consumable->purchase_date), + 'purchase_cost' => ($consumable->purchase_cost!='') ? number_format($consumable->purchase_cost, 2): '' , 'numRemaining' => $consumable->numRemaining(), 'actions' => $actions, 'companyName' => is_null($company) ? '' : e($company->name), diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php index bfd46a190..671ac1e91 100755 --- a/app/Http/Controllers/LicensesController.php +++ b/app/Http/Controllers/LicensesController.php @@ -61,18 +61,17 @@ class LicensesController extends Controller public function getCreate() { - $depreciation_list = Helper::depreciationList(); - $supplier_list = Helper::suppliersList(); $maintained_list = array('' => 'Maintained', '1' => 'Yes', '0' => 'No'); - $company_list = Helper::companyList(); return View::make('licenses/edit') //->with('license_options',$license_options) - ->with('depreciation_list', $depreciation_list) - ->with('supplier_list', $supplier_list) + ->with('depreciation_list', Helper::depreciationList()) + ->with('supplier_list', Helper::suppliersList()) ->with('maintained_list', $maintained_list) - ->with('company_list', $company_list) + ->with('company_list', Helper::companyList()) + ->with('manufacturer_list', Helper::manufacturerList()) ->with('license', new License); + } @@ -125,6 +124,12 @@ class LicensesController extends Controller $license->purchase_order = e(Input::get('purchase_order')); } + if (empty(e(Input::get('manufacturer_id')))) { + $license->manufacturer_id = null; + } else { + $license->manufacturer_id = e(Input::get('manufacturer_id')); + } + // Save the license data $license->name = e(Input::get('name')); $license->serial = e(Input::get('serial')); @@ -206,17 +211,15 @@ class LicensesController extends Controller // Show the page $license_options = array('' => 'Top Level') + DB::table('assets')->where('id', '!=', $licenseId)->pluck('name', 'id'); - $depreciation_list = array('0' => trans('admin/licenses/form.no_depreciation')) + Depreciation::pluck('name', 'id')->toArray(); - $supplier_list = array('' => 'Select Supplier') + Supplier::orderBy('name', 'asc')->pluck('name', 'id')->toArray(); $maintained_list = array('' => 'Maintained', '1' => 'Yes', '0' => 'No'); - $company_list = Helper::companyList(); return View::make('licenses/edit', compact('license')) ->with('license_options', $license_options) - ->with('depreciation_list', $depreciation_list) - ->with('supplier_list', $supplier_list) - ->with('company_list', $company_list) - ->with('maintained_list', $maintained_list); + ->with('depreciation_list', Helper::depreciationList()) + ->with('supplier_list', Helper::suppliersList()) + ->with('company_list', Helper::companyList()) + ->with('maintained_list', $maintained_list) + ->with('manufacturer_list', Helper::manufacturerList()); } @@ -253,6 +256,13 @@ class LicensesController extends Controller $license->maintained = e(Input::get('maintained')); $license->reassignable = e(Input::get('reassignable')); + if (empty(e(Input::get('manufacturer_id')))) { + $license->manufacturer_id = null; + } else { + $license->manufacturer_id = e(Input::get('manufacturer_id')); + } + + if (e(Input::get('supplier_id')) == '') { $license->supplier_id = null; } else { @@ -502,7 +512,7 @@ class LicensesController extends Controller } - if (($asset->assigned_to!='') && (($asset->assigned_to!=$assigned_to)) && ($assigned_to!='') ) { + if (($asset->assigned_to!='') && (($asset->assigned_to!=$assigned_to)) && ($assigned_to!='')) { return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.owner_doesnt_match_asset')); } @@ -987,21 +997,22 @@ class LicensesController extends Controller $actions = ''; if (Gate::allows('licenses.checkout')) { - $actions .= '' . trans('general.checkout') . ' '; + $actions .= '' . trans('general.checkout') . ' '; } if (Gate::allows('licenses.create')) { - $actions .= ''; + $actions .= ''; } if (Gate::allows('licenses.edit')) { - $actions .= ''; + $actions .= ''; } if (Gate::allows('licenses.delete')) { - $actions .= ''; + $actions .= ''; } $actions .=''; @@ -1012,15 +1023,16 @@ class LicensesController extends Controller 'totalSeats' => $license->totalSeatsByLicenseID(), 'remaining' => $license->remaincount(), 'license_name' => e($license->license_name), - 'license_email' => e($license->license_email), + 'license_email' => e($license->license_email), 'purchase_date' => ($license->purchase_date) ? $license->purchase_date : '', - 'expiration_date' => ($license->expiration_date) ? $license->expiration_date : '', + 'expiration_date' => ($license->expiration_date) ? $license->expiration_date : '', 'purchase_cost' => ($license->purchase_cost) ? number_format($license->purchase_cost, 2) : '', - 'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : '', - 'order_number' => ($license->order_number) ? e($license->order_number) : '', - 'notes' => ($license->notes) ? e($license->notes) : '', + 'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : '', + 'order_number' => ($license->order_number) ? e($license->order_number) : '', + 'notes' => ($license->notes) ? e($license->notes) : '', 'actions' => $actions, - 'companyName' => is_null($license->company) ? '' : e($license->company->name) + 'companyName' => is_null($license->company) ? '' : e($license->company->name), + 'manufacturer' => $license->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$license->manufacturer_id.'/view', $license->manufacturer->name) : '' ); } diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php index 312083bc5..666b8f8ea 100755 --- a/app/Http/Controllers/ManufacturersController.php +++ b/app/Http/Controllers/ManufacturersController.php @@ -5,7 +5,7 @@ use App\Models\Company; use App\Models\Manufacturer; use App\Models\Setting; use Auth; -use Illuminate\Support\Facades\Gate; +use Gate; use Input; use Lang; use Redirect; @@ -255,10 +255,27 @@ class ManufacturersController extends Controller * @since [v1.0] * @return String JSON */ - public function getDataView($manufacturerId) + public function getDataView($manufacturerId, $itemtype = null) { - $manufacturer = Manufacturer::with('assets.company')->find($manufacturerId); + + switch ($itemtype) { + case "assets": + return $this->getDataAssetsView($manufacturer); + case "licenses": + return $this->getDataLicensesView($manufacturer); + case "accessories": + return $this->getDataAccessoriesView($manufacturer); + case "consumables": + return $this->getDataConsumablesView($manufacturer); + } + + throw new Exception("We shouldn't be here"); + + } + + protected function getDataAssetsView(Manufacturer $manufacturer) + { $manufacturer_assets = $manufacturer->assets; if (Input::has('search')) { @@ -304,25 +321,203 @@ class ManufacturersController extends Controller } } - $row = array( - 'id' => $asset->id, - 'name' => (string)link_to('/hardware/'.$asset->id.'/view', e($asset->showAssetName())), - 'model' => e($asset->model->name), - 'asset_tag' => e($asset->asset_tag), - 'serial' => e($asset->serial), - 'assigned_to' => ($asset->assigneduser) ? (string)link_to('/admin/users/'.$asset->assigneduser->id.'/view', e($asset->assigneduser->fullName())): '', - 'actions' => $actions, - 'companyName' => e(Company::getName($asset)), - ); + $rows[] = array( + 'id' => $asset->id, + 'name' => (string)link_to('/hardware/'.$asset->id.'/view', e($asset->showAssetName())), + 'model' => e($asset->model->name), + 'asset_tag' => e($asset->asset_tag), + 'serial' => e($asset->serial), + 'assigned_to' => ($asset->assigneduser) ? (string)link_to('/admin/users/'.$asset->assigneduser->id.'/view', e($asset->assigneduser->fullName())): '', + 'actions' => $actions, + 'companyName' => e(Company::getName($asset)), + ); - if (isset($inout)) { - $row['change'] = $inout; + if (isset($inout)) { + $row['change'] = $inout; + } } - - $rows[] = $row; - } - + $data = array('total' => $count, 'rows' => $rows); return $data; } + + protected function getDataLicensesView(Manufacturer $manufacturer) + { + $licenses = $manufacturer->licenses; + + if (Input::has('search')) { + $licenses = $licenses->TextSearch(Input::get('search')); + } + + $licenseCount = $licenses->count(); + + $rows = array(); + + foreach ($licenses as $license) { + $actions = ''; + + if (Gate::allows('licenses.checkout')) { + $actions .= '' . trans('general.checkout') . ' '; + } + + if (Gate::allows('licenses.create')) { + $actions .= ''; + } + if (Gate::allows('licenses.edit')) { + $actions .= ''; + } + if (Gate::allows('licenses.delete')) { + $actions .= ''; + } + $actions .=''; + + $rows[] = array( + 'id' => $license->id, + 'name' => (string) link_to('/admin/licenses/'.$license->id.'/view', $license->name), + 'serial' => (string) link_to('/admin/licenses/'.$license->id.'/view', mb_strimwidth($license->serial, 0, 50, "...")), + 'totalSeats' => $license->totalSeatsByLicenseID(), + 'remaining' => $license->remaincount(), + 'license_name' => e($license->license_name), + 'license_email' => e($license->license_email), + 'purchase_date' => ($license->purchase_date) ? $license->purchase_date : '', + 'expiration_date' => ($license->expiration_date) ? $license->expiration_date : '', + 'purchase_cost' => ($license->purchase_cost) ? number_format($license->purchase_cost, 2) : '', + 'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : '', + 'order_number' => ($license->order_number) ? e($license->order_number) : '', + 'notes' => ($license->notes) ? e($license->notes) : '', + 'actions' => $actions, + 'companyName' => is_null($license->company) ? '' : e($license->company->name), + 'manufacturer' => $license->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$license->manufacturer_id.'/view', $license->manufacturer->name) : '' + ); + } + + $data = array('total' => $licenseCount, 'rows' => $rows); + + return $data; + } + + public function getDataAccessoriesView(Manufacturer $manufacturer) + { + $accessories = $manufacturer->accessories; + + if (Input::has('search')) { + $accessories = $accessories->TextSearch(e(Input::get('search'))); + } + + if (Input::has('limit')) { + $limit = e(Input::get('limit')); + } else { + $limit = 50; + } + + $accessCount = $accessories->count(); + + $rows = array(); + + foreach ($accessories as $accessory) { + + $actions = ''; + if (Gate::allows('accessories.checkout')) { + $actions .= 'numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . ''; + } + if (Gate::allows('accessories.edit')) { + $actions .= ''; + } + if (Gate::allows('accessories.delete')) { + $actions .= ''; + } + $actions .= ''; + $company = $accessory->company; + + $rows[] = array( + 'name' => ''. $accessory->name.'', + 'category' => ($accessory->category) ? (string)link_to('admin/settings/categories/'.$accessory->category->id.'/view', $accessory->category->name) : '', + 'qty' => e($accessory->qty), + 'order_number' => e($accessory->order_number), + 'min_amt' => e($accessory->min_amt), + 'location' => ($accessory->location) ? e($accessory->location->name): '', + 'purchase_date' => e($accessory->purchase_date), + 'purchase_cost' => number_format($accessory->purchase_cost, 2), + 'numRemaining' => $accessory->numRemaining(), + 'actions' => $actions, + 'companyName' => is_null($company) ? '' : e($company->name), + 'manufacturer' => $accessory->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$accessory->manufacturer_id.'/view', $accessory->manufacturer->name) : '' + + ); + } + + $data = array('total'=>$accessCount, 'rows'=>$rows); + + return $data; + } + + public function getDataConsumablesView($manufacturer) + { + $consumables = $manufacturer->consumables; + + if (Input::has('search')) { + $consumables = $consumables->TextSearch(e(Input::get('search'))); + } + + if (Input::has('limit')) { + $limit = e(Input::get('limit')); + } else { + $limit = 50; + } + + $consumCount = $consumables->count(); + + $rows = array(); + + foreach ($consumables as $consumable) { + $actions = ''; + if (Gate::allows('consumables.checkout')) { + $actions .= 'numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . ''; + } + + if (Gate::allows('consumables.edit')) { + $actions .= ''; + } + if (Gate::allows('consumables.delete')) { + $actions .= ''; + } + + $actions .=''; + + $company = $consumable->company; + + $rows[] = array( + 'id' => $consumable->id, + 'name' => (string)link_to('admin/consumables/'.$consumable->id.'/view', e($consumable->name)), + 'location' => ($consumable->location) ? e($consumable->location->name) : '', + 'min_amt' => e($consumable->min_amt), + 'qty' => e($consumable->qty), + 'manufacturer' => ($consumable->manufacturer) ? (string) link_to('/admin/settings/manufacturers/'.$consumable->manufacturer_id.'/view', $consumable->manufacturer->name): '', + 'model_no' => e($consumable->model_no), + 'item_no' => e($consumable->item_no), + 'category' => ($consumable->category) ? (string) link_to('/admin/settings/categories/'.$consumable->category_id.'/view', $consumable->category->name) : 'Missing category', + 'order_number' => e($consumable->order_number), + 'purchase_date' => e($consumable->purchase_date), + 'purchase_cost' => ($consumable->purchase_cost!='') ? number_format($consumable->purchase_cost, 2): '' , + 'numRemaining' => $consumable->numRemaining(), + 'actions' => $actions, + 'companyName' => is_null($company) ? '' : e($company->name), + ); + } + + $data = array('total' => $consumCount, 'rows' => $rows); + + return $data; + } } diff --git a/app/Http/routes.php b/app/Http/routes.php index 8f7404d22..25feecf9c 100755 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -78,7 +78,7 @@ Route::group([ 'prefix' => 'api', 'middleware' => 'auth' ], function () { /*---Manufacturers API---*/ Route::group(array('prefix'=>'manufacturers'), function () { Route::get('list', array('as'=>'api.manufacturers.list', 'uses'=>'ManufacturersController@getDatatable')); - Route::get('{manufacturerID}/view', array('as'=>'api.manufacturers.view', 'uses'=>'ManufacturersController@getDataView')); + Route::get('{manufacturerID}/view/{itemtype}', array('as'=>'api.manufacturers.view', 'uses'=>'ManufacturersController@getDataView')); }); /*---Suppliers API---*/ diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index 1a37a6a59..8bd139b49 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -82,6 +82,11 @@ class Accessory extends Model return $this->belongsToMany('\App\Models\User', 'accessories_users', 'accessory_id', 'assigned_to')->count(); } + public function manufacturer() + { + return $this->belongsTo('\App\Models\Manufacturer', 'manufacturer_id'); + } + public function checkin_email() { return $this->category->checkin_email; diff --git a/app/Models/License.php b/app/Models/License.php index 843a74c4f..4444ac649 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -36,6 +36,11 @@ class License extends Depreciable return $this->belongsTo('\App\Models\Company', 'company_id'); } + public function manufacturer() + { + return $this->belongsTo('\App\Models\Manufacturer', 'manufacturer_id'); + } + /** * Get the assigned user */ diff --git a/app/Models/Manufacturer.php b/app/Models/Manufacturer.php index cc10833f8..c5d5b8e04 100755 --- a/app/Models/Manufacturer.php +++ b/app/Models/Manufacturer.php @@ -46,6 +46,21 @@ class Manufacturer extends Model return $this->hasManyThrough('\App\Models\Asset', '\App\Models\AssetModel', 'manufacturer_id', 'model_id'); } + public function licenses() + { + return $this->hasMany('\App\Models\License', 'manufacturer_id'); + } + + public function accessories() + { + return $this->hasMany('\App\Models\Accessory', 'manufacturer_id'); + } + + public function consumables() + { + return $this->hasMany('\App\Models\Consumable', 'manufacturer_id'); + } + /** * Query builder scope to search on text * diff --git a/database/migrations/2016_08_09_002225_add_manufacturer_to_licenses.php b/database/migrations/2016_08_09_002225_add_manufacturer_to_licenses.php new file mode 100644 index 000000000..4b7dc0a09 --- /dev/null +++ b/database/migrations/2016_08_09_002225_add_manufacturer_to_licenses.php @@ -0,0 +1,32 @@ +integer('manufacturer_id')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('licenses', function (Blueprint $table) { + // + }); + } +} diff --git a/database/migrations/2016_08_12_121613_add_manufacturer_to_accessories_table.php b/database/migrations/2016_08_12_121613_add_manufacturer_to_accessories_table.php new file mode 100644 index 000000000..0415f1451 --- /dev/null +++ b/database/migrations/2016_08_12_121613_add_manufacturer_to_accessories_table.php @@ -0,0 +1,33 @@ +integer('manufacturer_id')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('accessories', function (Blueprint $table) { + // + $table->dropColumn('manufacturer_id'); + }); + } +} diff --git a/resources/views/accessories/edit.blade.php b/resources/views/accessories/edit.blade.php index 99f2cd5ed..a422d225e 100755 --- a/resources/views/accessories/edit.blade.php +++ b/resources/views/accessories/edit.blade.php @@ -86,6 +86,18 @@ + +
+
+ {{ Form::label('manufacturer_id', trans('general.manufacturer')) }} +
+ +
+ {{ Form::select('manufacturer_id', $manufacturer_list , Input::old('manufacturer_id', $accessory->manufacturer_id), array('class'=>'select2', 'style'=>'width:350px')) }} + {!! $errors->first('manufacturer_id', '
:message
') !!} +
+
+
diff --git a/resources/views/accessories/index.blade.php b/resources/views/accessories/index.blade.php index 827719672..1ad97dfdd 100755 --- a/resources/views/accessories/index.blade.php +++ b/resources/views/accessories/index.blade.php @@ -35,6 +35,7 @@ {{ trans('admin/companies/table.title') }} {{ trans('admin/accessories/table.title') }} {{ trans('admin/accessories/general.accessory_category') }} + {{ trans('general.manufacturer') }} {{ trans('general.location') }} {{ trans('admin/accessories/general.total') }} {{ trans('admin/accessories/general.date') }} diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 302e255e1..6321dd1e9 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -43,8 +43,6 @@
- - +
-
- - +
+
+ @@ -478,157 +480,150 @@ - - - @if (count($asset->assetlog) > 0) - @foreach ($asset->assetlog as $log) - - - - - - + @if (count($asset->assetlog) > 0) + @foreach ($asset->assetlog as $log) + + + + + - + - + + - @endforeach + @endforeach @endif + - - - - - + + + + + - -
{{ trans('general.date') }} {{ trans('general.admin') }}{{ trans('general.user') }} {{ trans('general.notes') }}
{{ $log->created_at }} - @if (isset($log->adminlog)) - {{ $log->adminlog->fullName() }} - @else - Deleted Admin - @endif - {{ $log->action_type }} + +
{{ $log->created_at }} + @if (isset($log->adminlog)) + {{ $log->adminlog->fullName() }} + @else + Deleted Admin + @endif + {{ $log->action_type }} @if ((isset($log->checkedout_to)) && ($log->checkedout_to!=0) && ($log->checkedout_to!='')) - @if ($log->userlog) + @if ($log->userlog) - @if ($log->userlog->deleted_at=='') - - {{ $log->userlog->fullName() }} - - @else - {{ $log->userlog->fullName() }} - @endif - @else - Deleted User - @endif + @if ($log->userlog->deleted_at=='') + + {{ $log->userlog->fullName() }} + + + @else + {{ $log->userlog->fullName() }} + @endif + @else + Deleted User + @endif @endif - + @if ($log->note) {{ $log->note }} @endif -
{{ $asset->created_at }} - @if ($asset->adminuser) - {{ $asset->adminuser->fullName() }} - @else - {{ trans('general.unknown_admin') }} - @endif - - {{ trans('general.created_asset') }} - - {{ $asset->created_at }} + @if ($asset->adminuser) + {{ $asset->adminuser->fullName() }} + @else + {{ trans('general.unknown_admin') }} + @endif + {{ trans('general.created_asset') }}
-
-
-
+ + +
+
+
+
+ {{ Form::open([ + 'method' => 'POST', + 'route' => ['upload/asset', $asset->id], + 'files' => true, 'class' => 'form-horizontal' ]) }} - {{ Form::open([ - 'method' => 'POST', - 'route' => ['upload/asset', $asset->id], - 'files' => true, 'class' => 'form-horizontal' ]) }} +
+ Browse for file... + {{ Form::file('assetfile[]', ['multiple' => 'multiple']) }} + +
+
+ {{ Form::text('notes', Input::old('notes', Input::old('notes')), array('class' => 'form-control','placeholder' => 'Notes')) }} +
+
+ +
-
- Browse for file... - {{ Form::file('assetfile[]', ['multiple' => 'multiple']) }} - -
-
- {{ Form::text('notes', Input::old('notes', Input::old('notes')), array('class' => 'form-control','placeholder' => 'Notes')) }} -
-
- -
+
+

{{ trans('admin/hardware/general.filetype_info') }}

+
+
-
-

{{ trans('admin/hardware/general.filetype_info') }}

-
-
+ {{ Form::close() }} - {{ Form::close() }} +
-
- - - +
- - - - - - - + + + + + + + - @if (count($asset->uploads) > 0) - @foreach ($asset->uploads as $file) - - - - - - - - @endforeach - @else - - - + @if (count($asset->uploads) > 0) + @foreach ($asset->uploads as $file) + + + + + + + + @endforeach + @else + + + - @endif + @endif -
{{ trans('general.notes') }}{{ trans('general.file_name') }}
{{ trans('general.notes') }}{{ trans('general.file_name') }}
- @if ($file->note) - {{ $file->note }} - @endif - - @if ( \App\Helpers\Helper::checkUploadIsImage($file->get_src('assets'))) - - @endif - - {{ $file->filename }} - - @if ($file->filename) - {{ trans('general.download') }} - @endif - - -
- {{ trans('general.no_results') }} -
+ @if ($file->note) + {{ $file->note }} + @endif + + @if ( \App\Helpers\Helper::checkUploadIsImage($file->get_src('assets'))) + + @endif + + {{ $file->filename }} + + @if ($file->filename) + {{ trans('general.download') }} + @endif + + +
+ {{ trans('general.no_results') }} +
-
-
-
- -
- - - - + + + + + + + + @section('moar_scripts')