Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Oct 6, 2023
2 parents 9596826 + 890efb1 commit a95fae0
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ public function create($component_asset_id)
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function store(Request $request, $component_asset_id)
public function store(Request $request, $component_asset_id, $backto = null)
{
if ($component_assets = DB::table('components_assets')->find($component_asset_id)) {
if (is_null($component = Component::find($component_assets->component_id))) {

return redirect()->route('components.index')->with('error',
trans('admin/components/message.not_found'));
}
Expand Down Expand Up @@ -95,6 +96,10 @@ public function store(Request $request, $component_asset_id)
$asset = Asset::find($component_assets->asset_id);

event(new CheckoutableCheckedIn($component, $asset, Auth::user(), $request->input('note'), Carbon::now()));
if($backto == 'asset'){
return redirect()->route('hardware.view', $asset->id)->with('success',
trans('admin/components/message.checkin.success'));
}

return redirect()->route('components.index')->with('success',
trans('admin/components/message.checkin.success'));
Expand Down
24 changes: 13 additions & 11 deletions app/Http/Transformers/ActionlogsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,26 @@ public function changedInfo(array $clean_meta)


if(array_key_exists('rtd_location_id',$clean_meta)) {
$clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."] ". $location->find($clean_meta['rtd_location_id']['old'])->name : trans('general.unassigned');
$clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."] ". $location->find($clean_meta['rtd_location_id']['new'])->name : trans('general.unassigned');
$clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."] ". e($location->find($clean_meta['rtd_location_id']['old'])->name) : trans('general.unassigned');
$clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."] ". e($location->find($clean_meta['rtd_location_id']['new'])->name) : trans('general.unassigned');
$clean_meta['Default Location'] = $clean_meta['rtd_location_id'];
unset($clean_meta['rtd_location_id']);
}
if(array_key_exists('location_id', $clean_meta)) {
$clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."] ".$location->find($clean_meta['location_id']['old'])->name : trans('general.unassigned');
$clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."] ".$location->find($clean_meta['location_id']['new'])->name : trans('general.unassigned');

if (array_key_exists('location_id', $clean_meta)) {
$clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."] ".e($location->find($clean_meta['location_id']['old'])->name): trans('general.unassigned');
$clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."] ".e($location->find($clean_meta['location_id']['new'])->name) : trans('general.unassigned');
$clean_meta['Current Location'] = $clean_meta['location_id'];
unset($clean_meta['location_id']);
}

if(array_key_exists('model_id', $clean_meta)) {

$oldModel = $model->find($clean_meta['model_id']['old']);
$oldModelName = $oldModel->name ?? trans('admin/models/message.deleted');
$oldModelName = $oldModel ? e($oldModel->name) : trans('admin/models/message.deleted');

$newModel = $model->find($clean_meta['model_id']['new']);
$newModelName = $newModel->name ?? trans('admin/models/message.deleted');
$newModelName = $newModel ? e($newModel->name) : trans('admin/models/message.deleted');

$clean_meta['model_id']['old'] = "[id: ".$clean_meta['model_id']['old']."] ".$oldModelName;
$clean_meta['model_id']['new'] = "[id: ".$clean_meta['model_id']['new']."] ".$newModelName; /** model is required at asset creation */
Expand All @@ -206,10 +208,10 @@ public function changedInfo(array $clean_meta)
if(array_key_exists('company_id', $clean_meta)) {

$oldCompany = $company->find($clean_meta['company_id']['old']);
$oldCompanyName = $oldCompany->name ?? trans('admin/companies/message.deleted');
$oldCompanyName = $oldCompany ? e($oldCompany->name) : trans('admin/company/message.deleted');

$newCompany = $company->find($clean_meta['company_id']['new']);
$newCompanyName = $newCompany->name ?? trans('admin/companies/message.deleted');
$newCompanyName = $newCompany ? e($newCompany->name) : trans('admin/company/message.deleted');

$clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? "[id: ".$clean_meta['company_id']['old']."] ". $oldCompanyName : trans('general.unassigned');
$clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? "[id: ".$clean_meta['company_id']['new']."] ". $newCompanyName : trans('general.unassigned');
Expand All @@ -219,10 +221,10 @@ public function changedInfo(array $clean_meta)
if(array_key_exists('supplier_id', $clean_meta)) {

$oldSupplier = $supplier->find($clean_meta['supplier_id']['old']);
$oldSupplierName = $oldSupplier->name ?? trans('admin/suppliers/message.deleted');
$oldSupplierName = $oldSupplier ? e($oldSupplier->name) : trans('admin/suppliers/message.deleted');

$newSupplier = $supplier->find($clean_meta['supplier_id']['new']);
$newSupplierName = $newSupplier->name ?? trans('admin/suppliers/message.deleted');
$newSupplierName = $newSupplier ? e($newSupplier->name) : trans('admin/suppliers/message.deleted');

$clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? "[id: ".$clean_meta['supplier_id']['old']."] ". $oldSupplierName : trans('general.unassigned');
$clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? "[id: ".$clean_meta['supplier_id']['new']."] ". $newSupplierName : trans('general.unassigned');
Expand Down
4 changes: 3 additions & 1 deletion app/Models/Labels/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function toArray(Asset $asset) { return Field::makeArray($this, $asset);

public static function makeArray(Field $field, Asset $asset) {
return $field->getOptions()
// filter out any FieldOptions that are accidentally null
->filter()
->map(fn($option) => $option->toArray($asset))
->filter(fn($result) => $result['value'] != null);
}
Expand All @@ -36,4 +38,4 @@ public static function fromString(string $theString) {
->map(fn($optionString) => FieldOption::fromString($optionString));
return $field;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Carbon\CarbonImmutable;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Log;

Expand All @@ -22,38 +23,33 @@ public function up()


// Update the eol_explicit column with the value from asset_eol_date if it exists and is different from the calculated value
Asset::whereNotNull('asset_eol_date')->with('model')->chunkById(500, function ($assetsWithEolDates) {
foreach ($assetsWithEolDates as $asset) {
if ($asset->asset_eol_date && $asset->purchase_date) {
try {
$months = CarbonImmutable::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date);
} catch (\Exception $e) {
Log::info('asset_eol_date invalid for asset '.$asset->id);
}
if ($asset->model->eol) {
if ($months != $asset->model->eol) {
Asset::whereNotNull('asset_eol_date')->with('model')->chunkById(500, function ($assetsWithEolDates) {
foreach ($assetsWithEolDates as $asset) {
if ($asset->asset_eol_date && $asset->purchase_date) {
try {
$months = CarbonImmutable::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date);
} catch (\Exception $e) {
Log::info('asset_eol_date invalid for asset ' . $asset->id);
}
if ($asset->model->eol) {
if ($months != $asset->model->eol) {
$asset->update(['eol_explicit' => true]);
}
} else {
$asset->update(['eol_explicit' => true]);
}
} else {
$asset->update(['eol_explicit' => true]);
}
}
}
});
});

// Update the asset_eol_date column with the calculated value if it doesn't exist
Asset::whereNull('asset_eol_date')->with('model')->chunkById(500, function ($assets) {
foreach ($assets as $asset) {
if ($asset->model->eol && $asset->purchase_date) {
try {
$asset_eol_date = CarbonImmutable::parse($asset->purchase_date)->addMonths($asset->model->eol)->format('Y-m-d');
$asset->update(['asset_eol_date' => $asset_eol_date]);
} catch (\Exception $e) {
Log::info('purchase date invalid for asset '.$asset->id);
}
}
}
});
DB::table('assets')
->whereNull('asset_eol_date')
->whereNotNull('purchase_date')
->whereNotNull('model_id')
->join('models', 'assets.model_id', '=', 'models.id')
->update([
'asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL models.eol MONTH)')
]);
}


Expand Down
Loading

0 comments on commit a95fae0

Please sign in to comment.