2022-11-02 02:23:52 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\AssetModel;
|
|
|
|
use App\Models\Category;
|
|
|
|
use App\Models\Company;
|
2024-02-21 09:31:01 -08:00
|
|
|
use App\Models\CustomField;
|
2022-11-02 02:23:52 -07:00
|
|
|
use App\Models\Labels\Label;
|
2023-09-28 13:40:51 -07:00
|
|
|
use App\Models\Location;
|
2022-11-02 02:23:52 -07:00
|
|
|
use App\Models\Manufacturer;
|
|
|
|
use App\Models\Setting;
|
2023-09-28 13:40:51 -07:00
|
|
|
use App\Models\Supplier;
|
2022-11-02 02:23:52 -07:00
|
|
|
use App\Models\User;
|
|
|
|
use App\View\Label as LabelView;
|
|
|
|
|
|
|
|
class LabelsController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns the Label view with test data
|
|
|
|
*
|
2024-03-26 16:10:08 -07:00
|
|
|
* @param string $labelName
|
|
|
|
* @author Grant Le Roux <grant.leroux+snipe-it@gmail.com>
|
2022-11-02 02:23:52 -07:00
|
|
|
*/
|
|
|
|
public function show(string $labelName)
|
|
|
|
{
|
|
|
|
$labelName = str_replace('/', '\\', $labelName);
|
|
|
|
$template = Label::find($labelName);
|
|
|
|
|
2024-02-21 09:31:01 -08:00
|
|
|
$exampleAsset = new Asset();
|
2024-02-15 11:50:41 -08:00
|
|
|
|
2024-02-21 09:31:01 -08:00
|
|
|
$exampleAsset->id = 999999;
|
|
|
|
$exampleAsset->name = 'JEN-867-5309';
|
|
|
|
$exampleAsset->asset_tag = '100001';
|
|
|
|
$exampleAsset->serial = 'SN9876543210';
|
|
|
|
$exampleAsset->asset_eol_date = '2025-01-01';
|
|
|
|
$exampleAsset->order_number = '12345';
|
|
|
|
$exampleAsset->purchase_date = '2023-01-01';
|
|
|
|
$exampleAsset->status_id = 1;
|
2024-02-15 11:50:41 -08:00
|
|
|
|
2024-02-21 09:31:01 -08:00
|
|
|
$exampleAsset->company = new Company([
|
|
|
|
'name' => trans('admin/labels/table.example_company'),
|
|
|
|
'phone' => '1-555-555-5555',
|
|
|
|
'email' => 'company@example.com',
|
|
|
|
]);
|
2024-02-15 11:50:41 -08:00
|
|
|
|
2024-02-21 09:31:01 -08:00
|
|
|
$exampleAsset->setRelation('assignedTo', new User(['first_name' => 'Luke', 'last_name' => 'Skywalker']));
|
|
|
|
$exampleAsset->defaultLoc = new Location(['name' => trans('admin/labels/table.example_defaultloc'), 'phone' => '1-555-555-5555']);
|
|
|
|
$exampleAsset->location = new Location(['name' => trans('admin/labels/table.example_location'), 'phone' => '1-555-555-5555']);
|
2024-02-15 11:50:41 -08:00
|
|
|
|
2024-02-21 09:31:01 -08:00
|
|
|
$exampleAsset->model = new AssetModel();
|
|
|
|
$exampleAsset->model->id = 999999;
|
|
|
|
$exampleAsset->model->name = trans('admin/labels/table.example_model');
|
|
|
|
$exampleAsset->model->model_number = 'MDL5678';
|
|
|
|
$exampleAsset->model->manufacturer = new Manufacturer();
|
|
|
|
$exampleAsset->model->manufacturer->id = 999999;
|
|
|
|
$exampleAsset->model->manufacturer->name = trans('admin/labels/table.example_manufacturer');
|
|
|
|
$exampleAsset->model->manufacturer->support_email = 'support@test.com';
|
|
|
|
$exampleAsset->model->manufacturer->support_phone = '1-555-555-5555';
|
|
|
|
$exampleAsset->model->manufacturer->support_url = 'https://example.com';
|
|
|
|
$exampleAsset->supplier = new Supplier(['name' => trans('admin/labels/table.example_company')]);
|
|
|
|
$exampleAsset->model->category = new Category();
|
|
|
|
$exampleAsset->model->category->id = 999999;
|
|
|
|
$exampleAsset->model->category->name = trans('admin/labels/table.example_category');
|
|
|
|
|
2024-04-03 11:03:58 -07:00
|
|
|
$customFieldColumns = CustomField::where('field_encrypted', '=', 0)->pluck('db_column');
|
2024-02-15 12:34:09 -08:00
|
|
|
|
2024-02-15 13:26:47 -08:00
|
|
|
collect(explode(';', Setting::getSettings()->label2_fields))
|
2024-02-21 11:38:03 -08:00
|
|
|
->filter()
|
2024-02-21 09:31:01 -08:00
|
|
|
->each(function ($item) use ($customFieldColumns, $exampleAsset) {
|
2024-03-28 05:25:29 -07:00
|
|
|
$pair = explode('=', $item);
|
|
|
|
|
|
|
|
if (array_key_exists(1, $pair)) {
|
|
|
|
if ($customFieldColumns->contains($pair[1])) {
|
|
|
|
$exampleAsset->{$pair[1]} = "{{$pair[0]}}";
|
|
|
|
}
|
|
|
|
}
|
2024-02-15 13:26:47 -08:00
|
|
|
});
|
2024-02-15 12:02:08 -08:00
|
|
|
|
2022-11-02 04:30:45 -07:00
|
|
|
$settings = Setting::getSettings();
|
|
|
|
if (request()->has('settings')) {
|
|
|
|
$overrides = request()->get('settings');
|
|
|
|
foreach ($overrides as $key => $value) {
|
|
|
|
$settings->$key = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-02 02:23:52 -07:00
|
|
|
return (new LabelView())
|
2023-01-31 22:58:58 -08:00
|
|
|
->with('assets', collect([$exampleAsset]))
|
2022-11-02 04:30:45 -07:00
|
|
|
->with('settings', $settings)
|
2022-11-02 02:23:52 -07:00
|
|
|
->with('template', $template)
|
|
|
|
->with('bulkedit', false)
|
|
|
|
->with('count', 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|