Merge branch 'v3' into Fix-Asset-Creation-with-old-data

This commit is contained in:
Daniel Meltzer 2016-06-10 07:35:30 -05:00
commit 9c4c91063f
6 changed files with 60 additions and 53 deletions

View file

@ -113,7 +113,12 @@ class ObjectImportCommand extends Command {
$item_status_name = $this->array_smart_fetch($row, "status");
$item["item_name"] = $this->array_smart_fetch($row, "item name");
$item["purchase_date"] = date("Y-m-d 00:00:01", strtotime($this->array_smart_fetch($row, "purchase date")));
if ($this->array_smart_fetch($row, "purchase date")!='') {
$item["purchase_date"] = date("Y-m-d 00:00:01", strtotime($this->array_smart_fetch($row, "purchase date")));
} else {
$item["purchase_date"] = null;
}
$item["purchase_cost"] = $this->array_smart_fetch($row, "purchase cost");
$item["order_number"] = $this->array_smart_fetch($row, "order number");
$item["notes"] = $this->array_smart_fetch($row, "notes");

View file

@ -10,7 +10,6 @@ use App\Models\Actionlog;
use App\Models\Asset;
use App\Models\AssetMaintenance;
use App\Models\AssetModel;
use App\Models\AssetModels;
use App\Models\Company;
use App\Models\CustomField;
use App\Models\Depreciation;
@ -256,8 +255,9 @@ class AssetsController extends Controller
*/
public function getEdit($assetId = null)
{
// Check if the asset exists
if (is_null($asset = Asset::find($assetId))) {
if (!$asset = Asset::find($assetId)) {
// Redirect to the asset management page
return redirect()->to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
} elseif (!Company::isCurrentUserHasAccess($asset)) {
@ -296,80 +296,79 @@ class AssetsController extends Controller
* @since [v1.0]
* @return Redirect
*/
public function postEdit($assetId = null, AssetRequest $request)
{
exit;
// Check if the asset exists
if (is_null($asset = Asset::find($assetId))) {
if (!$asset = Asset::find($assetId)) {
// Redirect to the asset management page with error
return redirect()->to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
} elseif (!Company::isCurrentUserHasAccess($asset)) {
return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions'));
}
if (e(Input::get('status_id')) == '') {
if ($request->has('status_id')) {
$asset->status_id = e($request->input('status_id'));
} else {
$asset->status_id = null;
} else {
$asset->status_id = e(Input::get('status_id'));
}
if (e(Input::get('warranty_months')) == '') {
if ($request->has('warranty_months')) {
$asset->warranty_months = e($request->input('warranty_months'));
} else {
$asset->warranty_months = null;
} else {
$asset->warranty_months = e(Input::get('warranty_months'));
}
if (e(Input::get('purchase_cost')) == '') {
if ($request->has('purchase_cost')) {
$asset->purchase_cost = e($request->input('purchase_cost'));
} else {
$asset->purchase_cost = null;
} else {
$asset->purchase_cost = e(Input::get('purchase_cost'));
}
if (e(Input::get('purchase_date')) == '') {
if ($request->has('purchase_date')) {
$asset->purchase_date = e($request->input('purchase_date'));
} else {
$asset->purchase_date = null;
} else {
$asset->purchase_date = e(Input::get('purchase_date'));
}
if (e(Input::get('supplier_id')) == '') {
if ($request->has('supplier_id')) {
$asset->supplier_id = e($request->input('supplier_id'));
} else {
$asset->supplier_id = null;
} else {
$asset->supplier_id = e(Input::get('supplier_id'));
}
if (e(Input::get('requestable')) == '') {
$asset->requestable = 0;
if ($request->has('requestable')) {
$asset->requestable = e($request->input('requestable'));
} else {
$asset->requestable = e(Input::get('requestable'));
$asset->requestable = null;
}
if (e(Input::get('rtd_location_id')) == '') {
$asset->rtd_location_id = 0;
if ($request->has('rtd_location_id')) {
$asset->rtd_location_id = e($request->input('rtd_location_id'));
} else {
$asset->rtd_location_id = e(Input::get('rtd_location_id'));
$asset->requestable = null;
}
if (Input::has('image_delete')) {
if ($request->has('image_delete')) {
unlink(public_path().'/uploads/assets/'.$asset->image);
$asset->image = '';
}
$checkModel = config('app.url').'/api/models/'.e(Input::get('model_id')).'/check';
// Update the asset data
$asset->name = e(Input::get('name'));
$asset->serial = e(Input::get('serial'));
$asset->company_id = Company::getIdForCurrentUser(e(Input::get('company_id')));
$asset->model_id = e(Input::get('model_id'));
$asset->order_number = e(Input::get('order_number'));
$asset->asset_tag = e(Input::get('asset_tag'));
$asset->notes = e(Input::get('notes'));
$asset->name = e($request->input('name'));
$asset->serial = e($request->input('serial'));
$asset->company_id = Company::getIdForCurrentUser(e($request->input('company_id')));
$asset->model_id = e($request->input('model_id'));
$asset->order_number = e($request->input('order_number'));
$asset->asset_tag = e($request->input('asset_tag'));
$asset->notes = e($request->input('notes'));
$asset->physical = '1';
// Update the image
if (Input::has('image')) {
$image = Input::get('image');
$image = $request->input('image');
$header = explode(';', $image, 2)[0];
$extension = substr( $header, strpos($header, '/')+1);
$image = substr( $image, strpos($image, ',')+1);
@ -697,9 +696,7 @@ class AssetsController extends Controller
$asset = Asset::find($assetId);
$size = Helper::barcodeDimensions($settings->barcode_type);
if (!Company::isCurrentUserHasAccess($asset)) {
return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions'));
}
if (isset($asset->id,$asset->asset_tag)) {
$barcode = new \Com\Tecnick\Barcode\Barcode();
@ -726,9 +723,6 @@ class AssetsController extends Controller
$settings = Setting::getSettings();
$asset = Asset::find($assetId);
if (!Company::isCurrentUserHasAccess($asset)) {
return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions'));
}
if (isset($asset->id,$asset->asset_tag)) {
$barcode = new \Com\Tecnick\Barcode\Barcode();

View file

@ -338,6 +338,7 @@ class SettingsController extends Controller
$setting->locale = e(Input::get('locale', 'en'));
$setting->qr_code = e(Input::get('qr_code', '0'));
$setting->full_multiple_companies_support = e(Input::get('full_multiple_companies_support', '0'));
$setting->alt_barcode = e(Input::get('alt_barcode'));
$setting->alt_barcode_enabled = e(Input::get('alt_barcode_enabled', '0'));
$setting->barcode_type = e(Input::get('barcode_type'));

View file

@ -3,6 +3,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Watson\Validating\ValidatingTrait;
use Auth;
/**
* Model for Companies.
@ -101,14 +102,14 @@ final class Company extends Model
} else {
$current_user_company_id = Auth::user()->company_id;
$companyable_company_id = $companyable->company_id;
return ($current_user_company_id == null || $current_user_company_id == $companyable_company_id);
return ($current_user_company_id == null || $current_user_company_id == $companyable_company_id || Auth::user()->isSuperUser());
}
}
public static function isCurrentUserAuthorized()
{
return (!static::isFullMultipleCompanySupportEnabled() || Auth::user()->company_id == null);
return ((!static::isFullMultipleCompanySupportEnabled()) || (Auth::user()->company_id == null) || (Auth::user()->isSuperUser()));
}
public static function canManageUsersCompanies()

View file

@ -15,7 +15,7 @@
{{ trans('general.back') }}</a>
@stop
@include('partials/modals')
{{-- Page content --}}
@ -309,6 +309,7 @@
@section('moar_scripts')
@include('partials/modals')
<script>
function fetchCustomFields() {

View file

@ -93,7 +93,7 @@
@foreach ($assets as $asset)
<?php $count++; ?>
<div class="label" {!! ($count % $settings->labels_per_page == 0) ? 'style="margin-bottom: 0px;"' : '' !!}>
<div class="label"{!! ($count % $settings->labels_per_page == 0) ? ' style="margin-bottom: 0px;"' : '' !!}>
@if ($settings->qr_code=='1')
<div class="qr_img">
@ -102,23 +102,28 @@
@endif
<div class="qr_text">
<div class="pull-left">
@if ($settings->qr_text!='')
<strong>{{ $settings->qr_text }}</strong>
<br>
<br>
@endif
</div>
<div class="pull-left">
@if (($settings->labels_display_name=='1') && ($asset->name!=''))
N: {{ $asset->name }}
<br>
@endif
</div>
<div class="pull-left">
@if (($settings->labels_display_tag=='1') && ($asset->asset_tag!=''))
T: {{ $asset->asset_tag }}
<br>
@endif
</div>
<div class="pull-left">
@if (($settings->labels_display_serial=='1') && ($asset->serial!=''))
S: {{ $asset->serial }}
@endif
</div>
</div>
@if ((($settings->alt_barcode_enabled=='1') && $settings->alt_barcode!=''))