Compare commits

...

610 Commits

Author SHA1 Message Date
Brady Wetherington
bf6c48d695 Clean up the fieldset experience for custom fields for users 2023-09-21 14:56:29 +01:00
Brady Wetherington
8428b2a04a Merge branch 'has_custom_fields_trait_rebase' into custom_fields_on_user 2023-09-18 13:45:35 +01:00
Brady Wetherington
71e745d966 Clean up this migration so it runs forwards and backwards OK 2023-09-14 21:14:26 +01:00
Brady Wetherington
a3a786f2af Merge branch 'develop' into has_custom_fields_trait_rebase 2023-09-14 20:27:06 +01:00
snipe
f6a11ac0ed Merge pull request #13586 from inietov/fixes/call_to_member_function_checkedOutToUser
Fixed Call to a member function checkedOutToUser() on null [rollbar-3598]
2023-09-12 08:35:30 +01:00
Ivan Nieto Vivanco
9cbd2d032c Add a boolean variable and condition to handle the call to checkedOutToUser() method 2023-09-11 17:40:59 -06:00
snipe
a49d3fe131 Merge pull request #13526 from Godmartinz/asset-model-notifs
Added threshold notifications and min qty for Asset models
2023-09-11 17:55:34 +01:00
Godfrey Martinez
a26b96185b Merge branch 'develop' into asset-model-notifs 2023-09-11 09:37:22 -07:00
Godfrey M
0eb50ceb3d removes commented code 2023-09-11 09:36:38 -07:00
snipe
dc74fb133f Merge pull request #13577 from marcusmoore/fixes/improve-testcase
Fixed failing test
2023-09-08 07:08:21 +01:00
Marcus Moore
093bf57448 Update assertion and add failure messages 2023-09-07 16:42:49 -07:00
snipe
06836663c8 Merge pull request #13575 from marcusmoore/fixes/improve-api-messaging
Added validation around department_id in API patch request
2023-09-07 21:36:20 +01:00
Marcus Moore
c6c1c64c1e Remove todo 2023-09-07 13:30:05 -07:00
Marcus Moore
4caa501996 Relax property type check 2023-09-07 13:28:32 -07:00
Marcus Moore
a7a70f6981 Test permissions update 2023-09-07 13:21:27 -07:00
Marcus Moore
39ff575ac1 Remove unused test cases 2023-09-07 13:16:08 -07:00
snipe
02c187b0a0 Merge pull request #13566 from snipe/features/13562_add_inline_file_link
Fixed #13562 - Added inline file link
2023-09-07 20:50:13 +01:00
snipe
7f892bf5ef Merge pull request #13574 from inietov/fixes/unaccepted_assets_report_incorrect
Fixed Unaccepted Assets report has incorrect people [freshdesk-37808]
2023-09-07 20:49:40 +01:00
Marcus Moore
56e6205667 Formatting 2023-09-07 12:45:03 -07:00
Ivan Nieto Vivanco
abd2ed3b81 Filter unaccepted assets that are not assigned to users 2023-09-07 13:39:16 -06:00
Marcus Moore
899c2eb19b Implement test case 2023-09-07 12:34:50 -07:00
snipe
894c34ff4f Update to only use relative paths
Signed-off-by: snipe <snipe@snipe.net>
2023-09-07 20:22:14 +01:00
snipe
b7c2b9374c Merge pull request #13573 from snipe/upgrade_scim_server
Upgrade to new branch for our fork of laravel-scim-server
2023-09-07 20:07:59 +01:00
Brady Wetherington
3184f795c2 Upgrade to new branch for our fork of laravel-scim-server 2023-09-07 18:29:23 +01:00
snipe
67cad9c751 Merge pull request #13571 from inietov/fixes/require_acceptance_on_null
Fixed Attempt to read property require_acceptance on null [rollbar-3557]
2023-09-07 18:11:42 +01:00
snipe
ec5238ff06 Merge pull request #13548 from marcusmoore/update-testing-documentation
Updated testing documentation
2023-09-07 11:25:53 +01:00
Marcus Moore
1c3c36f2a0 Begin to implement patch test 2023-09-06 16:14:14 -07:00
Ivan Nieto Vivanco
1509c512a5 Add guard clauses around some License and LicenseSeat models functions 2023-09-06 11:54:11 -06:00
snipe
e920199626 Merge pull request #13567 from johnson-yi/fixes/add_default_location_to_checkin_actionlog
Add default location to tracked changes on checkin actionlog
2023-09-06 09:37:04 +01:00
johnson-yi
5897f4d6d9 Add rtd_location_id to tracked changes on checkin actionlog 2023-09-06 00:36:48 +00:00
Brady Wetherington
0086adab86 Refactor out common code for 'custom fields view' partial 2023-09-05 20:45:43 +01:00
snipe
a67888f3d3 Merge pull request #13547 from inietov/fixes/Attempt_to_read_property_asset_tag
Fixed ErrorException: Attempt to read property "asset_tag" on null (rollbar #3541)
2023-09-05 20:26:21 +01:00
Ivan Nieto Vivanco
91b1cc7121 Move the early return to the controller instead of the Label model 2023-09-05 13:23:51 -06:00
Brady Wetherington
0f91e898fd Remove some code duplication 2023-09-05 19:18:04 +01:00
snipe
d6dd332b09 Merge pull request #13557 from johnson-yi/fixes/add_changes_to_checkinout_actionlog
Added/Fixed: track changes on asset checkin/out
2023-09-05 19:08:49 +01:00
snipe
65a76c599c Added inline=true to image preview modal
Signed-off-by: snipe <snipe@snipe.net>
2023-09-05 18:35:07 +01:00
snipe
f53db8ba75 Fixed #13562 - allow inline view for uploaded files
Signed-off-by: snipe <snipe@snipe.net>
2023-09-05 18:28:01 +01:00
snipe
e486fe2794 Removed soft-delete query
Signed-off-by: snipe <snipe@snipe.net>
2023-09-05 16:10:20 +01:00
snipe
26452a8a29 Merge pull request #13565 from snipe/fixes/asset_history_500_on_hard_deleted_models
Account for hard-deleted models, suppliers
2023-09-05 16:06:40 +01:00
snipe
f85df6bb8c Use same method of accessing companies as others
Signed-off-by: snipe <snipe@snipe.net>
2023-09-05 16:02:28 +01:00
Brady Wetherington
636da2ab5e Wiring up custom fields for users - still some big UI challenges tho 2023-09-05 16:01:53 +01:00
snipe
2acf2b880e Account for hard-deleted models, suppliers
Signed-off-by: snipe <snipe@snipe.net>
2023-09-05 15:58:21 +01:00
snipe
b17af38d8e Merge pull request #12901 from Godmartinz/user_total_cost
Added users total cost of assets to user profile
2023-09-05 13:52:34 +01:00
snipe
a62e2f092b Merge pull request #13498 from marcusmoore/feature/add-checkin-date-range-filter-to-custom-asset-report
Added last check in column and filter to custom asset report
2023-09-05 13:22:15 +01:00
Johnson Yi
09f7b3debe Track changes on asset checkin/out 2023-09-01 13:12:07 +10:00
Brady Wetherington
4f182c0a50 Got a chunk of Custom Fields for Users worked out, still needs cleanup 2023-08-31 19:34:25 +01:00
Marcus Moore
da7d6f6f77 Merge branch 'develop' into update-testing-documentation 2023-08-31 10:36:06 -07:00
snipe
f08cef8664 Merge pull request #13556 from snipe/feature/sc-23684
Added model name and number to dynamic url
2023-08-31 18:23:33 +01:00
snipe
e192cbbbe1 Merge pull request #13550 from marcusmoore/remove-dusk
Removed Dusk
2023-08-31 18:06:04 +01:00
snipe
83b178f5b2 Added model name and number to dynamic url
Signed-off-by: snipe <snipe@snipe.net>
2023-08-31 18:03:32 +01:00
snipe
c51574099f Merge pull request #13507 from Godmartinz/ignore_encrypt_and_other_changes
Added eager loading for `changedinfo` and removed encrypted values from Asset history
2023-08-31 13:04:39 +01:00
snipe
9a0f691f05 Merge pull request #13546 from snipe/fixes/make_boolean_user_fields_more_consistant
Don’t cast as boolean, do validate as boolean for User validation
2023-08-31 12:01:20 +01:00
Marcus Moore
a799659610 Scaffold tests and add context 2023-08-30 17:33:23 -07:00
Marcus Moore
999605f832 Add failing test 2023-08-30 17:10:50 -07:00
Marcus Moore
5828d29952 Remove Dusk 2023-08-30 16:43:18 -07:00
Marcus Moore
417b2c8331 Update testing documentation 2023-08-30 11:27:26 -07:00
snipe
663faffcc1 Un-cast byod, validate as boolean
Signed-off-by: snipe <snipe@snipe.net>
2023-08-30 19:13:55 +01:00
snipe
fb455be406 Added tests
Signed-off-by: snipe <snipe@snipe.net>
2023-08-30 19:13:38 +01:00
Brady Wetherington
a384d0173a Merge branch 'snipeit_v7_laravel10' into has_custom_fields_trait_rebase 2023-08-30 18:33:17 +01:00
Ivan Nieto Vivanco
085a993340 Early return if no asset is found 2023-08-30 11:05:58 -06:00
Marcus Moore
07c3fe1fce Update assertions to account for type change 2023-08-30 09:42:53 -07:00
snipe
2a93c38830 Don’t cast as boolean, validate as boolean
Signed-off-by: snipe <snipe@snipe.net>
2023-08-30 16:40:28 +01:00
snipe
c0cbdb1fc4 Fixed bug introduced in #13528
Signed-off-by: snipe <snipe@snipe.net>
2023-08-30 15:48:35 +01:00
snipe
5cf8c36698 Updated assets
Signed-off-by: snipe <snipe@snipe.net>
2023-08-30 15:43:06 +01:00
snipe
1bcc74f156 Upgrade @fortawesome/fontawesome-free from 6.4.0 to 6.4.2 #13527
Signed-off-by: snipe <snipe@snipe.net>
2023-08-30 15:41:11 +01:00
snipe
9ebcde4472 Upgrade less from 4.1.2 to 4.2.0 #13534
Signed-off-by: snipe <snipe@snipe.net>
2023-08-30 15:40:56 +01:00
snipe
fbc04cfd47 Bumped hash
Signed-off-by: snipe <snipe@snipe.net>
2023-08-30 15:07:38 +01:00
snipe
b109ee281a Merge pull request #13544 from marcusmoore/bug/sc-23675
Fixed user search not adhering to company scoping
2023-08-30 08:54:41 +01:00
Marcus Moore
806ab2cb9d Ensure users are scoped by company in index method 2023-08-29 16:17:29 -07:00
Marcus Moore
aafa1ab70e Add failing test 2023-08-29 16:15:13 -07:00
snipe
22d136df46 Merge pull request #13528 from inietov/fixes/cloning_model_blanks_fieldset
Fixed #12548 Cloning a model blanks fieldset of new one
2023-08-29 19:14:38 +01:00
Godfrey Martinez
0ac5d4d582 Merge pull request #8 from Godmartinz/fix-companyable
Fix companyable
2023-08-28 19:38:27 -07:00
Godfrey Martinez
d86c63cf23 Merge branch 'ignore_encrypt_and_other_changes' into fix-companyable 2023-08-28 19:38:16 -07:00
Godfrey M
74f45a4473 reworks company queries for asset history 2023-08-28 19:35:46 -07:00
Ivan Nieto Vivanco
4e4ba38038 Pass the model_id variable in the controller and get it only if we are cloning the asset model 2023-08-28 16:23:26 -06:00
snipe
367484a766 Merge pull request #13537 from snipe/fixes/13500_prevent_autocomplete_on_ldap_password
Fixed #13500 - Try to prevent the browser from pre-filling the LDAP password
2023-08-28 20:42:58 +01:00
snipe
81365ef911 Merge pull request #13518 from marcusmoore/chore/tests-via-github-actions
Run tests for PHP 7.4, 8.0, and 8.1.1 via GitHub Actions
2023-08-28 20:28:42 +01:00
snipe
6020927e24 Merge pull request #13538 from snipe/fixes/13516_use_int_not_string_for_port_default
Fixed #13516 - Use int not string if no DB_PORT specified
2023-08-28 19:38:41 +01:00
snipe
82981290d4 Use int not string if no DB_PORT specified
Signed-off-by: snipe <snipe@snipe.net>
2023-08-28 19:34:08 +01:00
snipe
7787ca328c Try to prevent the browser from pre-filling the LDAP password
Signed-off-by: snipe <snipe@snipe.net>
2023-08-28 18:36:06 +01:00
Godfrey Martinez
92e88a0ae2 Merge branch 'develop' into ignore_encrypt_and_other_changes 2023-08-28 10:14:41 -07:00
Brady Wetherington
427f8b1522 Merge branch 'develop' into snipeit_v7_laravel10
Upgraded composer due to lockfile conflicts
2023-08-28 16:04:21 +01:00
Brady Wetherington
8902145288 This is a squashed branch of all of the various commits that make up the new HasCustomFields trait.
This should allow us to add custom fields to just about anything we want to within Snipe-IT.

Below are the commits that have been squashed together:

Initial decoupling of custom field behavior from Assets for re-use

Add new DB columns to Custom Fields and fieldsets for 'type'

WIP: trying to figure out UI for custom fields for things other than Assets, find problematic places

Real progress towards getting to where this stuff might actually work...

Fix the table-name determining code for Custom Fields

Getting it closer to where Assets at least work

Rename the trait to it's new, even better name

Solid progress on the new Trait!

WIP: HasCustomFields, still working some stuff out

Got some basics working; creating custom fields and stuff

HasCustomFields now validates and saves

Starting to yank the other boilerplate code as things start to work (!)

Got the start of defaultValuesForCustomField() working

More progress (squash me!)

Add migrations for default_values_for_custom_fields table

WIP: more towards hasCustomFields trait

Progress cleaning up the PR, fixing FIXME's

New, passing HasCustomFieldsTrait test!

Fix date formatter helper for custom fields

Fixed more FIXME's
2023-08-28 13:07:33 +01:00
snipe
535ca0e3c0 Merge pull request #13535 from snipe/fixes/13521_make_modal_upload_button_wider
Fixed #13521 - make modal “select files” button wider
2023-08-28 12:41:27 +01:00
snipe
582cad2dc5 Fixed #13521 - make modal “select files” button wider
Signed-off-by: snipe <snipe@snipe.net>
2023-08-28 12:37:42 +01:00
snipe
e3a9c34818 Merge pull request #13533 from snipe/improvements/labels_clearer_barcode_text
Clearer labels barcode text
2023-08-26 18:08:10 +01:00
snipe
20e9f05a64 Tighter layout
Signed-off-by: snipe <snipe@snipe.net>
2023-08-26 17:43:02 +01:00
snipe
844fe0938c Added link to the help docs
Signed-off-by: snipe <snipe@snipe.net>
2023-08-26 17:42:56 +01:00
Ivan Nieto Vivanco
a12a68e4e9 Add a variable so I dont ended rewriting the original model 2023-08-24 15:28:12 -06:00
Ivan Nieto Vivanco
950536f59f Added a condition to send correct model id when cloning one 2023-08-24 15:18:51 -06:00
Godfrey M
e56628499c fixed lost changes 2023-08-24 11:45:23 -07:00
Godfrey M
2b7a899ef8 removed unnecessary code 2023-08-24 11:43:44 -07:00
Godfrey M
0b956b2a46 revert changes of composer.lock 2023-08-24 10:45:59 -07:00
Godfrey M
18cb514a53 revert unwanted changes 2023-08-24 10:40:44 -07:00
Godfrey M
a3b6e0fbe6 adds some spacing 2023-08-24 10:36:09 -07:00
Godfrey M
34ba0c4440 adds id to history info 2023-08-24 10:36:08 -07:00
Godfrey M
739fc152c2 Adds readable asset history in the action log transformer 2023-08-24 10:36:08 -07:00
Godfrey M
011c09a3dd working on getting notifications 2023-08-24 10:35:40 -07:00
Godfrey M
38d5691b88 fix conflicts 2023-08-24 10:35:40 -07:00
Godfrey M
c26ef224f4 fixing my mess 2023-08-24 10:31:01 -07:00
Godfrey M
8ebb9afedd adds min_amt to asset model edit, index, and table 2023-08-24 10:30:07 -07:00
snipe
26dd992d3c Merge pull request #13525 from marcusmoore/bug/sc-23660
Fixed undeclared variable in ActionlogsTransformer
2023-08-24 17:09:30 +01:00
Marcus Moore
e32c07be02 Clear commented log statements 2023-08-24 08:15:40 -07:00
Marcus Moore
5a0b0522b0 Explicitly declare $clean_meta variable 2023-08-24 08:15:07 -07:00
Marcus Moore
20457bd89e Run tests for PHP 7.4, 8.0, and 8.1.1 2023-08-23 15:53:34 -07:00
Godfrey Martinez
28cf533d19 Merge branch 'develop' into ignore_encrypt_and_other_changes 2023-08-23 00:42:59 -07:00
Godfrey M
0fc79ec936 fixes conflicts 2023-08-23 00:40:59 -07:00
Godfrey M
ffe1b11419 merged develop 2023-08-23 00:38:58 -07:00
Godfrey M
27488c1009 adds soft deletes to eager loading 2023-08-23 00:34:09 -07:00
Godfrey M
ce60db009c adds soft deletes to eager loading 2023-08-23 00:32:43 -07:00
snipe
d393bd5c97 Merge pull request #13511 from snipe/fixes/13510_no_translations_in_migrations
Fixed #13510 - do not use translations in migrations
2023-08-23 08:21:18 +01:00
snipe
ea37325806 Remove trans() from default values
Signed-off-by: snipe <snipe@snipe.net>
2023-08-23 08:19:05 +01:00
snipe
31a7758ab1 Merge pull request #13509 from marcusmoore/bug/sc-23636
Fixed asset model query in action log transformer
2023-08-23 06:58:41 +01:00
Marcus Moore
bee680683d Add withTrashed to asset model query 2023-08-22 17:05:06 -07:00
Godfrey M
92ddf8fc67 removed dead space 2023-08-22 12:38:50 -07:00
Godfrey M
1019287c76 retarget key 2023-08-22 12:36:43 -07:00
Godfrey M
9e438c3ed0 eager loaded changedInfo queries, reworked encrypted data change log changes 2023-08-22 12:34:45 -07:00
Godfrey M
c7f2acf2c6 removes encrypted info from change log, renames asset_eol_date in the change log 2023-08-22 11:39:38 -07:00
snipe
79b330f492 Merge pull request #13400 from inietov/fixes/asset_acceptance_user_error
Fixed Asset acceptance error when user company and asset company don't match
2023-08-22 15:49:56 +01:00
snipe
3da21e73e2 Merge pull request #13501 from snipe/fixes/checkbox_layout_in_settings
Small fixes to checkbox layout in general settings blade
2023-08-22 14:12:15 +01:00
snipe
da38945a53 Small fixes to checkbox layout in general settings blade
Signed-off-by: snipe <snipe@snipe.net>
2023-08-22 14:10:39 +01:00
snipe
a48762c64d Merge pull request #13496 from snipe/features/setting_for_name_order
Fixed #13495 added setting for name order
2023-08-22 12:50:58 +01:00
snipe
23237e5cd3 Removed unused translation
Signed-off-by: snipe <snipe@snipe.net>
2023-08-22 12:50:32 +01:00
snipe
aafb7668f5 Merge pull request #13453 from inietov/fixes/accessories_declined_issue
Fixed #13317 Accessories declined by user remain assigned
2023-08-22 12:42:55 +01:00
snipe
fea11ec7f1 Merge pull request #12761 from spencerrlongg/bulk_edit_custom_fields
Bulk Editing Custom Fields
2023-08-22 12:40:18 +01:00
snipe
303b45c9e9 Merge pull request #13485 from Godmartinz/history_info_clean_up
Added better handling of information of asset history
2023-08-22 12:25:17 +01:00
snipe
8c7925e703 Merge pull request #13436 from marcusmoore/chore/dependency-updates
Bumped dependencies
2023-08-21 22:58:52 +01:00
Marcus Moore
191c4f959f Bump guzzlehttp/psr7 to 2.4.5 2023-08-21 14:46:08 -07:00
Marcus Moore
1e10a7ee23 Bump nyholm/psr7 to 1.6.1 2023-08-21 14:45:21 -07:00
Marcus Moore
4e8537a1c7 Merge branch 'develop' into chore/dependency-updates
# Conflicts:
#	composer.lock
2023-08-21 14:44:15 -07:00
Marcus Moore
4e2ef4f056 Default to using the current date if last check in end date is not provided 2023-08-21 14:35:15 -07:00
snipe
79a4d915db Merge pull request #13456 from marcusmoore/fixes/auto-incrementing-on-74
Fixed passing invalid argument to `strpos()`
2023-08-21 22:25:52 +01:00
Marcus Moore
c332b98456 Add last checkin options to report front end 2023-08-21 13:44:49 -07:00
Godfrey M
b54aaefefb adds some spacing 2023-08-21 13:43:06 -07:00
Godfrey M
5076b45a0d adds id to history info 2023-08-21 13:40:39 -07:00
Marcus Moore
6fc06f2ee1 Add simple tests around asset check in 2023-08-21 12:31:51 -07:00
snipe
36a343365e Switched from fullName() to getFullNameAttribute()
Signed-off-by: snipe <snipe@snipe.net>
2023-08-21 20:14:07 +01:00
snipe
c617bf89b6 Tweak layout
Signed-off-by: snipe <snipe@snipe.net>
2023-08-21 20:13:45 +01:00
snipe
ba0643f6a4 Added name display format, tweaked some
Signed-off-by: snipe <snipe@snipe.net>
2023-08-21 20:13:28 +01:00
snipe
bfd674b622 Switched to getFullNameAttribute() from fullName() in User Presenter
Signed-off-by: snipe <snipe@snipe.net>
2023-08-21 20:12:25 +01:00
snipe
d73d15b8a2 Added form macro for name format
Signed-off-by: snipe <snipe@snipe.net>
2023-08-21 20:11:59 +01:00
snipe
8660d41aa3 Changed width of locale field
Signed-off-by: snipe <snipe@snipe.net>
2023-08-21 20:11:45 +01:00
snipe
c39579b170 New strings
Signed-off-by: snipe <snipe@snipe.net>
2023-08-21 20:11:25 +01:00
snipe
354550b52e Removed getCompleteNameAttribute(), modified getFullNameAttribute()
Signed-off-by: snipe <snipe@snipe.net>
2023-08-21 20:11:17 +01:00
snipe
f3460b5a4f Switch to getFullNameAttribute() in user transformer
Signed-off-by: snipe <snipe@snipe.net>
2023-08-21 20:10:48 +01:00
snipe
474c03e3fc Added name order to settings save controller method
Signed-off-by: snipe <snipe@snipe.net>
2023-08-21 20:10:03 +01:00
snipe
749002b768 Added migration to add name order to settings
Signed-off-by: snipe <snipe@snipe.net>
2023-08-21 20:09:48 +01:00
Marcus Moore
489d30c685 Set last_checkin in ui and api controllers 2023-08-21 11:57:33 -07:00
snipe
2346bab8ed Merge pull request #13492 from snipe/features/add_dymo_labelwriter
Added Dymo labelwriter
2023-08-18 23:27:37 +01:00
snipe
45898deb1a Don’t 500 if the 1D barcode doesn’t match the format requested - log an error instead
Signed-off-by: snipe <snipe@snipe.net>
2023-08-18 22:18:38 +01:00
snipe
ffc7c4e99a use number format to constrain large number displays
Signed-off-by: snipe <snipe@snipe.net>
2023-08-18 22:18:09 +01:00
snipe
1e82c2bfad Changed example asset name
Signed-off-by: snipe <snipe@snipe.net>
2023-08-18 22:17:54 +01:00
snipe
d12f4564e1 Added Dymo Labelwriter template
Signed-off-by: snipe <snipe@snipe.net>
2023-08-18 21:44:12 +01:00
snipe
1dcca14c37 Values are not sortable, so don’t show them as sortable
Signed-off-by: snipe <snipe@snipe.net>
2023-08-18 21:21:54 +01:00
snipe
63f847f125 Merge pull request #13491 from snipe/fixes/remove_border_from_default_label
Removed the black label from around the default labels
2023-08-18 18:40:45 +01:00
snipe
d56c671410 Removed the black label from around the default labels
Signed-off-by: snipe <snipe@snipe.net>
2023-08-18 18:39:00 +01:00
snipe
802651a1b4 Merge pull request #13489 from snipe/fixes/override_0_cols_rows_in_default_for_new_engine
Make sure the columns and rows can never be 0
2023-08-18 18:14:01 +01:00
snipe
0cb76a049a Make sure the columns and rows can never be 0
Signed-off-by: snipe <snipe@snipe.net>
2023-08-18 18:13:16 +01:00
snipe
5645141f93 Merge pull request #13488 from snipe/fixes/13487_supplier_url_in_listing
Fixed #13487 - include supplier url in listing
2023-08-18 15:32:14 +01:00
snipe
da2f22d504 Fixed #13487 - include supplier url in listing
Signed-off-by: snipe <snipe@snipe.net>
2023-08-18 15:31:15 +01:00
Marcus Moore
8b2716d2b7 Fix update statement 2023-08-17 18:33:01 -07:00
Marcus Moore
56fb45f1ea WIP: Add last_checkin to assets table 2023-08-17 18:01:26 -07:00
Godfrey M
a62876d4bc Adds readable asset history in the action log transformer 2023-08-17 16:14:01 -07:00
snipe
0ee032a10d Merge pull request #13391 from Godmartinz/ldap_sync_field_clear_bug
Fixed Ldap sync field clear bug
2023-08-17 17:45:03 +01:00
snipe
03a01c02c4 Merge pull request #13483 from inietov/fixes/default_locations_advanced_search
Fixed #13359 Advanced search by Default Location does not work
2023-08-17 15:15:21 +01:00
Ivan Nieto Vivanco
b607a59875 Add query to search default locations in advanced search 2023-08-16 15:04:17 -06:00
snipe
34f2221b02 Merge pull request #13471 from inietov/fixes/components_search
Fixed #13409 Search in component detail view not working
2023-08-16 21:59:40 +01:00
snipe
b81c6825cf Merge pull request #13476 from uberbrady/accessry_checkin_fix_develop
Accessory checkin via API reported wrong target user
2023-08-16 13:05:54 +01:00
Brady Wetherington
852e9ff311 Accessory checkin via API reported wrong target user 2023-08-16 13:03:37 +01:00
Ivan Nieto Vivanco
92df32dfaa Move a couple assignation of variables inside an else to only execute once 2023-08-15 21:10:48 -06:00
snipe
eacbde37e2 Merge pull request #13473 from snipe/fixes/check_for_company_on_labels
Check that there is a company before trying to get name property
2023-08-16 01:27:48 +01:00
snipe
74384f14e4 Use clearer translation (from original PR)
Signed-off-by: snipe <snipe@snipe.net>
2023-08-16 01:25:13 +01:00
snipe
027afa71f1 Check that there is a company before trying to get name property
Signed-off-by: snipe <snipe@snipe.net>
2023-08-16 01:09:22 +01:00
Ivan Nieto Vivanco
993918f47c Add query to search into the per-component view 2023-08-15 15:31:36 -06:00
Brady Wetherington
8b52bad16f Merge branch 'develop' into snipeit_v7_laravel10 2023-08-15 21:25:16 +01:00
Ivan Nieto Vivanco
25c58a8486 Fix typo in language variable name 2023-08-15 14:17:39 -06:00
snipe
7eaf3174ab Merge pull request #13457 from snipe/fixes/remove_autocomplete_off_on_login
Fixed #13365 - Added LOGIN_AUTOCOMPLETE as env var
2023-08-15 20:55:05 +01:00
snipe
297390ae63 Merge pull request #13470 from snipe/fixes/13464_typo_in_accessories_clone
Fixed #13464 typo in accessories clone
2023-08-15 20:41:54 +01:00
snipe
01ab360ef3 Fixed accessory clone typo
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 20:39:09 +01:00
snipe
1c2f3cd552 Fixed translation typo
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 20:39:00 +01:00
snipe
bc4a47421a Merge pull request #13469 from snipe/fixes/missed_one_checkbox_in_label
Fixed checkboxes for accessibility
2023-08-15 20:30:39 +01:00
snipe
0763b5135d Fixed checkboxes
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 20:28:16 +01:00
snipe
253975ce72 Updated translation
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 20:27:55 +01:00
snipe
9af850dbaa Re-apply a change that was dropped
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 20:27:47 +01:00
snipe
96b616be89 Downgraded TCPDF
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 20:11:56 +01:00
snipe
2b9f8ce4a6 Merge pull request #13467 from snipe/fixes/more_label_html_tweaks
Fixes more label html tweaks
2023-08-15 20:05:03 +01:00
snipe
fa6c8d864e Restore label engine checkbox
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 20:04:19 +01:00
snipe
c957f136aa More label tweaks
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 20:03:40 +01:00
snipe
697dc10d76 More label tweaks
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 20:03:32 +01:00
snipe
d47b502d86 Merge pull request #13466 from snipe/fixes/weird_label_engine_layout
Fixes weird label engine layout
2023-08-15 18:52:54 +01:00
snipe
6b02184e99 Fixed weird layout with checkbox
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 18:48:20 +01:00
snipe
64342838fd Return the user to the labels page on save
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 18:48:12 +01:00
snipe
346f243bc0 Merge pull request #13465 from snipe/fixes/parse_error_in_helper
Fixed unclosed brace
2023-08-15 18:14:55 +01:00
snipe
443adc50da Fixed unclosed brace
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 18:12:25 +01:00
snipe
cebf0e0de1 Add @cram42 as a contributor 2023-08-15 18:07:56 +01:00
snipe
e41368daac Merge pull request #12050 from cram42/develop
New Label Engine
2023-08-15 17:58:57 +01:00
Godfrey M
d1efca2ae1 fixes conflicts 2023-08-15 09:28:42 -07:00
snipe
c56f664811 Merge pull request #13442 from Robert-Azelis/Robert-Azelis-patch-add_email_to_companies
Add email to companies
2023-08-15 13:26:20 +01:00
snipe
6f373aed33 Merge pull request #13461 from snipe/localization/new_translations
Updated language strings from CrowdIn
2023-08-15 13:22:14 +01:00
snipe
d1ce1b6f18 Updated language strings from CrowdIn
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 13:21:35 +01:00
Ivan Nieto Vivanco
71cb16118d Change error string for a better (?) one 2023-08-14 20:52:00 -06:00
Ivan Nieto Vivanco
d365565b6d Add message in the acceptance assets view to indicate when the user can\'t accept nor deny the asset 2023-08-14 20:51:04 -06:00
snipe
24a3e0ee83 Added LOGIN_AUTOCOMPLETE as env var
Signed-off-by: snipe <snipe@snipe.net>
2023-08-15 01:56:01 +01:00
Marcus Moore
dc1a8840f1 Ensure empty string is not passed to strpos() 2023-08-14 16:40:34 -07:00
Ivan Nieto Vivanco
96440834bd Move the declinedCheckout function so it don/'t separate the class properties 2023-08-14 16:16:28 -06:00
snipe
d3fbbec92c Merge pull request #13455 from snipe/fixes/confusion_around_localization_date
Fixed #13382 - confusion around localization date
2023-08-14 22:50:30 +01:00
snipe
9820ab34d7 Use today’s date for date format selectlist
Signed-off-by: snipe <snipe@snipe.net>
2023-08-14 22:44:29 +01:00
snipe
aa333bcf0b Merge pull request #13448 from Godmartinz/status-label-translations_fix
Fixed #13446 - added translations to status label type column
2023-08-14 22:25:46 +01:00
snipe
ba56746f57 Merge pull request #13437 from marcusmoore/feature/improve-user-factory
Allowed permissions in the user factory to be chained
2023-08-14 22:23:55 +01:00
snipe
dcec4ba5e2 Merge pull request #13454 from snipe/fixes/13450_removed_escaping_custom_fieldsets
Fixed #13450 - remove escaping on saveing new custom fields
2023-08-14 22:22:35 +01:00
snipe
12e9d2adeb Fixed #13450 - remove escaping on saveing new custom fields
Signed-off-by: snipe <snipe@snipe.net>
2023-08-14 22:21:41 +01:00
Ivan Nieto Vivanco
8da2a8a79c Allows to save signature for declined items 2023-08-14 14:58:10 -06:00
Ivan Nieto Vivanco
4796598bb6 Add declinedCheckout method to Accessory model 2023-08-14 14:35:31 -06:00
Godfrey M
c3356ab765 fixed translation choice and color choice 2023-08-14 12:20:46 -07:00
Godfrey M
4446b2311d remove unnecessary changes 2023-08-14 12:14:15 -07:00
Godfrey M
6b94ef6adc fixes the statuslabeltypeforatter instead of the model 2023-08-14 12:13:01 -07:00
Godfrey M
a0d5774635 adds translations to status label type column 2023-08-14 10:42:17 -07:00
snipe
291fa1cd29 Merge pull request #13445 from snipe/fixes/typo_in_formatter_for_asset_maintenances
Fixed case in BS table formatter for boolean
2023-08-14 13:02:27 +01:00
snipe
58286c9cab Fixed case in BS table formatter for boolean
Signed-off-by: snipe <snipe@snipe.net>
2023-08-14 13:01:32 +01:00
Robert-Azelis
1e43d88e06 Create 2023_08_13_172600_add_email_to_companies.php 2023-08-13 17:25:33 +02:00
Robert-Azelis
da701677c7 Update edit.blade.php 2023-08-13 17:24:17 +02:00
Robert-Azelis
30d33310ae Update CompanyPresenter.php 2023-08-13 17:23:33 +02:00
Robert-Azelis
bbb8ecfee4 Update Company.php 2023-08-13 17:21:55 +02:00
Robert-Azelis
8988a5dfc3 Update CompaniesTransformer.php 2023-08-13 17:20:15 +02:00
Robert-Azelis
ed5b4ca0a2 Update CompaniesController.php 2023-08-13 17:18:25 +02:00
Robert-Azelis
07bafa9508 Update CompaniesController.php 2023-08-13 17:15:20 +02:00
snipe
a1cfa45344 Merge pull request #13439 from snipe/fixes/500_error_when_cloning_invalid_accessory
Fixed route for accessory index
2023-08-11 09:42:00 +01:00
snipe
df8f6a8d2b Correctly call the route for accessory index
Signed-off-by: snipe <snipe@snipe.net>
2023-08-11 09:40:49 +01:00
Marcus Moore
5b86c02366 Set permissions to empty object in user factory 2023-08-10 16:55:44 -07:00
Marcus Moore
41479b1ec7 Allow permissions in the user factory to be chained 2023-08-10 16:35:10 -07:00
Marcus Moore
3a2b15313c Bump guzzlehttp/psr7 to 2.4.5 2023-08-10 11:53:20 -07:00
Marcus Moore
6b6bb61400 Bump nyholm/psr7 to 1.6.1 2023-08-10 11:52:42 -07:00
snipe
6adaa32286 Merge pull request #13431 from marcusmoore/feature/custom-report-scoping
Removed unneeded `Company::scopeCompanyables` from `ReportsController`
2023-08-10 09:57:53 +01:00
snipe
a599f0c923 Merge pull request #13434 from marcusmoore/chore/improve-test-stability
Improved test stability and messaging
2023-08-10 09:57:26 +01:00
snipe
4db4bf7be4 Merge pull request #13432 from marcusmoore/chore/remove-old-testing-code
Removed unused Codeception test code
2023-08-10 09:57:11 +01:00
Marcus Moore
04661d5441 Add help text to response assertion helpers 2023-08-09 17:09:31 -07:00
Marcus Moore
3a5ed031bf Escape values in response assertion helpers 2023-08-09 17:08:49 -07:00
Marcus Moore
60baaae192 Remove unused test bootstrap file 2023-08-09 16:22:58 -07:00
Marcus Moore
8508594a2f Remove old and unused Codeception test code 2023-08-09 13:32:15 -07:00
Marcus Moore
e0b464dcec Merge branch 'develop' into feature/custom-report-scoping 2023-08-09 13:03:05 -07:00
snipe
bd3ba9a5f7 Merge pull request #13428 from snipe/security/update_autotable
Updated autotable
2023-08-09 10:49:01 +01:00
snipe
a65ac1ccdf Updated autotable
Signed-off-by: snipe <snipe@snipe.net>
2023-08-09 10:47:45 +01:00
snipe
ffabc9c331 Merge pull request #13414 from marcusmoore/fixes/chipperci-config
Fixes ChipperCi Pipeline
2023-08-09 10:37:21 +01:00
snipe
a6a742d8d8 Merge pull request #13407 from marcusmoore/feature/sc-23465
Added messaging to category edit page to improve clarity around when users will be emailed
2023-08-09 10:36:19 +01:00
Marcus Moore
2e632a3d2d Improve test readability 2023-08-08 17:40:02 -07:00
Marcus Moore
c32f099053 Remove unneeded call to Company::scopeCompanyables 2023-08-08 17:22:15 -07:00
Marcus Moore
c752e1670c Add test around company scoping in custom report 2023-08-08 17:21:39 -07:00
Marcus Moore
1405e17251 Add simple test around custom asset report response 2023-08-08 17:10:36 -07:00
snipe
15122bbb55 Merge pull request #13425 from snipe/security/upgrade_webpack_snyk_13416
Updated webpack
2023-08-08 22:24:59 +01:00
snipe
c18349d75f Updated webpack
Signed-off-by: snipe <snipe@snipe.net>
2023-08-08 22:07:49 +01:00
snipe
521961457d Merge pull request #13424 from snipe/bug/sc-23552
Fixed tooltip not loading on encrypted field lock icon on asset detail view
2023-08-08 19:00:56 +01:00
snipe
6a3a38b6f6 Call tooltip again on custom fields jquery
Signed-off-by: snipe <snipe@snipe.net>
2023-08-08 18:53:57 +01:00
snipe
40aca9709a Added container to the tooltip invocation
Signed-off-by: snipe <snipe@snipe.net>
2023-08-08 18:52:26 +01:00
snipe
9e6f23c8c7 Merge pull request #13421 from uberbrady/re_add_asset_eol_date
Re-add the option for asset_eol_date as an import field
2023-08-08 17:52:05 +01:00
Brady Wetherington
6afbf1b152 Re-add the option for asset_eol_date as an import field 2023-08-08 17:45:33 +01:00
snipe
af91ffb2da Merge pull request #13418 from snipe/fixes/add_mailgun_endpoint
Added mailgun endpoint option, defaulting to the US
2023-08-08 12:56:37 +01:00
snipe
94bef046b8 Added mailgun endpoint option, defaulting to the US
Signed-off-by: snipe <snipe@snipe.net>
2023-08-08 12:50:38 +01:00
snipe
bd4061e023 Change text on dropdown
Signed-off-by: snipe <snipe@snipe.net>
2023-08-08 08:18:56 +01:00
snipe
5bda73f151 Ugh - messing with the blade layout
Signed-off-by: snipe <snipe@snipe.net>
2023-08-08 08:18:40 +01:00
Marcus Moore
b56bcd3596 Troubleshooting pipeline: create both .env and .env.testing 2023-08-07 11:59:58 -07:00
Marcus Moore
999605b591 Troubleshooting pipeline: create .env.testing in place of .env 2023-08-07 11:57:34 -07:00
Marcus Moore
d3a45f73cf Troubleshooting pipeline: re-add creating .env.testing 2023-08-07 11:48:09 -07:00
Marcus Moore
0d40979724 Troubleshooting pipeline: Remove commented commands 2023-08-07 11:36:51 -07:00
Marcus Moore
81efa7d84e Revert "Troubleshooting pipeline: use phpunit in place of artisan test"
This reverts commit a7d1657111.
2023-08-07 11:35:18 -07:00
Marcus Moore
a7d1657111 Troubleshooting pipeline: use phpunit in place of artisan test 2023-08-07 11:31:00 -07:00
Marcus Moore
8ea8ff05e5 Troubleshooting pipeline: fix filename 2023-08-07 11:26:04 -07:00
Marcus Moore
6398805fc3 Troubleshooting pipeline: use .env.testing in place of .env.example 2023-08-07 11:24:38 -07:00
Marcus Moore
119ed9c882 Troubleshooting pipeline: remove comment to trigger build 2023-08-07 11:09:10 -07:00
snipe
32d8d8c50e Merge pull request #13397 from uberbrady/fix_locationless_ldap_sync
Fixed #13372: Put guard around assigning location via LDAP
2023-08-07 17:06:58 +01:00
Marcus Moore
ae9cf1e5b6 Formatting 2023-08-02 18:24:32 -07:00
Ivan Nieto Vivanco
053d3fc9ed Prevent asset to be checked out if full company support is enabled and companies not match 2023-08-02 19:23:28 -06:00
Marcus Moore
d019e62d39 Remove lazy from eula field to avoid race condition 2023-08-02 18:22:40 -07:00
Ivan Nieto Vivanco
9ca163e8cf Stop asset acceptances from shown to user if full company support is enabled and companies not match 2023-08-02 19:22:35 -06:00
Marcus Moore
b70a5280f9 Remove unneed jquery 2023-08-02 18:04:21 -07:00
Marcus Moore
cbe5a9bc8a Persist eula text even when field is disabled 2023-08-02 18:03:09 -07:00
Marcus Moore
3fd0853fd0 Ensure eula field enabled when not using default eula 2023-08-02 18:02:56 -07:00
Marcus Moore
2e7aa01abe Pass checkin_email value to backend even when unchecked 2023-08-02 17:45:39 -07:00
Marcus Moore
896f038054 Set send email back to original value when eulas cleared 2023-08-02 17:03:56 -07:00
Marcus Moore
48979ce177 Disable send email when it should not be modified 2023-08-02 16:52:56 -07:00
Marcus Moore
e12935f7fa Disable eula textarea when using global eula 2023-08-02 16:18:57 -07:00
Marcus Moore
6400034435 Improve variable name 2023-08-02 16:06:59 -07:00
Marcus Moore
269414e4f2 Automatically check the send email to user checkbox in certain conditions 2023-08-02 16:04:01 -07:00
Marcus Moore
dee6ebf8e0 Scaffold component test 2023-08-02 12:58:07 -07:00
Marcus Moore
105c94aea9 Implement toggling message when email will be sent 2023-08-02 11:36:20 -07:00
Brady Wetherington
0af205dade Put guard around assigning location via LDAP 2023-08-02 15:01:14 +01:00
Marcus Moore
6349d52803 WIP: migrate to livewire 2023-08-01 17:29:23 -07:00
Marcus Moore
65de9c5e07 Extract translation strings 2023-08-01 15:21:49 -07:00
Marcus Moore
ebfc395e78 Improve messaging 2023-08-01 14:39:30 -07:00
Marcus Moore
5c8c2ca027 Improve variable names 2023-08-01 14:26:21 -07:00
snipe
924f5287f7 Merge pull request #13392 from Godmartinz/change_webhook_variable_type
Fixed `webhook_endpoint` data type from varchar to a text
2023-08-01 20:28:39 +01:00
Godfrey M
7560afb8c4 changes webhook_endpoint var to a text 2023-08-01 10:45:39 -07:00
Godfrey M
8a24a47475 removed unnecessary code 2023-08-01 09:45:48 -07:00
Godfrey M
fb52038e7c applies a check if a sync field is designated 2023-08-01 09:39:58 -07:00
Brady Wetherington
daed0b60bc Merge branch 'develop' into snipeit_v7_laravel10 2023-07-31 19:40:56 +01:00
snipe
ffb605a37c Merge pull request #13309 from inietov/fixes/checkout_range_doesnt_include_today
Fixed #13300 Custom Asset Report, Checkout date range never includes current day
2023-07-31 15:04:22 +01:00
Brady Wetherington
4654f7aa37 Porting Snipe-IT v7 to Laravel v10 2023-07-31 14:07:12 +01:00
snipe
343aacab85 Merge pull request #13386 from snipe/security/dep_updates
Updated BS table and table export plugins
2023-07-31 13:46:41 +01:00
snipe
96d69b654d Updated BS table and table export plugins
Signed-off-by: snipe <snipe@snipe.net>
2023-07-31 13:45:15 +01:00
snipe
2e1c3fb51b Merge pull request #13295 from inietov/fixes/admins_cannot_view_encrypted_fields
Fixed #11794 Admins Cannot View Encrypted Field
2023-07-31 13:08:28 +01:00
snipe
3e4b371bf4 Merge pull request #13379 from inietov/fixes/component_checkout_via_api_returns_error
Fixed #13376 Component checkout via API returns error
2023-07-31 13:07:38 +01:00
Grant Le Roux
b1464e028c Merge branch 'develop' into develop 2023-07-31 07:57:29 +08:00
Ivan Nieto Vivanco
0a841ddbb8 Change component validator to the correct asset id we're passing in the API call 2023-07-27 20:22:13 -06:00
Brady Wetherington
70e87dad1c Merge branch 'develop' into snipeit_v7 2023-07-27 16:21:31 +01:00
snipe
af86c6138d Merge pull request #13361 from Godmartinz/bug/sc-19126
Fixed custom fieldset order
2023-07-26 08:55:18 +01:00
snipe
f6545be410 Merge pull request #13363 from inietov/fixes/no_records_found_multipage_license_seats
Fixed #13298 "No records Found" when Switching between Single and Multi-Page Licenses
2023-07-26 08:48:44 +01:00
Ivan Nieto Vivanco
c015264181 Adjust the license offset if it exceeds the total of license seats 2023-07-25 16:23:33 -06:00
Godfrey M
9c6e8d57aa removes typos 2023-07-25 11:44:16 -07:00
Godfrey M
11e3487263 custom field set order starts at 1 now 2023-07-25 11:41:08 -07:00
snipe
a01cb26aac Merge pull request #12940 from akemidx/delete_asset_from_view_page
Delete button on asset view page
2023-07-25 12:11:35 +01:00
akemidx
e289e95721 no ? needed 2023-07-24 17:22:10 -04:00
akemidx
b082d27c42 removing :item 2023-07-24 17:12:12 -04:00
snipe
39ea15a27a Merge pull request #13347 from snipe/fixes/custom_report_error_on_bad_model
Possible alternative to fixing #13296 - custom report failing when th…
2023-07-21 15:18:16 +01:00
snipe
4fe6632167 Merge pull request #13349 from snipe/fixes/check_for_valid_model
Fixed: tighter check for valid model
2023-07-21 14:52:00 +01:00
snipe
1a771e6ab9 Check that the model is valid before trying to chain the relationship
Signed-off-by: snipe <snipe@snipe.net>
2023-07-21 14:46:58 +01:00
snipe
7f761000b4 Use slightly less terrifying and more accurate language
Signed-off-by: snipe <snipe@snipe.net>
2023-07-21 14:46:39 +01:00
Ivan Nieto Vivanco
cb4ed92639 Use Carbon date objects instead of casting using DB::raw() 2023-07-20 16:17:06 -06:00
snipe
540b09c506 Possible alternative to fixing #13296 - custom report failing when the model is busted
Related: https://github.com/snipe/snipe-it/pull/13297
Signed-off-by: snipe <snipe@snipe.net>
2023-07-20 17:45:45 +01:00
Brady Wetherington
ba8d8a6f05 Merge branch 'develop' into snipeit_v7 2023-07-20 17:16:04 +01:00
snipe
0b8a3ee9a5 Merge pull request #13346 from snipe/fixes/depreciable
Check that $this->get_depreciation() returns
2023-07-20 16:33:15 +01:00
snipe
1e09320ebe Check that $this->get_depreciation() returns
Signed-off-by: snipe <snipe@snipe.net>
2023-07-20 16:30:07 +01:00
snipe
ee36497acf Merge pull request #13344 from snipe/fixes/added_manufacturer_to_licenses
Fixes bug/sc-23509: Added manufacturer back into license importer
2023-07-20 14:05:19 +01:00
snipe
d7ac8ef618 Added manufacturer to licenses
Signed-off-by: snipe <snipe@snipe.net>
2023-07-20 14:02:54 +01:00
snipe
244e4ec11f Added manufacturer back into license importer
Signed-off-by: snipe <snipe@snipe.net>
2023-07-20 13:48:51 +01:00
snipe
917005ceb4 Merge pull request #13342 from Loemnk/develop
Fixes #13341: Clean up correct seats on license delete
2023-07-20 13:05:31 +01:00
Tobias Franzius
90a344af0b Fixes #13341 Clean up correct seats on license delete
Before this, we checked for the `id` collumn in the `license_seats` table, insteasd of
using `license_id` for this.

This way, we ensure that we only alter seats belonging to the correct license.
2023-07-20 13:48:57 +02:00
Ivan Nieto Vivanco
ecf522243b Add the new rule to proper views and also in the Asset Transformer 2023-07-19 19:52:03 -06:00
Ivan Nieto Vivanco
705411eb4d Create the Gate that goes with the permission 2023-07-19 19:44:59 -06:00
Ivan Nieto Vivanco
3b4a2b0f5b Add permission to view and modify encrypted custom fields 2023-07-19 14:57:57 -06:00
snipe
a19a508a80 Merge pull request #13197 from akemidx/current_value_for_assets
Current value added to asset index page
2023-07-19 19:06:15 +01:00
akemidx
9e2987e680 changing book value to be NOT searchable or sortable 2023-07-19 13:44:31 -04:00
snipe
1e1aea2eb0 Merge pull request #13299 from ubc-cpsc/bugfix/CVE-2023-37260
Update league/oauth2-server for CVE-2023-3726
2023-07-19 13:14:35 +01:00
Brady Wetherington
605d267fe8 Merge branch 'develop' into snipeit_v7 2023-07-19 11:47:51 +01:00
snipe
33fd904c18 Merge pull request #13330 from akemidx/merge_users_typo
merge users page typo fix
2023-07-19 10:26:57 +01:00
snipe
dc20305db6 Merge pull request #13333 from snipe/fixes/strtolower_on_catgories
Added strtolower for category type
2023-07-19 09:00:55 +01:00
snipe
a0a5ca1f40 Added strtolower for category type
Signed-off-by: snipe <snipe@snipe.net>
2023-07-19 08:56:17 +01:00
akemidx
064e696521 merge users page typo fix 2023-07-18 15:33:33 -04:00
snipe
c1949ffb0d Merge pull request #13319 from marcusmoore/chore/user-search-test-cases
Added test cases around user search
2023-07-18 13:27:22 +01:00
snipe
18e2ec4dad Merge pull request #13310 from marcusmoore/bug/sc-23478
Fixed the inability to load location select when editing profile
2023-07-18 13:26:30 +01:00
snipe
6f8c3ca167 Merge pull request #13322 from uberbrady/fix_ldap_location_3
Fix to ldap_location attribute
2023-07-18 13:24:59 +01:00
snipe
cbdce994b8 Merge pull request #13318 from inietov/fixes/employee_id_not_importing
Fixed Employee Number no longer importing [sc-23497]
2023-07-18 11:08:43 +01:00
Brady Wetherington
051830dff4 Fix to ldap_location attribute 2023-07-17 20:42:02 +01:00
Marcus Moore
2eaab6d9fb Change message to a callout 2023-07-17 12:23:31 -07:00
Marcus Moore
fa0a88289a Add tests around user search
Follow up to #13311
2023-07-17 11:29:22 -07:00
Ivan Nieto Vivanco
88c40c9c14 Change the field name to the same the model uses 2023-07-17 12:08:10 -06:00
snipe
f15e14f905 Merge pull request #13315 from snipe/features/add_warranty_link_even_if_no_warranty_set
Moved warranty into manufactuer’s section
2023-07-15 10:47:44 +01:00
snipe
c21a7db3c1 Moved warranty into manufactuer’s section
Signed-off-by: snipe <snipe@snipe.net>
2023-07-15 10:45:36 +01:00
snipe
bb0eaf8b8d Merge pull request #13312 from snipe/features/add_show_hide_option_on_custom_fields
Added ability to show/hide custom fields in list views by default
2023-07-14 09:38:35 +01:00
snipe
3078cab7ee Added ability to show/hide custom fields in list views by default
Signed-off-by: snipe <snipe@snipe.net>
2023-07-14 09:09:43 +01:00
snipe
15bb943210 Merge pull request #13311 from snipe/fixes/deleted_users_showing_in_current_users
Fixed: deleted users showing in current users
2023-07-14 07:47:36 +01:00
snipe
f51dd15893 Moved deleted scope down
Signed-off-by: snipe <snipe@snipe.net>
2023-07-14 07:44:19 +01:00
Marcus Moore
346ace9444 Allow users that have permission to edit their own location to see locations in select list 2023-07-13 17:37:46 -07:00
Ivan Nieto Vivanco
ecac4718fe Add date casting to the SQL query, so the BETWEEN range doesn't care about time of day in custom report datetimes 2023-07-13 16:02:47 -06:00
snipe
4027acee46 Merge pull request #13184 from akemidx/department_in_side_bar
User department now visible in side pane of asset view page
2023-07-13 21:01:48 +01:00
snipe
5aa99a15d8 Merge pull request #13288 from snipe/fixes/line_based_markdown
Added Inline markdown method
2023-07-13 13:16:50 +01:00
snipe
016502f637 Added notesFormatter
Signed-off-by: snipe <snipe@snipe.net>
2023-07-13 13:14:10 +01:00
snipe
5d1f294f0e Added parseEscapedMarkedownInline to accessories API
Signed-off-by: snipe <snipe@snipe.net>
2023-07-13 12:03:01 +01:00
snipe
981c3a430d Merge pull request #13301 from uberbrady/better_auto_increment_tags
Better auto increment asset-tags [FD-32892]
2023-07-13 09:49:44 +01:00
Joël Pittet
24adcdb586 Revert lock file changes for PHP 7 support 2023-07-12 17:58:52 -07:00
akemidx
1163af3c10 change to make sure department actually exists 2023-07-12 15:57:44 -04:00
snipe
232e84acf7 Merge pull request #13302 from snipe/features/env_setting_for_bs_tables
Fixed #13256 - Added option to switch to localStorage instead of cookies
2023-07-12 20:10:33 +01:00
snipe
5d60a38a0e Added comment with link
Signed-off-by: snipe <snipe@snipe.net>
2023-07-12 20:08:20 +01:00
snipe
c1c2c38995 Fixed #13256 - Added option to switch to localStorage instead of cookies
Signed-off-by: snipe <snipe@snipe.net>
2023-07-12 20:06:17 +01:00
snipe
44231fa52c Merge pull request #13225 from inietov/fixes/change_default_location_at_checkin
Fixed #13167 Default location not being set/updated upon check-in
2023-07-12 19:14:53 +01:00
snipe
44b8558e38 Merge pull request #13233 from Godmartinz/barcode_adjusts_if_qr_code_
fixed margin if qr_code present
2023-07-12 17:11:58 +01:00
snipe
d3c44a462e Merge pull request #13268 from inietov/fixes/license_importer_missing_dropdown_items
Fixed License importer missing Checkout to: Username and Checkout to: Email in dropdown [sc-23456]
2023-07-12 17:11:27 +01:00
snipe
a569a99e61 Used inline markdown in views
Signed-off-by: snipe <snipe@snipe.net>
2023-07-12 16:57:04 +01:00
Brady Wetherington
e648da9dc5 Also do a sanity-check that the normal asset autoincrementing works 2023-07-12 16:51:23 +01:00
Brady Wetherington
76191a09ed Improvements to asset_tag auto-incrementing, with auto-fixups for gaps 2023-07-12 16:39:45 +01:00
snipe
1b8b117f4e Merge pull request #13292 from marcusmoore/guard-against-wiping-local-db
Avoid accidentally wiping local database when running tests
2023-07-12 15:23:11 +01:00
Marcus Moore
3df175fb3e Improve variable name 2023-07-11 16:36:38 -07:00
Marcus Moore
44d8b2fd5e Handle default eula checkbox 2023-07-11 16:36:03 -07:00
Ivan Nieto Vivanco
e0df8cc4aa Add admin role to show encrypted customfield values 2023-07-11 17:21:32 -06:00
Marcus Moore
af681d8190 Display message and update checkbox depending on EULA status 2023-07-11 16:12:43 -07:00
snipe
2bc4235368 Merge pull request #13293 from marcusmoore/run-chipper-on-all-prs
Run ChipperCI on all PRs (take three)
2023-07-11 20:36:49 +01:00
Marcus Moore
5b33c00e9f Run ChipperCI on all PRs 2023-07-11 12:34:39 -07:00
Marcus Moore
48e4ec8cf5 Guard against wiping database when running tests and test specific envs are not created 2023-07-11 12:16:37 -07:00
snipe
b5695c9ab7 Test parsedown in notes
Signed-off-by: snipe <snipe@snipe.net>
2023-07-11 12:20:47 +01:00
snipe
6d3bf1e5f5 Added additional method for inline
Signed-off-by: snipe <snipe@snipe.net>
2023-07-11 11:41:58 +01:00
snipe
9b5a67e31f Use $Parsedown->line instead of $Parsedown->text
Signed-off-by: snipe <snipe@snipe.net>
2023-07-11 11:33:29 +01:00
snipe
ba37a9db8c Merge pull request #13277 from snipe/features/added_phone_fax_to_locations
Added phone, fax to departments, locations, companies
2023-07-11 11:15:13 +01:00
snipe
9dc7fc93fb Small fixes
Signed-off-by: snipe <snipe@snipe.net>
2023-07-11 11:14:19 +01:00
snipe
a5555a1c67 Merge pull request #13281 from inietov/fixes/error_showing_requested_assets
Fixed #13276 Error Showing Requested Assets
2023-07-11 11:11:33 +01:00
snipe
d76f420f4e Merge pull request #13282 from marcusmoore/fixes/allow-installing-on-74-v2
Fixes dev dependency on PHP 7.4
2023-07-11 11:10:52 +01:00
Marcus Moore
d8f22880d6 Allow installing on PHP 7.4 2023-07-10 17:35:21 -07:00
Ivan Nieto Vivanco
ec8cb1b09e Add the withTrashed() method to requestingUser() method in CheckoutRequest model, so the view of requestable assets doesn't crash 2023-07-10 16:34:00 -06:00
snipe
4845a88c68 Merge pull request #13280 from snipe/security/webpack-upgade
[Snyk] Upgrade webpack from 5.86.0 to 5.87.0 #13267
2023-07-10 20:17:44 +01:00
snipe
73c2202d94 [Snyk] Upgrade webpack from 5.86.0 to 5.87.0 #13267
Signed-off-by: snipe <snipe@snipe.net>
2023-07-10 20:16:09 +01:00
snipe
0d37d1a905 Merge pull request #13279 from snipe/security/acorn-upgrade
Upgraded acorn
2023-07-10 20:08:46 +01:00
snipe
83cf106ce5 Upgraded acorn
Signed-off-by: snipe <snipe@snipe.net>
2023-07-10 20:06:57 +01:00
snipe
7debf126d6 Dev assets
Signed-off-by: snipe <snipe@snipe.net>
2023-07-10 20:03:12 +01:00
snipe
c5c87ea0ca Merge pull request #13278 from snipe/security/bs-tables-update
Applied Snyk #13272
2023-07-10 20:01:41 +01:00
snipe
8169206943 Applied Snyk #13272
Signed-off-by: snipe <snipe@snipe.net>
2023-07-10 19:59:08 +01:00
snipe
22d9df304b Merge pull request #13265 from marcusmoore/chore/chipperci-on-prs
Have ChipperCi run on each PR
2023-07-10 19:48:40 +01:00
snipe
14c61e4c17 Added phone, fax to departments, locations, companies
Signed-off-by: snipe <snipe@snipe.net>
2023-07-10 19:44:21 +01:00
Joël Pittet
a4a676ef0b Update league/oauth2-server for CVE-2023-3726 and lcobucci/clock to semver to allow dependencies to update 2023-07-10 11:19:54 -07:00
Brady Wetherington
8f2a17585e Merge branch 'develop' into snipeit_v7
Had to do a lot of conflict work here, so this could get ugly :(
2023-07-10 16:53:35 +01:00
Ivan Nieto Vivanco
299e546021 Adds the Username and Email to License Importer dropdown 2023-07-06 18:36:13 -06:00
snipe
5a9c2925c3 Merge pull request #13264 from marcusmoore/bug/sc-23451
Fix label wrapping on category edit page
2023-07-06 19:01:36 +01:00
Marcus Moore
149184dc3c Have ChipperCI on on each PR
Following up on #13218
2023-07-06 11:00:03 -07:00
Marcus Moore
ef160b0e15 Add span tag so label is displayed properly 2023-07-06 10:49:57 -07:00
Ivan Nieto Vivanco
f4ca29b4a8 Only show radio inputs for location in checkin view 2023-07-06 11:36:55 -06:00
Ivan Nieto Vivanco
9591442f1e Evaluate the radio input to update location only or default location too 2023-07-06 10:46:21 -06:00
Ivan Nieto Vivanco
743e852998 Add radio buttons to alter asset checkin location behavior 2023-07-06 10:38:48 -06:00
snipe
2faa73f983 Merge pull request #13169 from akemidx/license_sn_check1
Making Serial Number the logic checked against for new imports
2023-07-06 16:40:27 +01:00
snipe
d37aaee4c8 Merge pull request #13257 from snipe/fixes/check_for_ceiling_in_upgrader
Check for max PHP version in upgrader
2023-07-06 16:07:10 +01:00
snipe
a9d175a396 Check for max PHP version
Signed-off-by: snipe <snipe@snipe.net>
2023-07-05 18:47:48 +01:00
snipe
35039cd590 Merge pull request #13255 from snipe/fixes/larger_field_for_idp_meta
Change settings table `saml_idp_metadata` to MEDIUMTEXT
2023-07-05 17:30:02 +01:00
snipe
c85a33be6a Change settings table saml_idp_metadata to MEDIUMTEXT
Signed-off-by: snipe <snipe@snipe.net>
2023-07-05 17:28:08 +01:00
snipe
d890d923ff Bumped version
Signed-off-by: snipe <snipe@snipe.net>
2023-07-05 14:40:54 +01:00
snipe
4b4983e550 Merge pull request #13253 from uberbrady/improve_scim_404s
Properly return SCIM Exceptions
2023-07-05 14:37:32 +01:00
Brady Wetherington
a6a89ddd6c Also log(debug) the error - could be useful for troubleshooting 2023-07-05 14:31:08 +01:00
Brady Wetherington
1f4d2f1e4a Properly return SCIM Exceptions 2023-07-05 14:27:10 +01:00
Godfrey M
d44e667697 fixed margin if qr_code present 2023-06-29 13:37:38 -07:00
snipe
bbbeaaee2b Merge pull request #13232 from Godmartinz/labels_overlapping_issue
fixed barcode and info from overlapping
2023-06-29 21:23:31 +01:00
Godfrey M
df90e924b4 prevent labels from overlapping 2023-06-29 13:18:17 -07:00
snipe
630b6496ec Merge pull request #13231 from snipe/fixes/small_fix_for_error_during_seeding
Redirect if the license can’t be found
2023-06-29 21:18:02 +01:00
snipe
7937542dcb Redirect if the license can’t be found
Signed-off-by: snipe <snipe@snipe.net>
2023-06-29 21:15:50 +01:00
akemidx
d0212d4bda formatting fix 2023-06-29 15:39:19 -04:00
snipe
e236bf412c Merge pull request #13230 from snipe/fixes/windows_backup_filename_colon_wtf_issue
Fixed windows backup filename - swapped colon in timestamp to hyphen to handle windows filesystems
2023-06-29 20:37:09 +01:00
snipe
fb9b3a5453 Switched from a colon to a hyphen to handle windows filesystems
Signed-off-by: snipe <snipe@snipe.net>
2023-06-29 20:32:20 +01:00
snipe
faf2a235fb Updated dev assets
Signed-off-by: snipe <snipe@snipe.net>
2023-06-29 20:31:13 +01:00
snipe
9f99f8275c Merge pull request #13229 from Godmartinz/status_label_color
fixed custom fields labels being unreadable
2023-06-29 20:21:46 +01:00
slong753
8cee3a8218 ok, @marcusmoore was right all along
i just didn't get it
2023-06-29 14:06:52 -05:00
Godfrey M
f83effbb85 removed unnecessary css rule 2023-06-29 11:25:40 -07:00
Godfrey M
d4cddebba5 fixes custom fields labels being unreadable 2023-06-29 11:21:21 -07:00
snipe
825e988dfa Merge pull request #13228 from snipe/bug/sc-23434
Use proper alias for table scope
2023-06-29 17:11:50 +01:00
snipe
bcefe73c9c Use proper alias for table scope
Signed-off-by: snipe <snipe@snipe.net>
2023-06-29 16:52:09 +01:00
slong753
826ea0ded8 move colon to blade based on a comment 2023-06-29 10:40:04 -05:00
snipe
a3096e1b47 Merge pull request #13219 from inietov/features/cancel_request_asset
Cancel requested assets without checkin/out [ch-17606]
2023-06-29 16:18:13 +01:00
snipe
16ce06a3cc Merge pull request #13222 from snipe/feature/sc-23427
Fixed #13213 - Use the Helper::parseEscapedMarkedown in notes
2023-06-29 16:16:25 +01:00
snipe
8be3a6985b Merge pull request #13227 from snipe/bug/sc-23433
More reshuffling of scopes in assets API
2023-06-29 16:10:26 +01:00
snipe
4c3a306a6e More shuffling of scopes
Signed-off-by: snipe <snipe@snipe.net>
2023-06-29 13:35:41 +01:00
Ivan Nieto Vivanco
011726154c Set rtd_location if a location is given at checkin 2023-06-29 03:16:59 -06:00
slong753
ea61f634fb get rid of nice nullsafe 2023-06-28 16:48:52 -05:00
slong753
afe6fe207a resolved, missed adding errors in a case 2023-06-28 16:45:18 -05:00
akemidx
af03b9f140 user department clarification & translation for that phrase. will be used in a later PR 2023-06-28 17:45:13 -04:00
snipe
f7f2d799f2 Merge pull request #13223 from inietov/fixes/delete_notes_map_from_asset_importer
Delete notes column map from assets importer
2023-06-28 20:06:33 +01:00
slong753
8923206ac8 translation string 2023-06-28 13:08:34 -05:00
slong753
3b8ab2d682 clean formatting a little 2023-06-28 13:00:59 -05:00
slong753
2d27941105 added to textarea too 2023-06-28 12:59:54 -05:00
slong753
50a518e5f3 disable input when field is unique 2023-06-28 12:57:23 -05:00
Ivan Nieto Vivanco
a4b8723dcb Delete notes column map from assets importer 2023-06-28 11:38:51 -06:00
Ivan Nieto Vivanco
e2c2736a9c Delete (gulp) Form for bulk edit since is not used in this view 2023-06-28 11:23:37 -06:00
Ivan Nieto Vivanco
85e717bc4e Fix cancel button style and translate title 2023-06-28 10:38:44 -06:00
snipe
161f4c8d83 Merge pull request #13045 from akemidx/feature/sc-23261
Checkin/out info on side bar
2023-06-28 16:41:21 +01:00
slong753
8b8e7cb5ee couple translation strings 2023-06-28 10:17:28 -05:00
snipe
e1fdfd01f6 Merge pull request #13211 from marcusmoore/company-scoping
Improve testing around company scoping
2023-06-28 16:17:07 +01:00
snipe
4278471d81 Merge pull request #13207 from Godmartinz/half_year_dep_fix
adds half_year fix from jdickerson71388
2023-06-28 15:12:30 +01:00
snipe
e3f381a1e1 Merge pull request #13212 from marcusmoore/feature/sc-23419
Allow running tests in parallel
2023-06-28 15:12:13 +01:00
snipe
8d8adc1639 Use the Helper::parseEscapedMarkedown in notes
Signed-off-by: snipe <snipe@snipe.net>
2023-06-28 15:02:32 +01:00
Brady Wetherington
51424d01a9 Merge branch 'develop' into snipeit_v7 2023-06-28 14:25:33 +01:00
snipe
a455f67d62 Merge pull request #13216 from marcusmoore/bug/sc-23420
Fix translation string in user importer
2023-06-28 07:03:11 +01:00
snipe
b6a11cde65 Merge pull request #13218 from marcusmoore/chore/sc-23424
Have ChipperCI run on each PR
2023-06-28 07:01:14 +01:00
snipe
a8d4494e68 Merge pull request #13220 from marcusmoore/bug/sc-23425
Add missing relationship check in Asset Transformer
2023-06-28 06:59:33 +01:00
Marcus Moore
ab51857854 Check to see if model relationship exists before using it 2023-06-27 19:35:55 -07:00
Ivan Nieto Vivanco
8496e64e16 Adds ternary to set a quantity when needed 2023-06-27 18:37:22 -06:00
Ivan Nieto Vivanco
b4b84f91d0 Redirect to correct page after cancel action 2023-06-27 18:25:38 -06:00
Ivan Nieto Vivanco
1c29bd37a6 Added feature to cancel requests from the Requested Assets view 2023-06-27 18:11:10 -06:00
Marcus Moore
6df7be8c13 Have ChipperCI run on each PR 2023-06-27 16:55:20 -07:00
Ivan Nieto Vivanco
eb4d764601 Refactor Requestable@cancelRequest() firm to admit a user_id so we can cancel a request of whatever user we want 2023-06-27 17:13:11 -06:00
Ivan Nieto Vivanco
b647a8fcd2 Change the inline form HTML label to the Form:: facade 2023-06-27 17:02:25 -06:00
Ivan Nieto Vivanco
62347a56ba Add button with cancel action in requested assets view 2023-06-27 16:41:30 -06:00
Marcus Moore
b0177d513a Fix translation 2023-06-27 12:37:19 -07:00
slong753
e8988bf51e add list 2023-06-26 20:22:27 -05:00
Marcus Moore
3f09e6017b Install paratest to allow for parallel test running 2023-06-26 16:22:28 -07:00
slong753
2736161909 oops, fixed translation 2023-06-26 16:37:06 -05:00
slong753
8cbff0179c translation strings 2023-06-26 16:35:53 -05:00
slong753
2a352619f7 clean up 2023-06-26 16:25:48 -05:00
Marcus Moore
2abdb8a5fd Revert unneeded changes 2023-06-26 14:01:09 -07:00
Marcus Moore
7cb22d3d49 Remove incomplete tests 2023-06-26 14:00:53 -07:00
slong753
691faf6340 ok, this kind of works - pr needs some clean up 2023-06-26 14:56:07 -05:00
Marcus Moore
3cb0920411 Merge branch 'develop' into company-scoping 2023-06-26 12:32:10 -07:00
Godfrey M
114d946437 adds half_year fix from jdickerson71388 2023-06-26 11:26:46 -07:00
snipe
49b50d81ee Merge pull request #13200 from snipe/bug/sc-23417
Set table alias for model number sort scope
2023-06-26 08:29:16 +01:00
snipe
4f7b2836b5 Set table alias for model number sort scope
Signed-off-by: snipe <snipe@snipe.net>
2023-06-26 08:27:17 +01:00
Marcus Moore
acd06927ac Add helper method for authenticating with passport 2023-06-22 17:37:30 -07:00
Spencer Long
f646623a5e Merge branch 'develop' into bulk_edit_custom_fields 2023-06-22 18:00:31 -05:00
Marcus Moore
a35d83d14a Migrate to response macros for readability 2023-06-22 14:41:56 -07:00
akemidx
8df9db76bc column ordering fix 2023-06-22 17:12:40 -04:00
akemidx
8725d40f8d current value added to asset index page. translations for this in reports 2023-06-22 17:00:42 -04:00
snipe
8c6bde335e Merge pull request #13196 from inietov/fixes/default_status_labels_when_import
Fixed issue when importing Assets and no status labels exists [sc-23359]
2023-06-22 21:34:25 +01:00
snipe
b2d74f7e95 Merge pull request #13186 from snipe/bug/sc-23386
Moved logic for tighter constraints when ids are passed
2023-06-22 21:32:36 +01:00
snipe
78d8e32a22 Fixed weird order number thing
Signed-off-by: snipe <snipe@snipe.net>
2023-06-22 21:16:24 +01:00
snipe
4029efebfd Merge pull request #13159 from Godmartinz/audit_image_bug
fixed audit log image not appearing
2023-06-22 21:11:39 +01:00
Marcus Moore
8aae5beaba Add explicit select back to query 2023-06-22 13:09:08 -07:00
Marcus Moore
a8133f62e8 Add explicit select back to query 2023-06-22 13:07:49 -07:00
Ivan Nieto Vivanco
67e47a7d8b Add guard clause to obtain the default ID of imported asset's status label 2023-06-22 13:53:58 -06:00
Marcus Moore
a333d7b72f Add context to incomplete tests 2023-06-22 12:48:09 -07:00
Marcus Moore
ab5fed09db Remove scopeCompanyables call from AssetsController@requestable 2023-06-22 12:36:43 -07:00
Marcus Moore
74b072f1b5 Improve messaging in testing helper 2023-06-22 12:36:30 -07:00
Marcus Moore
0a5e1e3190 Remove scopeCompanyables call from AssetsController@selectlist 2023-06-21 17:21:36 -07:00
Marcus Moore
effd969284 Scaffold test before removing scopeCompanyables call from AssetsController@selectlist 2023-06-21 17:15:02 -07:00
Marcus Moore
fd55c99b87 Remove scopeCompanyables call from AssetsController@index 2023-06-21 16:29:44 -07:00
Marcus Moore
af77fefc61 Scaffold test before removing scopeCompanyables call from AssetsController 2023-06-21 16:19:56 -07:00
Marcus Moore
65e8e4e163 Guard against attempting to use invalid property 2023-06-21 16:18:09 -07:00
snipe
5d4e704fac Added a comment
Signed-off-by: snipe <snipe@snipe.net>
2023-06-21 09:26:54 +01:00
snipe
2d9ddab3f0 Moved logic for tighter constraints when ids are passed
Signed-off-by: snipe <snipe@snipe.net>
2023-06-21 09:24:17 +01:00
akemidx
4b8a08edc1 typo 2023-06-20 19:32:16 -04:00
akemidx
1a407dc05b user department now in side view of asset view page 2023-06-20 19:17:14 -04:00
akemidx
00fd541963 improve logging clarity 2023-06-15 15:09:14 -04:00
akemidx
eda5bbf305 fix to allow empty SN 2023-06-15 14:42:34 -04:00
akemidx
df6b4ff349 tagging code 2023-06-14 15:51:14 -04:00
akemidx
efaed3d02c making serial number logic checked against for new imports 2023-06-14 15:32:47 -04:00
Godfrey M
6dd7181d09 fixed audit log image not appearing 2023-06-12 12:10:19 -07:00
Brady Wetherington
f5ff9b2208 Merge branch 'develop' into snipeit_v7 - 2023-06-12 2023-06-12 16:56:23 +01:00
Marcus Moore
7672861b96 Scaffold test before removing scopeCompanyables call from DashboardController 2023-06-07 17:38:23 -07:00
Marcus Moore
6f5252449e Scaffold test before removing scopeCompanyables call from UsersController 2023-06-07 16:25:18 -07:00
Marcus Moore
0f6051bbe5 Inline method call 2023-06-07 16:18:02 -07:00
Marcus Moore
abaf59c990 Extract and use helper methods 2023-06-07 16:16:30 -07:00
Marcus Moore
27d4d107bb Scaffold test before removing scopeCompanyables call from DepartmentsController 2023-06-07 16:10:29 -07:00
Marcus Moore
8e6e525b47 Remove scopeCompanyables call from LicensesController 2023-06-07 16:09:45 -07:00
Marcus Moore
a18f5e7fc0 Remove scopeCompanyables call from ConsumablesController 2023-06-07 14:22:22 -07:00
Marcus Moore
48850f3597 Remove scopeCompanyables call from ComponentsController 2023-06-06 18:02:18 -07:00
Marcus Moore
4fb86ad2fb Get name as a string and not an array 2023-06-06 16:31:26 -07:00
Marcus Moore
42a4941ad2 Ensure consumable name is valid in factory 2023-06-06 16:31:26 -07:00
Marcus Moore
6585aa0cf0 Add unit tests for company scoping 2023-06-06 16:31:14 -07:00
Brady Wetherington
a9c7dbd17a Shift PHP version requiremeents for Snipe-IT v7 to be php 8.0-8.2 2023-05-17 17:51:02 -07:00
Brady Wetherington
09fdc946a0 Merge branch 'develop' into snipeit_v7
Had to do some asset rebuilds, and a composer update
2023-05-17 17:37:10 -07:00
akemidx
deca80ba71 checkin/out info on side bar 2023-05-17 13:17:48 -04:00
akemidx
ba4fc146e2 Merge branch 'delete_asset_from_view_page' of https://github.com/akemidx/snipe-it into delete_asset_from_view_page 2023-05-10 19:30:11 -04:00
akemidx
1916594d27 fixing translation 2023-05-10 19:16:11 -04:00
slong753
5e34ffa2b0 wip 2023-05-10 14:08:12 -05:00
akemidx
537aa04c9a Merge branch 'develop' into delete_asset_from_view_page 2023-05-10 09:30:54 -04:00
slong753
1d2596fc54 wip 2023-05-09 14:58:59 -05:00
slong753
815c77f943 wip 2023-05-03 14:49:31 -05:00
akemidx
889be83762 replacing route. sorry! 2023-05-03 14:14:18 -04:00
snipe
31f1bce16b Merge pull request #12958 from uberbrady/snipeit_v7_merge_develop_05_01_2022
Snipeit v7 merge develop 05 01 2022
2023-05-03 10:40:18 -07:00
slong753
cdda4a56d8 aha, ok thisd kind of works 2023-05-02 19:11:43 -05:00
slong753
b2c2097e8b just more troubleshooting stuff, still no solution 2023-05-02 18:54:20 -05:00
Brady Wetherington
2f3ddaec20 Merge branch 'develop' into snipeit_v7 2023-05-01 18:09:12 -07:00
snipe
7cd37e6e95 Merge pull request #12957 from uberbrady/fix_webpack_for_v7
Fix webpack for v7
2023-05-01 18:08:46 -07:00
Brady Wetherington
a938009074 Rebuilt assets with new Node and node_modules and package.json 2023-05-01 18:06:51 -07:00
Brady Wetherington
21d08ff742 Whoops! Forgot to commit this before 2023-05-01 18:05:06 -07:00
snipe
da8b41b12a Merge pull request #12956 from uberbrady/upgrade_node_and_packages_for_v7
Updated Node version, and various packages to more recent
2023-05-01 17:33:20 -07:00
Brady Wetherington
6e031727fa Updated Node version, and various packages to more recent 2023-05-01 17:05:10 -07:00
akemidx
2cb1545b83 removing route 2023-05-01 19:51:52 -04:00
akemidx
ad7a1d6c3b edits from Github comments 2023-05-01 15:50:48 -04:00
akemidx
1c60d686bd Merge remote-tracking branch 'origin/delete_asset_from_view_page' into delete_asset_from_view_page
# Conflicts:
#	resources/views/hardware/view.blade.php
2023-04-27 19:08:51 -04:00
akemidx
cd389368f7 adding in script 2023-04-27 19:00:17 -04:00
akemidx
d3675831bb snippet rewrite 2023-04-27 18:58:59 -04:00
akemidx
84134b45e6 form work 2023-04-27 18:58:59 -04:00
akemidx
b1e68be545 delete button progress 2023-04-27 18:58:59 -04:00
akemidx
d94bed3f57 push for testing 2023-04-27 18:58:59 -04:00
akemidx
aabcf22b40 commiting 2023-04-27 18:58:59 -04:00
akemidx
af549a0be9 Mock Up of the Buttons 2023-04-27 18:58:59 -04:00
Brady Wetherington
381890b578 Merge branch 'develop' into laravel_v9 2023-04-27 13:56:04 -07:00
slong753
52c9fefbe0 ok, this works except error display 2023-04-26 15:06:50 -05:00
slong753
6bec9cf880 fix a couple things 2023-04-25 23:26:16 -05:00
Godfrey M
b8c424fca0 adds users total cost to user profile 2023-04-24 09:17:42 -07:00
Godfrey M
97df39001d adds optional breakdowns for total cost 2023-04-19 17:51:37 -07:00
Godfrey M
6872f8da7b adding total cost to user view 2023-04-19 17:31:09 -07:00
Brady Wetherington
71fa6d765f Update to Latest Livewire files 2023-04-18 11:05:35 -07:00
Brady Wetherington
9793130f6c Merge branch 'develop' into laravel_v9 2023-04-18 11:01:00 -07:00
slong753
52dc99588e pushing for now, needs validation work 2023-04-17 13:57:48 -05:00
slong753
8b9aea8874 very much WIP, but dupe queries reduced
but i think this can be cleaned up a bit more
2023-04-12 14:46:48 -05:00
akemidx
a65b8025b6 push for testing 2023-04-11 13:53:56 -04:00
akemidx
cc88a361ca commiting 2023-04-06 15:01:01 -04:00
slong753
830e3e5594 cleanup 2023-04-05 15:27:28 -05:00
slong753
d56a4e7173 cleanup+formatting 2023-04-05 15:16:46 -05:00
slong753
3929526a57 ok, this works but needs to be tested more 2023-04-04 18:57:51 -05:00
akemidx
f5122b01b1 Mock Up of the Buttons 2023-04-04 15:51:04 -04:00
slong753
29e3d202fe checking something, quick push 2023-04-03 17:54:31 -05:00
slong753
b0fa298d8f delete a couple things 2023-03-29 15:14:48 -05:00
slong753
65bbecd145 this all works - could use some eyes 2023-03-29 14:46:31 -05:00
slong753
032ae4348e custom fields display, need to get saving
+some clean up
2023-03-28 21:45:31 -05:00
slong753
804a788a27 initial fetch working 2023-03-28 20:31:24 -05:00
Brady Wetherington
aadfa9aa9c Back out Laravel Vite stuff - we're so far away from that right now 2023-02-21 19:54:14 -08:00
Brady Wetherington
645bba96cd WIP: First stabs at getting Laravel Vite to work; no luck so far :(
Probably going to back out all the 'vite' stuff anyways :/
2023-02-21 19:35:37 -08:00
cram42
0f3c5d10ba Merge branch 'feature-label2' into develop 2023-02-01 18:01:46 +11:00
cram42
73fd0a24ca Clarify example asset variable 2023-02-01 17:58:58 +11:00
cram42
4b4c228f1a Correct parameter order 2023-02-01 17:56:23 +11:00
cram42
b72c6b7afc Fix 2D barcode defaults 2023-02-01 17:48:39 +11:00
cram42
c2c009a018 Merge branch 'develop' into develop 2023-01-24 09:53:42 +08:00
Cram42
17e81af4cd Add more Avery label sheets 2022-11-12 20:29:50 +08:00
Cram42
ffce6ec327 Need uppercase 2022-11-12 20:29:34 +08:00
Cram42
60ef5686ab Add "Pop Out" button for preview 2022-11-12 19:02:38 +08:00
Cram42
af0872dc23 Fix form refresh after bootstrap-table 2022-11-11 14:23:38 +08:00
Cram42
30a7a31724 Move label preview to alpine component 2022-11-11 14:23:02 +08:00
Cram42
67d021e457 Add alpinejs to deferred scripts 2022-11-11 11:25:41 +08:00
Cram42
7108156072 Fix button disabling 2022-11-10 19:24:02 +08:00
Cram42
a4b93d4bbd Create Field Definitions helper control 2022-11-10 19:20:18 +08:00
Cram42
f849fcca89 Change the way fields are passed 2022-11-10 18:54:02 +08:00
Cram42
fd9616683c Label preview auto-refresh 2022-11-03 10:20:12 +08:00
Cram42
3d470d6f2f Drop asset tag from default field def. 2022-11-02 22:39:08 +08:00
Cram42
53513d93fa Rework TZe labels for Asset Tag support 2022-11-02 22:38:00 +08:00
Cram42
f5fac50e91 Add preview pane 2022-11-02 19:31:34 +08:00
Cram42
36210f1c6a Allow settings to be overridden in request 2022-11-02 19:30:45 +08:00
Cram42
48fb4f2439 Add labels route for testing layouts 2022-11-02 17:23:52 +08:00
Cram42
fb467d9078 Include Asset for advanced users 2022-11-02 17:20:01 +08:00
Cram42
4fee5ece43 Support Avery L7163 2022-11-02 16:08:10 +08:00
Cram42
4bb40adfce Add Asset Tag as separate supported feature 2022-11-02 16:07:50 +08:00
Cram42
06ce40ac08 Don't add data if it's not there 2022-11-02 16:05:52 +08:00
Cram42
a8b6a4a259 Allow passing "template" param 2022-11-02 16:04:40 +08:00
Cram42
a60ee7736b Add P-touch TZe 12mm Tape Example 2022-11-02 12:22:55 +08:00
Cram42
d0eb3cfc9b Merge branch 'feature-label2' into develop 2022-11-02 10:09:46 +08:00
Cram42
19150aeb44 Add P-touch TZe 24mm Tape Example 2022-11-02 10:09:11 +08:00
Cram42
cde2ba7720 Fix: Oops 2022-11-02 09:51:02 +08:00
Cram42
6b2fe582ca Merge branch 'feature-label2' into develop 2022-11-01 20:12:28 +08:00
cram42
7e2546b31f Merge branch 'snipe:develop' into develop 2022-11-01 20:04:59 +08:00
Cram42
7b29ddd283 Tie into tag generation 2022-11-01 20:02:12 +08:00
Cram42
d37605ff18 Add localization strings 2022-11-01 20:01:18 +08:00
Cram42
6de48b4dc8 Implement settings for labels 2022-11-01 20:00:53 +08:00
Cram42
5558a005b9 Implement API for labels 2022-11-01 19:57:51 +08:00
Cram42
bb09f0168f Create Label View/Generator 2022-11-01 19:56:53 +08:00
Cram42
4ed728d954 Add template to simulate legacy label 2022-11-01 19:54:00 +08:00
Cram42
bbecdb6768 Add QR example 2022-11-01 19:53:11 +08:00
Cram42
df89406987 Create Label model and example 2022-11-01 19:52:34 +08:00
Cram42
7c355cef2d Add helper to convert between units of measurement 2022-11-01 19:49:57 +08:00
Cram42
35536b5dbd Require tecnickcom/tcpdf 2022-11-01 19:47:59 +08:00
Cram42
0e69e4248c Fix: Multiple outputs at hardware/{id}/label 2022-10-27 08:12:42 +08:00
883 changed files with 24477 additions and 306642 deletions

View File

@@ -2952,6 +2952,15 @@
"contributions": [
"code"
]
},
{
"login": "cram42",
"name": "Grant Le Roux",
"avatar_url": "https://avatars.githubusercontent.com/u/5396871?v=4",
"profile": "https://github.com/cram42",
"contributions": [
"code"
]
}
]
}

View File

@@ -6,7 +6,6 @@ environment:
services:
- mysql: 5.7
- dusk:
on:
push:
@@ -14,11 +13,14 @@ on:
- master
- develop
pull_request:
branches: .*
pipeline:
- name: Setup
cmd: |
cp -v .env.example .env
cp -v .env.testing.example .env
cp -v .env.testing.example .env.testing
composer install --no-interaction --prefer-dist --optimize-autoloader
- name: Generate Key
@@ -31,28 +33,12 @@ pipeline:
- name: Run Migrations
cmd: |
# php artisan migrate --force
php artisan migrate --force
- name: PHPUnit Unit Tests
cmd: |
# php artisan test --testsuite Unit
php artisan test --testsuite Unit
- name: PHPUnit Feature Tests
cmd: |
# php artisan test --testsuite Feature
# - name: Browser Tests
# cmd: |
# cp -v .env.dusk.example .env.dusk.ci
# sed -i "s@APP_ENV=.*@APP_ENV=ci@g" .env.dusk.ci
# sed -i "s@APP_URL=.*@APP_URL=http://$BUILD_HOST:8000@g" .env.dusk.ci
# #sed -i "s@DB_HOST=.*@DB_HOST=mysql@g" .env.dusk.ci
# sed -i "s@DB_HOST=.*@DB_HOST=$DB_HOST@g" .env.dusk.ci
# sed -i "s@DB_USERNAME=.*@DB_USERNAME=chipperci@g" .env.dusk.ci
# sed -i "s@DB_DATABASE=.*@DB_DATABASE=chipperci@g" .env.dusk.ci
# sed -i "s@DB_PASSWORD=.*@DB_PASSWORD=secret@g" .env.dusk.ci
#
# php -S [::0]:8000 -t public 2>server.log &
# sleep 2
# php artisan dusk:chrome-driver $CHROME_DRIVER
# php artisan dusk --env=ci
php artisan test --testsuite Feature

View File

@@ -85,6 +85,7 @@ COOKIE_NAME=snipeit_session
COOKIE_DOMAIN=null
SECURE_COOKIES=false
API_TOKEN_EXPIRATION_YEARS=15
BS_TABLE_STORAGE=cookieStorage
# --------------------------------------------
# OPTIONAL: SECURITY HEADER SETTINGS
@@ -148,6 +149,7 @@ AWS_DEFAULT_REGION=null
# --------------------------------------------
LOGIN_MAX_ATTEMPTS=5
LOGIN_LOCKOUT_DURATION=60
LOGIN_AUTOCOMPLETE=false
# --------------------------------------------
# OPTIONAL: FORGOTTEN PASSWORD SETTINGS

73
.github/workflows/tests.yml vendored Normal file
View File

@@ -0,0 +1,73 @@
name: Tests
on:
push:
branches:
- master
- develop
pull_request:
jobs:
tests:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: snipeit
ports:
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1.1"
name: PHP ${{ matrix.php-version }}
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php-version }}"
coverage: none
- uses: actions/checkout@v3
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Copy .env
run: |
cp -v .env.testing.example .env
cp -v .env.testing.example .env.testing
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_CONNECTION: mysql
DB_DATABASE: snipeit
DB_PORT: ${{ job.services.mysql.ports[3306] }}
DB_USERNAME: root
run: php artisan test --parallel

2
.gitignore vendored
View File

@@ -1,8 +1,6 @@
.couscous
.DS_Store
.env
.env.dusk.*
!.env.dusk.example
.env.testing
phpstan.neon
.idea

2
.nvmrc
View File

@@ -1 +1 @@
v12.22.1
v18.16.0

View File

@@ -1,5 +1,5 @@
![Build Status](https://app.chipperci.com/projects/0e5f8979-31eb-4ee6-9abf-050b76ab0383/status/master) [![Crowdin](https://d322cqt584bo4o.cloudfront.net/snipe-it/localized.svg)](https://crowdin.com/project/snipe-it) [![Docker Pulls](https://img.shields.io/docker/pulls/snipe/snipe-it.svg)](https://hub.docker.com/r/snipe/snipe-it/) [![Twitter Follow](https://img.shields.io/twitter/follow/snipeitapp.svg?style=social)](https://twitter.com/snipeitapp) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/553ce52037fc43ea99149785afcfe641)](https://www.codacy.com/app/snipe/snipe-it?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=snipe/snipe-it&amp;utm_campaign=Badge_Grade)
[![All Contributors](https://img.shields.io/badge/all_contributors-325-orange.svg?style=flat-square)](#contributors) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/yZFtShAcKk) [![huntr](https://cdn.huntr.dev/huntr_security_badge_mono.svg)](https://huntr.dev)
[![All Contributors](https://img.shields.io/badge/all_contributors-326-orange.svg?style=flat-square)](#contributors) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/yZFtShAcKk) [![huntr](https://cdn.huntr.dev/huntr_security_badge_mono.svg)](https://huntr.dev)
## Snipe-IT - Open Source Asset Management System
@@ -145,7 +145,7 @@ Thanks goes to all of these wonderful people ([emoji key](https://github.com/ken
| [<img src="https://avatars.githubusercontent.com/u/28321?v=4" width="110px;"/><br /><sub>Chris Hartjes</sub>](http://www.littlehart.net/atthekeyboard)<br />[💻](https://github.com/snipe/snipe-it/commits?author=chartjes "Code") | [<img src="https://avatars.githubusercontent.com/u/2404584?v=4" width="110px;"/><br /><sub>geo-chen</sub>](https://github.com/geo-chen)<br />[💻](https://github.com/snipe/snipe-it/commits?author=geo-chen "Code") | [<img src="https://avatars.githubusercontent.com/u/6006620?v=4" width="110px;"/><br /><sub>Phan Nguyen</sub>](https://github.com/nh314)<br />[💻](https://github.com/snipe/snipe-it/commits?author=nh314 "Code") | [<img src="https://avatars.githubusercontent.com/u/115993812?v=4" width="110px;"/><br /><sub>Iisakki Jaakkola</sub>](https://github.com/StarlessNights)<br />[💻](https://github.com/snipe/snipe-it/commits?author=StarlessNights "Code") | [<img src="https://avatars.githubusercontent.com/u/22633385?v=4" width="110px;"/><br /><sub>Ikko Ashimine</sub>](https://bandism.net/)<br />[💻](https://github.com/snipe/snipe-it/commits?author=eltociear "Code") | [<img src="https://avatars.githubusercontent.com/u/56871540?v=4" width="110px;"/><br /><sub>Lukas Fehling</sub>](https://github.com/lukasfehling)<br />[💻](https://github.com/snipe/snipe-it/commits?author=lukasfehling "Code") | [<img src="https://avatars.githubusercontent.com/u/1975990?v=4" width="110px;"/><br /><sub>Fernando Almeida</sub>](https://github.com/fernando-almeida)<br />[💻](https://github.com/snipe/snipe-it/commits?author=fernando-almeida "Code") |
| [<img src="https://avatars.githubusercontent.com/u/116301219?v=4" width="110px;"/><br /><sub>akemidx</sub>](https://github.com/akemidx)<br />[💻](https://github.com/snipe/snipe-it/commits?author=akemidx "Code") | [<img src="https://avatars.githubusercontent.com/u/144778?v=4" width="110px;"/><br /><sub>Oguz Bilgic</sub>](http://oguz.site)<br />[💻](https://github.com/snipe/snipe-it/commits?author=oguzbilgic "Code") | [<img src="https://avatars.githubusercontent.com/u/9262438?v=4" width="110px;"/><br /><sub>Scooter Crawford</sub>](https://github.com/scoo73r)<br />[💻](https://github.com/snipe/snipe-it/commits?author=scoo73r "Code") | [<img src="https://avatars.githubusercontent.com/u/5957345?v=4" width="110px;"/><br /><sub>subdriven</sub>](https://github.com/subdriven)<br />[💻](https://github.com/snipe/snipe-it/commits?author=subdriven "Code") | [<img src="https://avatars.githubusercontent.com/u/658865?v=4" width="110px;"/><br /><sub>Andrew Savinykh</sub>](https://github.com/AndrewSav)<br />[💻](https://github.com/snipe/snipe-it/commits?author=AndrewSav "Code") | [<img src="https://avatars.githubusercontent.com/u/1155067?v=4" width="110px;"/><br /><sub>Tadayuki Onishi</sub>](https://kenchan0130.github.io)<br />[💻](https://github.com/snipe/snipe-it/commits?author=kenchan0130 "Code") | [<img src="https://avatars.githubusercontent.com/u/112496896?v=4" width="110px;"/><br /><sub>Florian</sub>](https://github.com/floschoepfer)<br />[💻](https://github.com/snipe/snipe-it/commits?author=floschoepfer "Code") |
| [<img src="https://avatars.githubusercontent.com/u/7305753?v=4" width="110px;"/><br /><sub>Spencer Long</sub>](http://spencerlong.com)<br />[💻](https://github.com/snipe/snipe-it/commits?author=spencerrlongg "Code") | [<img src="https://avatars.githubusercontent.com/u/1141514?v=4" width="110px;"/><br /><sub>Marcus Moore</sub>](https://github.com/marcusmoore)<br />[💻](https://github.com/snipe/snipe-it/commits?author=marcusmoore "Code") | [<img src="https://avatars.githubusercontent.com/u/570639?v=4" width="110px;"/><br /><sub>Martin Meredith</sub>](https://github.com/Mezzle)<br /> | [<img src="https://avatars.githubusercontent.com/u/5731963?v=4" width="110px;"/><br /><sub>dboth</sub>](http://dboth.de)<br />[💻](https://github.com/snipe/snipe-it/commits?author=dboth "Code") | [<img src="https://avatars.githubusercontent.com/u/87536651?v=4" width="110px;"/><br /><sub>Zachary Fleck</sub>](https://github.com/zacharyfleck)<br />[💻](https://github.com/snipe/snipe-it/commits?author=zacharyfleck "Code") | [<img src="https://avatars.githubusercontent.com/u/74609912?v=4" width="110px;"/><br /><sub>VIKAAS-A</sub>](https://github.com/vikaas-cyper)<br />[💻](https://github.com/snipe/snipe-it/commits?author=vikaas-cyper "Code") | [<img src="https://avatars.githubusercontent.com/u/88882041?v=4" width="110px;"/><br /><sub>Abdul Kareem</sub>](https://github.com/ak-piracha)<br />[💻](https://github.com/snipe/snipe-it/commits?author=ak-piracha "Code") |
| [<img src="https://avatars.githubusercontent.com/u/111287779?v=4" width="110px;"/><br /><sub>NojoudAlshehri</sub>](https://github.com/NojoudAlshehri)<br />[💻](https://github.com/snipe/snipe-it/commits?author=NojoudAlshehri "Code") | [<img src="https://avatars.githubusercontent.com/u/54367449?v=4" width="110px;"/><br /><sub>Stefan Stidl</sub>](https://github.com/stefanstidlffg)<br />[💻](https://github.com/snipe/snipe-it/commits?author=stefanstidlffg "Code") | [<img src="https://avatars.githubusercontent.com/u/87803479?v=4" width="110px;"/><br /><sub>Quentin Aymard</sub>](https://github.com/qay21)<br />[💻](https://github.com/snipe/snipe-it/commits?author=qay21 "Code") |
| [<img src="https://avatars.githubusercontent.com/u/111287779?v=4" width="110px;"/><br /><sub>NojoudAlshehri</sub>](https://github.com/NojoudAlshehri)<br />[💻](https://github.com/snipe/snipe-it/commits?author=NojoudAlshehri "Code") | [<img src="https://avatars.githubusercontent.com/u/54367449?v=4" width="110px;"/><br /><sub>Stefan Stidl</sub>](https://github.com/stefanstidlffg)<br />[💻](https://github.com/snipe/snipe-it/commits?author=stefanstidlffg "Code") | [<img src="https://avatars.githubusercontent.com/u/87803479?v=4" width="110px;"/><br /><sub>Quentin Aymard</sub>](https://github.com/qay21)<br />[💻](https://github.com/snipe/snipe-it/commits?author=qay21 "Code") | [<img src="https://avatars.githubusercontent.com/u/5396871?v=4" width="110px;"/><br /><sub>Grant Le Roux</sub>](https://github.com/cram42)<br />[💻](https://github.com/snipe/snipe-it/commits?author=cram42 "Code") |
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!

View File

@@ -9,7 +9,39 @@ Before starting, follow the [instructions](README.md#installation) for installin
Before attempting to run the test suite copy the example environment file for tests and update the values to match your environment:
`cp .env.testing.example .env.testing`
> Since the data in the database is flushed after each test it is recommended you create a separate mysql database for specifically for tests
The following should work for running tests in memory with sqlite:
```
# --------------------------------------------
# REQUIRED: BASIC APP SETTINGS
# --------------------------------------------
APP_ENV=testing
APP_DEBUG=true
APP_KEY=base64:glJpcM7BYwWiBggp3SQ/+NlRkqsBQMaGEOjemXqJzOU=
APP_URL=http://localhost:8000
APP_TIMEZONE='UTC'
APP_LOCALE=en
# --------------------------------------------
# REQUIRED: DATABASE SETTINGS
# --------------------------------------------
DB_CONNECTION=sqlite_testing
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=null
#DB_USERNAME=null
#DB_PASSWORD=null
```
To use MySQL you should update the `DB_` variables to match your local test database:
```
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE={}
DB_USERNAME={}
DB_PASSWORD={}
```
Now you are ready to run the entire test suite from your terminal:
@@ -18,34 +50,3 @@ Now you are ready to run the entire test suite from your terminal:
To run individual test files, you can pass the path to the test that you want to run:
`php artisan test tests/Unit/AccessoryTest.php`
## Browser Tests
Browser tests are run via [Laravel Dusk](https://laravel.com/docs/8.x/dusk) and require Google Chrome to be installed.
Before attempting to run Dusk tests copy the example environment file for Dusk and update the values to match your environment:
`cp .env.dusk.example .env.dusk.local`
> `local` refers to the value of `APP_ENV` in your `.env` so if you have it set to `dev` then the file should be named `.env.dusk.dev`.
**Important**: Dusk tests cannot be run using an in-memory SQLite database. Additionally, the Dusk test suite uses the `DatabaseMigrations` trait which will leave the database in a fresh state after running. Therefore, it is recommended that you create a test database and point `DB_DATABASE` in `.env.dusk.local` to it.
### Running Browser Tests
Your application needs to be configured and up and running in order for the browser tests to actually run. When running the tests locally, you can start the application using the following command:
`php artisan serve`
Now you are ready to run the test suite. Use the following command from another terminal tab or window:
`php artisan dusk`
To run individual test files, you can pass the path to the test that you want to run:
`php artisan dusk tests/Browser/LoginTest.php`
If you get an error when attempting to run Dusk tests that says `Couldn't connect to server` run:
`php artisan dusk:chrome-driver --detect`
This command will install the specific ChromeDriver Dusk needs for your operating system and Chrome version.

View File

@@ -212,9 +212,12 @@ class LdapSync extends Command
$item['manager'] = $results[$i][$ldap_result_manager][0] ?? '';
$item['location'] = $results[$i][$ldap_result_location][0] ?? '';
$location = Location::firstOrCreate([
'name' => $item['location'],
]);
// ONLY if you are using the "ldap_location" option *AND* you have an actual result
if ($ldap_result_location && $item['location']) {
$location = Location::firstOrCreate([
'name' => $item['location'],
]);
}
$department = Department::firstOrCreate([
'name' => $item['department'],
]);
@@ -231,17 +234,39 @@ class LdapSync extends Command
$item['createorupdate'] = 'created';
}
$user->first_name = $item['firstname'];
$user->last_name = $item['lastname'];
//If a sync option is not filled in on the LDAP settings don't populate the user field
if($ldap_result_username != null){
$user->username = $item['username'];
$user->email = $item['email'];
}
if($ldap_result_last_name != null){
$user->last_name = $item['lastname'];
}
if($ldap_result_first_name != null){
$user->first_name = $item['firstname'];
}
if($ldap_result_emp_num != null){
$user->employee_num = e($item['employee_number']);
}
if($ldap_result_email != null){
$user->email = $item['email'];
}
if($ldap_result_phone != null){
$user->phone = $item['telephone'];
}
if($ldap_result_jobtitle != null){
$user->jobtitle = $item['jobtitle'];
}
if($ldap_result_country != null){
$user->country = $item['country'];
}
if($ldap_result_dept != null){
$user->department_id = $department->id;
$user->location_id = $location->id;
}
if($ldap_result_location != null){
$user->location_id = $location ? $location->id : null;
}
if($ldap_result_manager != null){
if($item['manager'] != null) {
// Check Cache first
if (isset($manager_cache[$item['manager']])) {
@@ -281,6 +306,7 @@ class LdapSync extends Command
}
}
}
// Sync activated state for Active Directory.
if ( !empty($ldap_result_active_flag)) { // IF we have an 'active' flag set....

View File

@@ -15,18 +15,20 @@ class CheckoutableCheckedIn
public $checkedInBy;
public $note;
public $action_date; // Date setted in the hardware.checkin view at the checkin_at input, for the action log
public $originalValues;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($checkoutable, $checkedOutTo, User $checkedInBy, $note, $action_date = null)
public function __construct($checkoutable, $checkedOutTo, User $checkedInBy, $note, $action_date = null, $originalValues = [])
{
$this->checkoutable = $checkoutable;
$this->checkedOutTo = $checkedOutTo;
$this->checkedInBy = $checkedInBy;
$this->note = $note;
$this->action_date = $action_date ?? date('Y-m-d');
$this->originalValues = $originalValues;
}
}

View File

@@ -14,17 +14,19 @@ class CheckoutableCheckedOut
public $checkedOutTo;
public $checkedOutBy;
public $note;
public $originalValues;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($checkoutable, $checkedOutTo, User $checkedOutBy, $note)
public function __construct($checkoutable, $checkedOutTo, User $checkedOutBy, $note, $originalValues = [])
{
$this->checkoutable = $checkoutable;
$this->checkedOutTo = $checkedOutTo;
$this->checkedOutBy = $checkedOutBy;
$this->note = $note;
$this->originalValues = $originalValues;
}
}

View File

@@ -75,7 +75,12 @@ class Handler extends ExceptionHandler
// Handle SCIM exceptions
if ($e instanceof SCIMException) {
return response()->json(Helper::formatStandardApiResponse('error', null, 'Invalid SCIM Request'), 400);
try {
$e->report(); // logs as 'debug', so shouldn't get too noisy
} catch(\Exception $reportException) {
//do nothing
}
return $e->render($request); // ALL SCIMExceptions have the 'render()' method
}
// Handle standard requests that fail because Carbon cannot parse the date on validation (when a submitted date value is definitely not a date)

View File

@@ -0,0 +1,77 @@
<?php
namespace App\Helpers;
use Illuminate\Support\Facades\Gate;
/*********************
* These two helper methods are more designed for being re-used with the new HasCustomFields Trait
*
* The 'transform' method is designed for BlahTransformer things that need to return custom field values.
*
* The 'present' method is designed for when you're trying to generate fieldlists for use in Bootstrap tables
* - typically the 'dataTableLayout' method
*
*********************/
class CustomFieldHelper {
static function transform($fieldset, $item) {
if ($fieldset && ($fieldset->fields->count() > 0)) {
$fields_array = [];
foreach ($fieldset->fields as $field) {
if ($field->isFieldDecryptable($item->{$field->db_column})) {
$decrypted = Helper::gracefulDecrypt($field, $item->{$field->db_column});
$value = (Gate::allows('assets.view.encrypted_custom_fields')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));
if ($field->format == 'DATE'){
if (Gate::allows('assets.view.encrypted_custom_fields')){
$value = Helper::getFormattedDateObject($value, 'date', false);
} else {
$value = strtoupper(trans('admin/custom_fields/general.encrypted'));
}
}
$fields_array[$field->name] = [
'field' => e($field->db_column),
'value' => e($value),
'field_format' => $field->format,
'element' => $field->element,
];
} else {
$value = $item->{$field->db_column};
if (($field->format == 'DATE') && (!is_null($value)) && ($value!='')){
$value = Helper::getFormattedDateObject($value, 'date', false);
}
$fields_array[$field->name] = [
'field' => e($field->db_column),
'value' => e($value),
'field_format' => $field->format,
'element' => $field->element,
];
}
return $fields_array;
}
} else {
return new \stdClass; // HACK to force generation of empty object instead of empty list
}
}
static function present($field) {
return [
'field' => 'custom_fields.'.$field->db_column,
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => $field->name,
'formatter'=> 'customFieldsFormatter',
'escape' => true,
'class' => ($field->field_encrypted == '1') ? 'css-padlock' : '',
'visible' => ($field->show_in_listview == '1') ? true : false,
];
}
}

View File

@@ -2,6 +2,8 @@
namespace App\Helpers;
use App\Models\Accessory;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Component;
use App\Models\Consumable;
use App\Models\CustomField;
@@ -33,6 +35,16 @@ class Helper
}
}
public static function parseEscapedMarkedownInline($str = null)
{
$Parsedown = new \Parsedown();
$Parsedown->setSafeMode(true);
if ($str) {
return $Parsedown->line($str);
}
}
/**
* The importer has formatted number strings since v3,
* so the value might be a string, or an integer.
@@ -543,8 +555,8 @@ class Helper
'license' => trans('general.license'),
];
if($selection != null){
return $category_types[$selection];
if ($selection != null){
return $category_types[strtolower($selection)];
}
else
return $category_types;
@@ -563,6 +575,17 @@ class Helper
return $customfields;
}
/**
* Get all of the different types of custom fields there are
* TODO - how to make this more general? Or more useful? or more dynamic?
* idea - key of classname, *value* of trans? (thus having to make this a method, which is fine)
*/
static $itemtypes_having_custom_fields = [
0 => \App\Models\Asset::class,
1 => \App\Models\User::class,
// 2 => \App\Models\Accessory::class
];
/**
* Get the list of custom field formats in an array to make a dropdown menu
*
@@ -633,6 +656,7 @@ class Helper
$consumables = Consumable::withCount('consumableAssignments as consumable_assignments_count')->whereNotNull('min_amt')->get();
$accessories = Accessory::withCount('users as users_count')->whereNotNull('min_amt')->get();
$components = Component::whereNotNull('min_amt')->get();
$asset_models = AssetModel::where('min_amt', '>', 0)->get();
$avail_consumables = 0;
$items_array = [];
@@ -695,6 +719,28 @@ class Helper
}
}
foreach ($asset_models as $asset_model){
$asset = new Asset();
$total_owned = $asset->where('model_id', '=', $asset_model->id)->count();
$avail = $asset->where('model_id', '=', $asset_model->id)->whereNull('assigned_to')->count();
if ($avail < ($asset_model->min_amt)+ \App\Models\Setting::getSettings()->alert_threshold) {
if ($avail > 0) {
$percent = number_format((($avail / $total_owned) * 100), 0);
} else {
$percent = 100;
}
$items_array[$all_count]['id'] = $asset_model->id;
$items_array[$all_count]['name'] = $asset_model->name;
$items_array[$all_count]['type'] = 'models';
$items_array[$all_count]['percent'] = $percent;
$items_array[$all_count]['remaining'] = $avail;
$items_array[$all_count]['min_amt'] = $asset_model->min_amt;
$all_count++;
}
}
return $items_array;
}
@@ -1210,10 +1256,60 @@ class Helper
return true;
\Log::debug('app locked!');
}
return false;
}
/**
* Conversion between units of measurement
*
* @author Grant Le Roux <grant.leroux+snipe-it@gmail.com>
* @since 5.0
* @param float $value Measurement value to convert
* @param string $srcUnit Source unit of measurement
* @param string $dstUnit Destination unit of measurement
* @param int $round Round the result to decimals (Default false - No rounding)
* @return float
*/
public static function convertUnit($value, $srcUnit, $dstUnit, $round=false) {
$srcFactor = static::getUnitConversionFactor($srcUnit);
$dstFactor = static::getUnitConversionFactor($dstUnit);
$output = $value * $srcFactor / $dstFactor;
return ($round !== false) ? round($output, $round) : $output;
}
/**
* Get conversion factor from unit of measurement to mm
*
* @author Grant Le Roux <grant.leroux+snipe-it@gmail.com>
* @since 5.0
* @param string $unit Unit of measurement
* @return float
*/
public static function getUnitConversionFactor($unit) {
switch (strtolower($unit)) {
case 'mm':
return 1.0;
case 'cm':
return 10.0;
case 'm':
return 1000.0;
case 'in':
return 25.4;
case 'ft':
return 12 * static::getUnitConversionFactor('in');
case 'yd':
return 3 * static::getUnitConversionFactor('ft');
case 'pt':
return (1 / 72) * static::getUnitConversionFactor('in');
default:
throw new \InvalidArgumentException('Unit: \'' . $unit . '\' is not supported');
return false;
}
}
/*
* I know it's gauche to return a shitty HTML string, but this is just a helper and since it will be the same every single time,

View File

@@ -126,12 +126,13 @@ class AccessoriesController extends Controller
public function getClone($accessoryId = null)
{
$this->authorize('create', Accesory::class);
$this->authorize('create', Accessory::class);
// Check if the asset exists
if (is_null($accessory_to_clone = Accessory::find($accessoryId))) {
// Redirect to the asset management page
return redirect()->route('accessory.index')->with('error', trans('admin/accessories/message.does_not_exist'));
return redirect()->route('accessories.index')
->with('error', trans('admin/accessories/message.does_not_exist', ['id' => $accessoryId]));
}
$accessory = clone $accessory_to_clone;

View File

@@ -161,22 +161,19 @@ class AccessoriesFilesController extends Controller
->header('Content-Type', 'text/plain');
} else {
// Display the file inline
if (request('inline') == 'true') {
$headers = [
'Content-Disposition' => 'inline',
];
return Storage::download($file, $log->filename, $headers);
}
// We have to override the URL stuff here, since local defaults in Laravel's Flysystem
// won't work, as they're not accessible via the web
if (config('filesystems.default') == 'local') { // TODO - is there any way to fix this at the StorageHelper layer?
return StorageHelper::downloader($file);
} else {
if ($download != 'true') {
\Log::debug('display the file');
if ($contents = file_get_contents(Storage::url($file))) { // TODO - this will fail on private S3 files or large public ones
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
}
return JsonResponse::create(['error' => 'Failed validation: '], 500);
}
return StorageHelper::downloader($file);
}
}
}

View File

@@ -69,7 +69,7 @@ class AcceptanceController extends Controller
}
if (! Company::isCurrentUserHasAccess($acceptance->checkoutable)) {
return redirect()->route('account.accept')->with('error', trans('general.insufficient_permissions'));
return redirect()->route('account.accept')->with('error', trans('general.error_user_company'));
}
return view('account/accept.create', compact('acceptance'));
@@ -245,6 +245,36 @@ class AcceptanceController extends Controller
$return_msg = trans('admin/users/message.accepted');
} else {
/**
* Check for the eula-pdfs directory
*/
if (! Storage::exists('private_uploads/eula-pdfs')) {
Storage::makeDirectory('private_uploads/eula-pdfs', 775);
}
if (Setting::getSettings()->require_accept_signature == '1') {
// Check if the signature directory exists, if not create it
if (!Storage::exists('private_uploads/signatures')) {
Storage::makeDirectory('private_uploads/signatures', 775);
}
// The item was accepted, check for a signature
if ($request->filled('signature_output')) {
$sig_filename = 'siglog-' . Str::uuid() . '-' . date('Y-m-d-his') . '.png';
$data_uri = $request->input('signature_output');
$encoded_image = explode(',', $data_uri);
$decoded_image = base64_decode($encoded_image[1]);
Storage::put('private_uploads/signatures/' . $sig_filename, (string)$decoded_image);
// No image data is present, kick them back.
// This mostly only applies to users on super-duper crapola browsers *cough* IE *cough*
} else {
return redirect()->back()->with('error', trans('general.shitty_browser'));
}
}
// Format the data to send the declined notification
$branding_settings = SettingsController::getPDFBranding();
@@ -281,11 +311,18 @@ class AcceptanceController extends Controller
'item_model' => $display_model,
'item_serial' => $item->serial,
'declined_date' => Carbon::parse($acceptance->declined_at)->format('Y-m-d'),
'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null,
'assigned_to' => $assigned_to,
'company_name' => $branding_settings->site_name,
'date_settings' => $branding_settings->date_display_format,
];
if ($pdf_view_route!='') {
\Log::debug($pdf_filename.' is the filename, and the route was specified.');
$pdf = Pdf::loadView($pdf_view_route, $data);
Storage::put('private_uploads/eula-pdfs/' .$pdf_filename, $pdf->output());
}
$acceptance->decline($sig_filename);
$acceptance->notify(new AcceptanceAssetDeclinedNotification($data));
event(new CheckoutDeclined($acceptance));

View File

@@ -331,7 +331,7 @@ class AccessoriesController extends Controller
$accessory = Accessory::find($accessory_user->accessory_id);
$this->authorize('checkin', $accessory);
$logaction = $accessory->logCheckin(User::find($accessory_user->user_id), $request->input('note'));
$logaction = $accessory->logCheckin(User::find($accessory_user->assigned_to), $request->input('note'));
// Was the accessory updated?
if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) {

View File

@@ -38,6 +38,7 @@ class AssetModelsController extends Controller
'image',
'name',
'model_number',
'min_amt',
'eol',
'notes',
'created_at',
@@ -52,6 +53,7 @@ class AssetModelsController extends Controller
'models.image',
'models.name',
'model_number',
'min_amt',
'eol',
'requestable',
'models.notes',
@@ -63,7 +65,7 @@ class AssetModelsController extends Controller
'models.deleted_at',
'models.updated_at',
])
->with('category', 'depreciation', 'manufacturer', 'fieldset.fields.defaultValues')
->with('category', 'depreciation', 'manufacturer')
->withCount('assets as assets_count');
if ($request->input('status')=='deleted') {

View File

@@ -110,12 +110,12 @@ class AssetsController extends Controller
$filter = json_decode($request->input('filter'), true);
}
$all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load
$all_custom_fields = CustomField::where('type', Asset::class); //used as a 'cache' of custom fields throughout this page load
foreach ($all_custom_fields as $field) {
$allowed_columns[] = $field->db_column_name();
}
$assets = Company::scopeCompanyables(Asset::select('assets.*'), 'company_id', 'assets')
$assets = Asset::select('assets.*')
->with('location', 'assetstatus', 'company', 'defaultLoc','assignedTo',
'model.category', 'model.manufacturer', 'model.fieldset','supplier'); //it might be tempting to add 'assetlog' here, but don't. It blows up update-heavy users.
@@ -125,6 +125,8 @@ class AssetsController extends Controller
$assets->InModelList($non_deprecable_models->toArray());
}
// These are used by the API to query against specific ID numbers.
// They are also used by the individual searches on detail pages like
// locations, etc.
@@ -136,6 +138,101 @@ class AssetsController extends Controller
}
}
if ((! is_null($filter)) && (count($filter)) > 0) {
$assets->ByFilter($filter);
} elseif ($request->filled('search')) {
$assets->TextSearch($request->input('search'));
}
// This is used by the audit reporting routes
if (Gate::allows('audit', Asset::class)) {
switch ($audit) {
case 'due':
$assets->DueOrOverdueForAudit($settings);
break;
case 'overdue':
$assets->overdueForAudit($settings);
break;
}
}
// This is used by the sidenav, mostly
// We switched from using query scopes here because of a Laravel bug
// related to fulltext searches on complex queries.
// I am sad. :(
switch ($request->input('status')) {
case 'Deleted':
$assets->onlyTrashed();
break;
case 'Pending':
$assets->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id')
->where('status_alias.deployable', '=', 0)
->where('status_alias.pending', '=', 1)
->where('status_alias.archived', '=', 0);
});
break;
case 'RTD':
$assets->whereNull('assets.assigned_to')
->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id')
->where('status_alias.deployable', '=', 1)
->where('status_alias.pending', '=', 0)
->where('status_alias.archived', '=', 0);
});
break;
case 'Undeployable':
$assets->Undeployable();
break;
case 'Archived':
$assets->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id')
->where('status_alias.deployable', '=', 0)
->where('status_alias.pending', '=', 0)
->where('status_alias.archived', '=', 1);
});
break;
case 'Requestable':
$assets->where('assets.requestable', '=', 1)
->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id')
->where('status_alias.deployable', '=', 1)
->where('status_alias.pending', '=', 0)
->where('status_alias.archived', '=', 0);
});
break;
case 'Deployed':
// more sad, horrible workarounds for laravel bugs when doing full text searches
$assets->whereNotNull('assets.assigned_to');
break;
case 'byod':
// This is kind of redundant, since we already check for byod=1 above, but this keeps the
// sidebar nav links a little less chaotic
$assets->where('assets.byod', '=', '1');
break;
default:
if ((! $request->filled('status_id')) && ($settings->show_archived_in_list != '1')) {
// terrible workaround for complex-query Laravel bug in fulltext
$assets->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id')
->where('status_alias.archived', '=', 0);
});
// If there is a status ID, don't take show_archived_in_list into consideration
} else {
$assets->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id');
});
}
}
// Leave these under the TextSearch scope, else the fuzziness will override the specific ID (status ID, etc) requested
if ($request->filled('status_id')) {
$assets->where('assets.status_id', '=', $request->input('status_id'));
}
@@ -197,110 +294,10 @@ class AssetsController extends Controller
$assets->where('assets.byod', '=', $request->input('byod'));
}
$request->filled('order_number') ? $assets = $assets->where('assets.order_number', '=', e($request->get('order_number'))) : '';
// Make sure the offset and limit are actually integers and do not exceed system limits
$offset = ($request->input('offset') > $assets->count()) ? $assets->count() : abs($request->input('offset'));
$limit = app('api_limit_value');
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
// This is used by the audit reporting routes
if (Gate::allows('audit', Asset::class)) {
switch ($audit) {
case 'due':
$assets->DueOrOverdueForAudit($settings);
break;
case 'overdue':
$assets->overdueForAudit($settings);
break;
}
if ($request->filled('order_number')) {
$assets->where('assets.order_number', '=', $request->get('order_number'));
}
// This is used by the sidenav, mostly
// We switched from using query scopes here because of a Laravel bug
// related to fulltext searches on complex queries.
// I am sad. :(
switch ($request->input('status')) {
case 'Deleted':
$assets->onlyTrashed();
break;
case 'Pending':
$assets->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id')
->where('status_alias.deployable', '=', 0)
->where('status_alias.pending', '=', 1)
->where('status_alias.archived', '=', 0);
});
break;
case 'RTD':
$assets->whereNull('assets.assigned_to')
->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id')
->where('status_alias.deployable', '=', 1)
->where('status_alias.pending', '=', 0)
->where('status_alias.archived', '=', 0);
});
break;
case 'Undeployable':
$assets->Undeployable();
break;
case 'Archived':
$assets->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id')
->where('status_alias.deployable', '=', 0)
->where('status_alias.pending', '=', 0)
->where('status_alias.archived', '=', 1);
});
break;
case 'Requestable':
$assets->where('assets.requestable', '=', 1)
->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id')
->where('status_alias.deployable', '=', 1)
->where('status_alias.pending', '=', 0)
->where('status_alias.archived', '=', 0);
});
break;
case 'Deployed':
// more sad, horrible workarounds for laravel bugs when doing full text searches
$assets->where('assets.assigned_to', '>', '0');
break;
case 'byod':
// This is kind of redundant, since we already check for byod=1 above, but this keeps the
// sidebar nav links a little less chaotic
$assets->where('assets.byod', '=', '1');
break;
default:
if ((! $request->filled('status_id')) && ($settings->show_archived_in_list != '1')) {
// terrible workaround for complex-query Laravel bug in fulltext
$assets->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id')
->where('status_alias.archived', '=', 0);
});
// If there is a status ID, don't take show_archived_in_list into consideration
} else {
$assets->join('status_labels AS status_alias', function ($join) {
$join->on('status_alias.id', '=', 'assets.status_id');
});
}
}
if ((! is_null($filter)) && (count($filter)) > 0) {
$assets->ByFilter($filter);
} elseif ($request->filled('search')) {
$assets->TextSearch($request->input('search'));
}
// This is kinda gross, but we need to do this because the Bootstrap Tables
// API passes custom field ordering as custom_fields.fieldname, and we have to strip
// that out to let the default sorter below order them correctly on the assets table.
@@ -310,7 +307,8 @@ class AssetsController extends Controller
// in the allowed_columns array)
$column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'assets.created_at';
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
switch ($sort_override) {
case 'model':
$assets->OrderModels($order);
@@ -347,6 +345,10 @@ class AssetsController extends Controller
}
// Make sure the offset and limit are actually integers and do not exceed system limits
$offset = ($request->input('offset') > $assets->count()) ? $assets->count() : abs($request->input('offset'));
$limit = app('api_limit_value');
$total = $assets->count();
$assets = $assets->skip($offset)->take($limit)->get();
@@ -477,7 +479,7 @@ class AssetsController extends Controller
public function selectlist(Request $request)
{
$assets = Company::scopeCompanyables(Asset::select([
$assets = Asset::select([
'assets.id',
'assets.name',
'assets.asset_tag',
@@ -485,7 +487,7 @@ class AssetsController extends Controller
'assets.assigned_to',
'assets.assigned_type',
'assets.status_id',
])->with('model', 'assetstatus', 'assignedTo')->NotArchived(), 'company_id', 'assets');
])->with('model', 'assetstatus', 'assignedTo')->NotArchived();
if ($request->filled('assetStatusType') && $request->input('assetStatusType') === 'RTD') {
$assets = $assets->RTD();
@@ -543,7 +545,8 @@ class AssetsController extends Controller
$asset->model_id = $request->get('model_id');
$asset->order_number = $request->get('order_number');
$asset->notes = $request->get('notes');
$asset->asset_tag = $request->get('asset_tag', Asset::autoincrement_asset());
$asset->asset_tag = $request->get('asset_tag', Asset::autoincrement_asset()); //yup, problem :/
// NO IT IS NOT!!! This is never firing; we SHOW the asset_tag you're going to get, so it *will* be filled in!
$asset->user_id = Auth::id();
$asset->archived = '0';
$asset->physical = '1';
@@ -570,42 +573,8 @@ class AssetsController extends Controller
$asset = $request->handleImages($asset);
// Update custom fields in the database.
// Validation for these fields is handled through the AssetRequest form request
$model = AssetModel::find($request->get('model_id'));
$asset->customFill($request, Auth::user(), true);
if (($model) && ($model->fieldset)) {
foreach ($model->fieldset->fields as $field) {
// Set the field value based on what was sent in the request
$field_val = $request->input($field->db_column, null);
// If input value is null, use custom field's default value
if ($field_val == null) {
\Log::debug('Field value for '.$field->db_column.' is null');
$field_val = $field->defaultValue($request->get('model_id'));
\Log::debug('Use the default fieldset value of '.$field->defaultValue($request->get('model_id')));
}
// if the field is set to encrypted, make sure we encrypt the value
if ($field->field_encrypted == '1') {
\Log::debug('This model field is encrypted in this fieldset.');
if (Gate::allows('admin')) {
// If input value is null, use custom field's default value
if (($field_val == null) && ($request->has('model_id') != '')) {
$field_val = \Crypt::encrypt($field->defaultValue($request->get('model_id')));
} else {
$field_val = \Crypt::encrypt($request->input($field->db_column));
}
}
}
$asset->{$field->db_column} = $field_val;
}
}
if ($asset->save()) {
if ($request->get('assigned_user')) {
@@ -665,21 +634,7 @@ class AssetsController extends Controller
$asset = $request->handleImages($asset);
// Update custom fields
if (($model = AssetModel::find($asset->model_id)) && (isset($model->fieldset))) {
foreach ($model->fieldset->fields as $field) {
if ($request->has($field->db_column)) {
if ($field->field_encrypted == '1') {
if (Gate::allows('admin')) {
$asset->{$field->db_column} = \Crypt::encrypt($request->input($field->db_column));
}
} else {
$asset->{$field->db_column} = $request->input($field->db_column);
}
}
}
}
$asset->customFill($request,Auth::user());
if ($asset->save()) {
if (($request->filled('assigned_user')) && ($target = User::find($request->get('assigned_user')))) {
@@ -902,6 +857,7 @@ class AssetsController extends Controller
$asset->expected_checkin = null;
$asset->last_checkout = null;
$asset->last_checkin = now();
$asset->assigned_to = null;
$asset->assignedTo()->disassociate($asset);
$asset->accepted = null;
@@ -921,10 +877,14 @@ class AssetsController extends Controller
}
$checkin_at = $request->filled('checkin_at') ? $request->input('checkin_at').' '. date('H:i:s') : date('Y-m-d H:i:s');
$originalValues = $asset->getRawOriginal();
if (($request->filled('checkin_at')) && ($request->get('checkin_at') != date('Y-m-d'))) {
$originalValues['action_date'] = $checkin_at;
}
if ($asset->save()) {
event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'), $checkin_at));
event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'), $checkin_at, $originalValues));
return response()->json(Helper::formatStandardApiResponse('success', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkin.success')));
}
@@ -1030,9 +990,10 @@ class AssetsController extends Controller
{
$this->authorize('viewRequestable', Asset::class);
$assets = Company::scopeCompanyables(Asset::select('assets.*'), 'company_id', 'assets')
$assets = Asset::select('assets.*')
->with('location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo',
'model.category', 'model.manufacturer', 'model.fieldset', 'supplier')->requestableAssets();
'model.category', 'model.manufacturer', 'model.fieldset', 'supplier')
->requestableAssets();
$offset = request('offset', 0);
$limit = $request->input('limit', 50);

View File

@@ -27,6 +27,9 @@ class CompaniesController extends Controller
$allowed_columns = [
'id',
'name',
'phone',
'fax',
'email',
'created_at',
'updated_at',
'users_count',
@@ -47,6 +50,10 @@ class CompaniesController extends Controller
$companies->where('name', '=', $request->input('name'));
}
if ($request->filled('email')) {
$companies->where('email', '=', $request->input('email'));
}
// Make sure the offset and limit are actually integers and do not exceed system limits
$offset = ($request->input('offset') > $companies->count()) ? $companies->count() : abs($request->input('offset'));
@@ -166,6 +173,7 @@ class CompaniesController extends Controller
$companies = Company::select([
'companies.id',
'companies.name',
'companies.email',
'companies.image',
]);

View File

@@ -13,6 +13,7 @@ use App\Events\CheckoutableCheckedIn;
use App\Events\ComponentCheckedIn;
use App\Models\Asset;
use Illuminate\Support\Facades\Validator;
use Illuminate\Database\Query\Builder;
class ComponentsController extends Controller
{
@@ -44,9 +45,8 @@ class ComponentsController extends Controller
'notes',
];
$components = Company::scopeCompanyables(Component::select('components.*')
->with('company', 'location', 'category', 'assets', 'supplier'));
$components = Component::select('components.*')
->with('company', 'location', 'category', 'assets', 'supplier');
if ($request->filled('search')) {
$components = $components->TextSearch($request->input('search'));
@@ -204,12 +204,29 @@ class ComponentsController extends Controller
$this->authorize('view', \App\Models\Asset::class);
$component = Component::findOrFail($id);
$assets = $component->assets();
$offset = request('offset', 0);
$limit = $request->input('limit', 50);
$total = $assets->count();
$assets = $assets->skip($offset)->take($limit)->get();
if ($request->filled('search')) {
$assets = $component->assets()
->where(function ($query) use ($request) {
$search_str = '%' . $request->input('search') . '%';
$query->where('name', 'like', $search_str)
->orWhereIn('model_id', function (Builder $query) use ($request) {
$search_str = '%' . $request->input('search') . '%';
$query->selectRaw('id')->from('models')->where('name', 'like', $search_str);
})
->orWhere('asset_tag', 'like', $search_str);
})
->get();
$total = $assets->count();
} else {
$assets = $component->assets();
$total = $assets->count();
$assets = $assets->skip($offset)->take($limit)->get();
}
return (new ComponentsTransformer)->transformCheckedoutComponents($assets, $total);
}
@@ -236,7 +253,7 @@ class ComponentsController extends Controller
$this->authorize('checkout', $component);
$validator = Validator::make($request->all(), [
'asset_id' => 'required|exists:assets,id',
'assigned_to' => 'required|exists:assets,id',
'assigned_qty' => "required|numeric|min:1|digits_between:1,".$component->numRemaining(),
]);

View File

@@ -45,11 +45,8 @@ class ConsumablesController extends Controller
'notes',
];
$consumables = Company::scopeCompanyables(
Consumable::select('consumables.*')
->with('company', 'location', 'category', 'users', 'manufacturer')
);
$consumables = Consumable::select('consumables.*')
->with('company', 'location', 'category', 'users', 'manufacturer');
if ($request->filled('search')) {
$consumables = $consumables->TextSearch(e($request->input('search')));

View File

@@ -35,7 +35,7 @@ class CustomFieldsetsController extends Controller
public function index()
{
$this->authorize('index', CustomField::class);
$fieldsets = CustomFieldset::withCount('fields as fields_count', 'models as models_count')->get();
$fieldsets = CustomFieldset::withCount('fields as fields_count')->get();
return (new CustomFieldsetsTransformer)->transformCustomFieldsets($fieldsets, $fieldsets->count());
}
@@ -125,7 +125,7 @@ class CustomFieldsetsController extends Controller
$this->authorize('delete', CustomField::class);
$fieldset = CustomFieldset::findOrFail($id);
$modelsCount = $fieldset->models->count();
$modelsCount = $fieldset->customizables()->count();
$fieldsCount = $fieldset->fields->count();
if (($modelsCount > 0) || ($fieldsCount > 0)) {

View File

@@ -30,6 +30,8 @@ class DepartmentsController extends Controller
$departments = Company::scopeCompanyables(Department::select(
'departments.id',
'departments.name',
'departments.phone',
'departments.fax',
'departments.location_id',
'departments.company_id',
'departments.manager_id',

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Http\Controllers\Api;
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Http\Transformers\LabelsTransformer;
use App\Models\Labels\Label;
use Illuminate\Http\Request;
use Illuminate\Support\ItemNotFoundException;
use Auth;
class LabelsController extends Controller
{
/**
* Returns JSON listing of all labels.
*
* @author Grant Le Roux <grant.leroux+snipe-it@gmail.com>
* @return JsonResponse
*/
public function index(Request $request)
{
$this->authorize('view', Label::class);
$labels = Label::find();
if ($request->filled('search')) {
$search = $request->get('search');
$labels = $labels->filter(function ($label, $index) use ($search) {
return stripos($label->getName(), $search) !== false;
});
}
$total = $labels->count();
$offset = $request->get('offset', 0);
$offset = ($offset > $total) ? $total : $offset;
$maxLimit = config('app.max_results');
$limit = $request->get('limit', $maxLimit);
$limit = ($limit > $maxLimit) ? $maxLimit : $limit;
$labels = $labels->skip($offset)->take($limit);
return (new LabelsTransformer)->transformLabels($labels, $total, $request);
}
/**
* Returns JSON with information about a label for detail view.
*
* @author Grant Le Roux <grant.leroux+snipe-it@gmail.com>
* @param string $labelName
* @return JsonResponse
*/
public function show(string $labelName)
{
$labelName = str_replace('/', '\\', $labelName);
try {
$label = Label::find($labelName);
} catch(ItemNotFoundException $e) {
return response()
->json(
Helper::formatStandardApiResponse('error', null, trans('admin/labels/message.does_not_exist')),
404
);
}
$this->authorize('view', $label);
return (new LabelsTransformer)->transformLabel($label);
}
}

View File

@@ -42,6 +42,11 @@ class LicenseSeatsController extends Controller
// Make sure the offset and limit are actually integers and do not exceed system limits
$offset = ($request->input('offset') > $seats->count()) ? $seats->count() : abs($request->input('offset'));
if ($offset >= $total ){
$offset = 0;
}
$limit = app('api_limit_value');
$seats = $seats->skip($offset)->take($limit)->get();

View File

@@ -26,8 +26,8 @@ class LicensesController extends Controller
public function index(Request $request)
{
$this->authorize('view', License::class);
$licenses = Company::scopeCompanyables(License::with('company', 'manufacturer', 'supplier','category')->withCount('freeSeats as free_seats_count'));
$licenses = License::with('company', 'manufacturer', 'supplier','category')->withCount('freeSeats as free_seats_count');
if ($request->filled('company_id')) {
$licenses->where('company_id', '=', $request->input('company_id'));

View File

@@ -37,6 +37,8 @@ class LocationsController extends Controller
'locations.city',
'locations.state',
'locations.zip',
'locations.phone',
'locations.fax',
'locations.country',
'locations.parent_id',
'locations.manager_id',
@@ -251,8 +253,12 @@ class LocationsController extends Controller
*/
public function selectlist(Request $request)
{
$this->authorize('view.selectlists');
// If a user is in the process of editing their profile, as determined by the referrer,
// then we check that they have permission to edit their own location.
// Otherwise, we do our normal check that they can view select lists.
$request->headers->get('referer') === route('profile')
? $this->authorize('self.edit_location')
: $this->authorize('view.selectlists');
$locations = Location::select([
'locations.id',

View File

@@ -41,7 +41,7 @@ class SuppliersController extends Controller
];
$suppliers = Supplier::select(
['id', 'name', 'address', 'address2', 'city', 'state', 'country', 'fax', 'phone', 'email', 'contact', 'created_at', 'updated_at', 'deleted_at', 'image', 'notes'])
['id', 'name', 'address', 'address2', 'city', 'state', 'country', 'fax', 'phone', 'email', 'contact', 'created_at', 'updated_at', 'deleted_at', 'image', 'notes', 'url'])
->withCount('assets as assets_count')
->withCount('licenses as licenses_count')
->withCount('accessories as accessories_count')

View File

@@ -13,6 +13,7 @@ use App\Http\Transformers\SelectlistTransformer;
use App\Http\Transformers\UsersTransformer;
use App\Models\Asset;
use App\Models\Company;
use App\Models\CustomField;
use App\Models\License;
use App\Models\User;
use App\Notifications\CurrentInventory;
@@ -36,7 +37,7 @@ class UsersController extends Controller
{
$this->authorize('view', User::class);
$users = User::select([
$allowed_columns = [
'users.activated',
'users.created_by',
'users.address',
@@ -73,16 +74,14 @@ class UsersController extends Controller
'users.vip',
'users.autoassign_licenses',
])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy',)
->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count');
$users = Company::scopeCompanyables($users);
];
if (($request->filled('deleted')) && ($request->input('deleted') == 'true')) {
$users = $users->onlyTrashed();
} elseif (($request->filled('all')) && ($request->input('all') == 'true')) {
$users = $users->withTrashed();
foreach(CustomField::where('type', User::class)->get() as $field) {
$allowed_columns[] = $field->db_column_name();
}
$users = User::select()->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy',)
->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count');
if ($request->filled('activated')) {
$users = $users->where('users.activated', '=', $request->input('activated'));
@@ -272,6 +271,14 @@ class UsersController extends Controller
break;
}
if (($request->filled('deleted')) && ($request->input('deleted') == 'true')) {
$users = $users->onlyTrashed();
} elseif (($request->filled('all')) && ($request->input('all') == 'true')) {
$users = $users->withTrashed();
}
$users = Company::scopeCompanyables($users);
$total = $users->count();
$users = $users->skip($offset)->take($limit)->get();
@@ -366,7 +373,9 @@ class UsersController extends Controller
$user->password = bcrypt($request->get('password', $tmp_pass));
app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar');
$user->customFill($request,Auth::user());
if ($user->save()) {
if ($request->filled('groups')) {
$user->groups()->sync($request->input('groups'));
@@ -457,7 +466,9 @@ class UsersController extends Controller
app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar');
$user->customFill($request,Auth::user());
if ($user->save()) {
// Sync group memberships:

View File

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Helpers\Helper;
use App\Http\Requests\ImageUploadRequest;
use App\Models\AssetModel;
use App\Models\DefaultValuesForCustomFields;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\View;
@@ -76,6 +77,7 @@ class AssetModelsController extends Controller
$model->depreciation_id = $request->input('depreciation_id');
$model->name = $request->input('name');
$model->model_number = $request->input('model_number');
$model->min_amt = $request->input('min_amt');
$model->manufacturer_id = $request->input('manufacturer_id');
$model->category_id = $request->input('category_id');
$model->notes = $request->input('notes');
@@ -153,12 +155,13 @@ class AssetModelsController extends Controller
$model->eol = $request->input('eol');
$model->name = $request->input('name');
$model->model_number = $request->input('model_number');
$model->min_amt = $request->input('min_amt');
$model->manufacturer_id = $request->input('manufacturer_id');
$model->category_id = $request->input('category_id');
$model->notes = $request->input('notes');
$model->requestable = $request->input('requestable', '0');
$this->removeCustomFieldsDefaultValues($model);
DefaultValuesForCustomFields::forPivot($model, Asset::class)->delete();
if ($request->input('fieldset_id') == '') {
$model->fieldset_id = null;
@@ -286,6 +289,7 @@ class AssetModelsController extends Controller
return view('models/edit')
->with('depreciation_list', Helper::depreciationList())
->with('item', $model)
->with('model_id', $model_to_clone->id)
->with('clone_model', $model_to_clone);
}
@@ -448,7 +452,7 @@ class AssetModelsController extends Controller
}
/**
* Adds default values to a model (as long as they are truthy)
* Adds default values to a model (as long as they are truthy) (does this mean I cannot set a default value of 0?)
*
* @param AssetModel $model
* @param array $defaultValues
@@ -483,22 +487,12 @@ class AssetModelsController extends Controller
}
foreach ($defaultValues as $customFieldId => $defaultValue) {
if(is_array($defaultValue)){
$model->defaultValues()->attach($customFieldId, ['default_value' => implode(', ', $defaultValue)]);
}elseif ($defaultValue) {
$model->defaultValues()->attach($customFieldId, ['default_value' => $defaultValue]);
if(is_array($defaultValue)) {
$defaultValue = implode(', ', $defaultValue);
}
DefaultValuesForCustomFields::updateOrCreate(['custom_field_id' => $customFieldId,'item_pivot_id' => $model->id], ['default_value' => $defaultValue]);
}
return true;
}
/**
* Removes all default values
*
* @return void
*/
private function removeCustomFieldsDefaultValues(AssetModel $model)
{
$model->defaultValues()->detach();
}
}

View File

@@ -78,7 +78,7 @@ class AssetModelsFilesController extends Controller
* @return View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function show($modelId = null, $fileId = null, $download = true)
public function show($modelId = null, $fileId = null)
{
$model = AssetModel::find($modelId);
// the asset is valid
@@ -99,12 +99,13 @@ class AssetModelsFilesController extends Controller
->header('Content-Type', 'text/plain');
}
if ($download != 'true') {
if ($contents = file_get_contents(Storage::url($file))) {
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
}
if (request('inline') == 'true') {
return JsonResponse::create(['error' => 'Failed validation: '], 500);
$headers = [
'Content-Disposition' => 'inline',
];
return Storage::download($file, $log->filename, $headers);
}
return StorageHelper::downloader($file);

View File

@@ -68,6 +68,7 @@ class AssetCheckinController extends Controller
$asset->expected_checkin = null;
$asset->last_checkout = null;
$asset->last_checkin = now();
$asset->assigned_to = null;
$asset->assignedTo()->disassociate($asset);
$asset->assigned_type = null;
@@ -94,18 +95,25 @@ class AssetCheckinController extends Controller
\Log::debug('Manually override the location IDs');
\Log::debug('Original Location ID: '.$asset->location_id);
$asset->location_id = '';
\Log::debug('New RTD Location ID: '.$asset->location_id);
\Log::debug('New Location ID: '.$asset->location_id);
}
$asset->location_id = $asset->rtd_location_id;
if ($request->filled('location_id')) {
\Log::debug('NEW Location ID: '.$request->get('location_id'));
$asset->location_id = e($request->get('location_id'));
$asset->location_id = $request->get('location_id');
if ($request->get('update_default_location') == 0){
$asset->rtd_location_id = $request->get('location_id');
}
}
$originalValues = $asset->getRawOriginal();
$checkin_at = date('Y-m-d H:i:s');
if (($request->filled('checkin_at')) && ($request->get('checkin_at') != date('Y-m-d'))) {
$originalValues['action_date'] = $checkin_at;
$checkin_at = $request->get('checkin_at');
}
@@ -128,7 +136,7 @@ class AssetCheckinController extends Controller
// Was the asset updated?
if ($asset->save()) {
event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'), $checkin_at));
event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'), $checkin_at, $originalValues));
if ((isset($user)) && ($backto == 'user')) {
return redirect()->route('users.show', $user->id)->with('success', trans('admin/hardware/message.checkin.success'));

View File

@@ -89,6 +89,14 @@ class AssetCheckoutController extends Controller
}
}
$settings = \App\Models\Setting::getSettings();
if ($settings->full_multiple_companies_support){
if ($target->company_id != $asset->company_id){
return redirect()->to("hardware/$assetId/checkout")->with('error', trans('general.error_user_company'));
}
}
if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e($request->get('note')), $request->get('name'))) {
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkout.success'));
}

View File

@@ -79,7 +79,7 @@ class AssetFilesController extends Controller
* @return View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function show($assetId = null, $fileId = null, $download = true)
public function show($assetId = null, $fileId = null)
{
$asset = Asset::find($assetId);
// the asset is valid
@@ -103,12 +103,13 @@ class AssetFilesController extends Controller
->header('Content-Type', 'text/plain');
}
if ($download != 'true') {
if ($contents = file_get_contents(Storage::url($file))) {
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
}
if (request('inline') == 'true') {
return JsonResponse::create(['error' => 'Failed validation: '], 500);
$headers = [
'Content-Disposition' => 'inline',
];
return Storage::download($file, $log->filename, $headers);
}
return StorageHelper::downloader($file);

View File

@@ -14,6 +14,7 @@ use App\Models\Location;
use App\Models\Setting;
use App\Models\Statuslabel;
use App\Models\User;
use App\View\Label;
use Auth;
use Carbon\Carbon;
use DB;
@@ -163,29 +164,7 @@ class AssetsController extends Controller
$asset = $request->handleImages($asset);
}
// Update custom fields in the database.
// Validation for these fields is handled through the AssetRequest form request
$model = AssetModel::find($request->get('model_id'));
if (($model) && ($model->fieldset)) {
foreach ($model->fieldset->fields as $field) {
if ($field->field_encrypted == '1') {
if (Gate::allows('admin')) {
if (is_array($request->input($field->db_column))) {
$asset->{$field->db_column} = \Crypt::encrypt(implode(', ', $request->input($field->db_column)));
} else {
$asset->{$field->db_column} = \Crypt::encrypt($request->input($field->db_column));
}
}
} else {
if (is_array($request->input($field->db_column))) {
$asset->{$field->db_column} = implode(', ', $request->input($field->db_column));
} else {
$asset->{$field->db_column} = $request->input($field->db_column);
}
}
}
}
$asset->customFill($request, Auth::user()); // Update custom fields in the database.
// Validate the asset before saving
if ($asset->isValid() && $asset->save()) {
@@ -453,11 +432,12 @@ class AssetsController extends Controller
* @since [v3.0]
* @return Redirect
*/
public function getAssetByTag(Request $request)
public function getAssetByTag(Request $request, $tag=null)
{
$tag = $tag ? $tag : $request->get('assetTag');
$topsearch = ($request->get('topsearch') == 'true');
if (! $asset = Asset::where('asset_tag', '=', $request->get('assetTag'))->first()) {
if (! $asset = Asset::where('asset_tag', '=', $tag)->first()) {
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
}
$this->authorize('view', $asset);
@@ -554,9 +534,11 @@ class AssetsController extends Controller
$asset = Asset::find($assetId);
$this->authorize('view', $asset);
return view('hardware/labels')
->with('assets', Asset::find($asset))
return (new Label())
->with('assets', collect([ $asset ]))
->with('settings', Setting::getSettings())
->with('template', request()->get('template'))
->with('offset', request()->get('offset'))
->with('bulkedit', false)
->with('count', 0);
}
@@ -774,7 +756,7 @@ class AssetsController extends Controller
}
/**
* Retore a deleted asset.
* Restore a deleted asset.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $assetId

View File

@@ -8,11 +8,13 @@ use App\Http\Controllers\CheckInOutRequest;
use App\Http\Controllers\Controller;
use App\Models\Asset;
use App\Models\Setting;
use App\View\Label;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
use App\Http\Requests\AssetCheckoutRequest;
use App\Models\CustomField;
class BulkAssetsController extends Controller
{
@@ -30,7 +32,7 @@ class BulkAssetsController extends Controller
public function edit(Request $request)
{
$this->authorize('view', Asset::class);
if (! $request->filled('ids')) {
return redirect()->back()->with('error', trans('admin/hardware/message.update.no_assets_selected'));
}
@@ -40,13 +42,30 @@ class BulkAssetsController extends Controller
session(['bulk_back_url' => $bulk_back_url]);
$asset_ids = array_values(array_unique($request->input('ids')));
//custom fields logic
$asset_custom_field = Asset::with(['model.fieldset.fields', 'model'])->whereIn('id', $asset_ids)->whereHas('model', function ($query) {
return $query->where('fieldset_id', '!=', null);
})->get();
$models = $asset_custom_field->unique('model_id');
$modelNames = [];
foreach($models as $model) {
$modelNames[] = $model->model->name;
}
if ($request->filled('bulk_actions')) {
switch ($request->input('bulk_actions')) {
case 'labels':
$this->authorize('view', Asset::class);
return view('hardware/labels')
->with('assets', Asset::find($asset_ids))
$assets_found = Asset::find($asset_ids);
if ($assets_found->isEmpty()){
return redirect()->back();
}
return (new Label)
->with('assets', $assets_found)
->with('settings', Setting::getSettings())
->with('bulkedit', true)
->with('count', 0);
@@ -73,7 +92,9 @@ class BulkAssetsController extends Controller
$this->authorize('update', Asset::class);
return view('hardware/bulk')
->with('assets', $asset_ids)
->with('statuslabel_list', Helper::statusLabelList());
->with('statuslabel_list', Helper::statusLabelList())
->with('models', $models->pluck(['model']))
->with('modelNames', $modelNames);
}
}
@@ -91,6 +112,7 @@ class BulkAssetsController extends Controller
public function update(Request $request)
{
$this->authorize('update', Asset::class);
$error_bag = [];
// Get the back url from the session and then destroy the session
$bulk_back_url = route('hardware.index');
@@ -99,12 +121,21 @@ class BulkAssetsController extends Controller
}
if (! $request->filled('ids') || count($request->input('ids')) <= 0) {
$custom_field_columns = CustomField::all()->pluck('db_column')->toArray();
if(Session::exists('ids')) {
$assets = Session::get('ids');
} elseif (! $request->filled('ids') || count($request->input('ids')) <= 0) {
return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected'));
}
$assets = array_keys($request->input('ids'));
if ($request->anyFilled($custom_field_columns)) {
$custom_fields_present = true;
} else {
$custom_fields_present = false;
}
if (($request->filled('purchase_date'))
|| ($request->filled('expected_checkin'))
|| ($request->filled('purchase_cost'))
@@ -120,6 +151,7 @@ class BulkAssetsController extends Controller
|| ($request->filled('null_purchase_date'))
|| ($request->filled('null_expected_checkin_date'))
|| ($request->filled('null_next_audit_date'))
|| ($request->anyFilled($custom_field_columns))
) {
foreach ($assets as $assetId) {
@@ -135,6 +167,9 @@ class BulkAssetsController extends Controller
->conditionallyAddItem('supplier_id')
->conditionallyAddItem('warranty_months')
->conditionallyAddItem('next_audit_date');
foreach ($custom_field_columns as $key => $custom_field_column) {
$this->conditionallyAddItem($custom_field_column);
}
if ($request->input('null_purchase_date')=='1') {
$this->update_array['purchase_date'] = null;
@@ -167,11 +202,11 @@ class BulkAssetsController extends Controller
}
$changed = [];
$asset = Asset::where('id' ,$assetId)->get();
$assetCollection = Asset::where('id' ,$assetId)->get();
foreach ($this->update_array as $key => $value) {
if ($this->update_array[$key] != $asset->toArray()[0][$key]) {
$changed[$key]['old'] = $asset->toArray()[0][$key];
if ($this->update_array[$key] != $assetCollection->toArray()[0][$key]) {
$changed[$key]['old'] = $assetCollection->toArray()[0][$key];
$changed[$key]['new'] = $this->update_array[$key];
}
}
@@ -183,17 +218,47 @@ class BulkAssetsController extends Controller
$logAction->user_id = Auth::id();
$logAction->log_meta = json_encode($changed);
$logAction->logaction('update');
DB::table('assets')
->where('id', $assetId)
->update($this->update_array);
} // endforeach
if($custom_fields_present) {
$asset = Asset::find($assetId);
$assetCustomFields = $asset->model()->first()->fieldset;
if($assetCustomFields && $assetCustomFields->fields) {
foreach ($assetCustomFields->fields as $field) {
if (array_key_exists($field->db_column, $this->update_array)) {
$asset->{$field->db_column} = $this->update_array[$field->db_column];
$saved = $asset->save();
if(!$saved) {
$error_bag[] = $asset->getErrors();
}
continue;
} else {
$array = $this->update_array;
array_except($array, $field->db_column);
$asset->save($array);
}
if (!$asset->save()) {
$error_bag[] = $asset->getErrors();
}
}
}
} else {
Asset::find($assetId)->update($this->update_array);
}
}
if(!empty($error_bag)) {
$errors = [];
//find the customfield name from the name of the messagebag items
foreach ($error_bag as $key => $bag) {
foreach($bag->keys() as $key => $value) {
CustomField::where('db_column', $value)->get()->map(function($item) use (&$errors) {
$errors[] = $item->name;
});
}
}
return redirect($bulk_back_url)->with('bulk_errors', array_unique($errors));
}
return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success'));
}
// no values given, nothing to update
return redirect($bulk_back_url)->with('warning', trans('admin/hardware/message.update.nothing_updated'));
}

View File

@@ -60,6 +60,9 @@ final class CompaniesController extends Controller
$company = new Company;
$company->name = $request->input('name');
$company->phone = $request->input('phone');
$company->fax = $request->input('fax');
$company->email = $request->input('email');
$company = $request->handleImages($company);
@@ -111,6 +114,9 @@ final class CompaniesController extends Controller
$this->authorize('update', $company);
$company->name = $request->input('name');
$company->phone = $request->input('phone');
$company->fax = $request->input('fax');
$company->email = $request->input('email');
$company = $request->handleImages($company);
@@ -119,8 +125,7 @@ final class CompaniesController extends Controller
->with('success', trans('admin/companies/message.update.success'));
}
return redirect()->route('companies.edit', ['company' => $companyId])
->with('error', trans('admin/companies/message.update.error'));
return redirect()->back()->withInput()->withErrors($company->getErrors());
}
/**

View File

@@ -132,7 +132,7 @@ class ComponentsFilesController extends Controller
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function show($componentId = null, $fileId = null, $download = true)
public function show($componentId = null, $fileId = null)
{
\Log::debug('Private filesystem is: '.config('filesystems.default'));
$component = Component::find($componentId);
@@ -157,21 +157,17 @@ class ComponentsFilesController extends Controller
->header('Content-Type', 'text/plain');
} else {
// Display the file inline
if (request('inline') == 'true') {
$headers = [
'Content-Disposition' => 'inline',
];
return Storage::download($file, $log->filename, $headers);
}
if (config('filesystems.default') == 'local') { // TODO - is there any way to fix this at the StorageHelper layer?
return StorageHelper::downloader($file);
} else {
if ($download != 'true') {
\Log::debug('display the file');
if ($contents = file_get_contents(Storage::url($file))) { // TODO - this will fail on private S3 files or large public ones
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
}
return JsonResponse::create(['error' => 'Failed validation: '], 500);
}
return StorageHelper::downloader($file);
}
}
}
}

View File

@@ -131,7 +131,7 @@ class ConsumablesFilesController extends Controller
* @return \Symfony\Consumable\HttpFoundation\Response
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function show($consumableId = null, $fileId = null, $download = true)
public function show($consumableId = null, $fileId = null)
{
$consumable = Consumable::find($consumableId);
@@ -155,22 +155,19 @@ class ConsumablesFilesController extends Controller
->header('Content-Type', 'text/plain');
} else {
// Display the file inline
if (request('inline') == 'true') {
$headers = [
'Content-Disposition' => 'inline',
];
return Storage::download($file, $log->filename, $headers);
}
// We have to override the URL stuff here, since local defaults in Laravel's Flysystem
// won't work, as they're not accessible via the web
if (config('filesystems.default') == 'local') { // TODO - is there any way to fix this at the StorageHelper layer?
return StorageHelper::downloader($file);
} else {
if ($download != 'true') {
\Log::debug('display the file');
if ($contents = file_get_contents(Storage::url($file))) { // TODO - this will fail on private S3 files or large public ones
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
}
return JsonResponse::create(['error' => 'Failed validation: '], 500);
}
return StorageHelper::downloader($file);
}
}
}

View File

@@ -6,10 +6,12 @@ use App\Helpers\Helper;
use App\Http\Requests\CustomFieldRequest;
use App\Models\CustomField;
use App\Models\CustomFieldset;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Redirect;
/**
* This controller handles all actions related to Custom Asset Fields for
* the Snipe-IT Asset Management application.
@@ -21,6 +23,7 @@ use Redirect;
*/
class CustomFieldsController extends Controller
{
/**
* Returns a view with a listing of custom fields.
*
@@ -29,12 +32,16 @@ class CustomFieldsController extends Controller
* @return \Illuminate\Support\Facades\View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function index()
public function index(Request $request)
{
$this->authorize('view', CustomField::class);
if ( $request->input('tab') == 1 ) {
// Users section, make sure to auto-create the first fieldset if so
CustomFieldset::firstOrCreate(['type' => Helper::$itemtypes_having_custom_fields[1]], ['name' => 'default']);
}
$fieldsets = CustomFieldset::with('fields', 'models')->get();
$fields = CustomField::with('fieldset')->get();
$fieldsets = CustomFieldset::with('fields')->where("type", Helper::$itemtypes_having_custom_fields[$request->get('tab',0)])->get(); //cannot eager-load 'customizable' because it's not a relation
$fields = CustomField::with('fieldset')->where("type", Helper::$itemtypes_having_custom_fields[$request->get('tab',0)])->get();
return view('custom_fields.index')->with('custom_fieldsets', $fieldsets)->with('custom_fields', $fields);
}
@@ -67,7 +74,7 @@ class CustomFieldsController extends Controller
public function create(Request $request)
{
$this->authorize('create', CustomField::class);
$fieldsets = CustomFieldset::get();
$fieldsets = CustomFieldset::where('type', Helper::$itemtypes_having_custom_fields[$request->get('tab')])->get();
return view('custom_fields.fields.edit', [
'predefinedFormats' => Helper::predefined_formats(),
@@ -109,8 +116,11 @@ class CustomFieldsController extends Controller
"is_unique" => $request->get("is_unique", 0),
"display_in_user_view" => $display_in_user_view,
"auto_add_to_fieldsets" => $request->get("auto_add_to_fieldsets", 0),
"user_id" => Auth::id()
"show_in_listview" => $request->get("show_in_listview", 0),
"user_id" => Auth::id(),
]);
// not mass-assignable; must be manual
$field->type = Helper::$itemtypes_having_custom_fields[$request->get('tab')];
if ($request->filled('custom_format')) {
@@ -123,14 +133,17 @@ class CustomFieldsController extends Controller
// Sync fields with fieldsets
$fieldset_array = $request->input('associate_fieldsets');
if ($request->has('associate_fieldsets') && (is_array($fieldset_array))) {
if ($request->get('tab') == 1 ) {
$fieldset_array = [CustomFieldset::firstOrCreate(['type' => User::class],['name' => 'default'])->id => true];
}
if (($request->has('associate_fieldsets') || $request->get('tab') == 1) && (is_array($fieldset_array))) {
$field->fieldset()->sync(array_keys($fieldset_array));
} else {
$field->fieldset()->sync([]);
}
return redirect()->route('fields.index')->with('success', trans('admin/custom_fields/message.field.create.success'));
return redirect()->route('fields.index',['tab' => $request->get('tab',0)])->with('success', trans('admin/custom_fields/message.field.create.success'));
}
return redirect()->back()->with('selected_fieldsets', $request->input('associate_fieldsets'))->withInput()
@@ -183,12 +196,17 @@ class CustomFieldsController extends Controller
if ($field = CustomField::find($field_id)) {
$this->authorize('delete', $field);
if ($field->type == User::class) {
$field->fieldset()->detach(); // remove from 'default' group (and others, if they exist in the future!)
}
if (($field->fieldset) && ($field->fieldset->count() > 0)) {
return redirect()->back()->withErrors(['message' => 'Field is in-use']);
}
$type = $field->type;
$field->delete();
return redirect()->route("fields.index")
->with("success", trans('admin/custom_fields/message.field.delete.success'));
return redirect()->route('fields.index',['tab' => array_search($type, Helper::$itemtypes_having_custom_fields)])
->with('success', trans('admin/custom_fields/message.field.delete.success'));
}
return redirect()->back()->withErrors(['message' => 'Field does not exist']);
@@ -265,6 +283,7 @@ class CustomFieldsController extends Controller
$field->is_unique = $request->get("is_unique", 0);
$field->display_in_user_view = $display_in_user_view;
$field->auto_add_to_fieldsets = $request->get("auto_add_to_fieldsets", 0);
$field->show_in_listview = $request->get("show_in_listview", 0);
if ($request->get('format') == 'CUSTOM REGEX') {
$field->format = e($request->get('custom_format'));
@@ -287,7 +306,7 @@ class CustomFieldsController extends Controller
$field->fieldset()->sync([]);
}
return redirect()->route('fields.index')->with('success', trans('admin/custom_fields/message.field.update.success'));
return redirect()->route('fields.index',['tab' => $request->get('tab',0)])->with('success', trans('admin/custom_fields/message.field.update.success'));
}
return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.field.update.error'));

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Helpers\Helper;
use App\Models\AssetModel;
use App\Models\CustomField;
use App\Models\CustomFieldset;
@@ -38,7 +39,7 @@ class CustomFieldsetsController extends Controller
* @throws \Illuminate\Auth\Access\AuthorizationException
* @since [v1.8]
*/
public function show($id)
public function show( $id)
{
$cfset = CustomFieldset::with('fields')
->where('id', '=', $id)->orderBy('id', 'ASC')->first();
@@ -46,7 +47,7 @@ class CustomFieldsetsController extends Controller
$this->authorize('view', $cfset);
if ($cfset) {
$custom_fields_list = ['' => 'Add New Field to Fieldset'] + CustomField::pluck('name', 'id')->toArray();
$custom_fields_list = ['' => 'Add New Field to Fieldset'] + CustomField::where('type', $cfset->type)->pluck('name', 'id')->toArray();
$maxid = 0;
foreach ($cfset->fields as $field) {
@@ -94,8 +95,10 @@ class CustomFieldsetsController extends Controller
$this->authorize('create', CustomField::class);
$fieldset = new CustomFieldset([
'name' => e($request->get('name')),
'name' => $request->get('name'),
'user_id' => Auth::user()->id,
'type' => Helper::$itemtypes_having_custom_fields[$request->get('tab')]
// 'sub' =>
]);
$validator = Validator::make($request->all(), $fieldset->rules);

View File

@@ -170,6 +170,8 @@ class DepartmentsController extends Controller
$department->manager_id = ($request->filled('manager_id') ? $request->input('manager_id') : null);
$department->location_id = ($request->filled('location_id') ? $request->input('location_id') : null);
$department->company_id = ($request->filled('company_id') ? $request->input('company_id') : null);
$department->phone = $request->input('phone');
$department->fax = $request->input('fax');
$department = $request->handleImages($department);

View File

@@ -0,0 +1,77 @@
<?php
namespace App\Http\Controllers;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\Company;
use App\Models\Labels\Label;
use App\Models\Manufacturer;
use App\Models\Setting;
use App\Models\User;
use App\View\Label as LabelView;
use Illuminate\Support\Facades\Storage;
class LabelsController extends Controller
{
/**
* Returns the Label view with test data
*
* @author Grant Le Roux <grant.leroux+snipe-it@gmail.com>
* @param string $labelName
* @return \Illuminate\Contracts\View\View
*/
public function show(string $labelName)
{
$labelName = str_replace('/', '\\', $labelName);
$template = Label::find($labelName);
$exampleAsset = new Asset();
$exampleAsset->id = 999999;
$exampleAsset->name = 'JEN-867-5309';
$exampleAsset->asset_tag = 'TCA-00001';
$exampleAsset->serial = 'SN9876543210';
$exampleAsset->company = new Company();
$exampleAsset->company->id = 999999;
$exampleAsset->company->name = 'Test Company Limited';
$exampleAsset->company->image = 'company-image-test.png';
$exampleAsset->assignedto = new User();
$exampleAsset->assignedto->id = 999999;
$exampleAsset->assignedto->first_name = 'Test';
$exampleAsset->assignedto->last_name = 'Person';
$exampleAsset->assignedto->username = 'Test.Person';
$exampleAsset->assignedto->employee_num = '0123456789';
$exampleAsset->model = new AssetModel();
$exampleAsset->model->id = 999999;
$exampleAsset->model->name = 'Test Model';
$exampleAsset->model->model_number = 'MDL5678';
$exampleAsset->model->manufacturer = new Manufacturer();
$exampleAsset->model->manufacturer->id = 999999;
$exampleAsset->model->manufacturer->name = 'Test Manufacturing Inc.';
$exampleAsset->model->category = new Category();
$exampleAsset->model->category->id = 999999;
$exampleAsset->model->category->name = 'Test Category';
$settings = Setting::getSettings();
if (request()->has('settings')) {
$overrides = request()->get('settings');
foreach ($overrides as $key => $value) {
$settings->$key = $value;
}
}
return (new LabelView())
->with('assets', collect([$exampleAsset]))
->with('settings', $settings)
->with('template', $template)
->with('bulkedit', false)
->with('count', 0);
return redirect()->route('home')->with('error', trans('admin/labels/message.does_not_exist'));
}
}

View File

@@ -30,15 +30,17 @@ class LicenseCheckoutController extends Controller
// Check that the license is valid
if ($license = License::find($licenseId)) {
$this->authorize('checkout', $license);
// If the license is valid, check that there is an available seat
if ($license->avail_seats_count < 1) {
return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
}
return view('licenses/checkout', compact('license'));
}
$this->authorize('checkout', $license);
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
return view('licenses/checkout', compact('license'));
}
/**

View File

@@ -152,21 +152,19 @@ class LicenseFilesController extends Controller
->header('Content-Type', 'text/plain');
} else {
if (request('inline') == 'true') {
$headers = [
'Content-Disposition' => 'inline',
];
return Storage::download($file, $log->filename, $headers);
}
// We have to override the URL stuff here, since local defaults in Laravel's Flysystem
// won't work, as they're not accessible via the web
if (config('filesystems.default') == 'local') { // TODO - is there any way to fix this at the StorageHelper layer?
return StorageHelper::downloader($file);
} else {
if ($download != 'true') {
\Log::debug('display the file');
if ($contents = file_get_contents(Storage::url($file))) { // TODO - this will fail on private S3 files or large public ones
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
}
return JsonResponse::create(['error' => 'Failed validation: '], 500);
}
return StorageHelper::downloader($file);
}
}

View File

@@ -207,7 +207,7 @@ class LicensesController extends Controller
if ($license->assigned_seats_count == 0) {
// Delete the license and the associated license seats
DB::table('license_seats')
->where('id', $license->id)
->where('license_id', $license->id)
->update(['assigned_to' => null, 'asset_id' => null]);
$licenseSeats = $license->licenseseats();

View File

@@ -79,6 +79,8 @@ class LocationsController extends Controller
$location->ldap_ou = $request->input('ldap_ou');
$location->manager_id = $request->input('manager_id');
$location->user_id = Auth::id();
$location->phone = request('phone');
$location->fax = request('fax');
$location = $request->handleImages($location);
@@ -139,6 +141,8 @@ class LocationsController extends Controller
$location->state = $request->input('state');
$location->country = $request->input('country');
$location->zip = $request->input('zip');
$location->phone = request('phone');
$location->fax = request('fax');
$location->ldap_ou = $request->input('ldap_ou');
$location->manager_id = $request->input('manager_id');

View File

@@ -501,7 +501,6 @@ class ReportsController extends Controller
$header[] = trans('general.zip');
}
if ($request->filled('assigned_to')) {
$header[] = trans('admin/hardware/table.checkoutto');
$header[] = trans('general.type');
@@ -532,19 +531,24 @@ class ReportsController extends Controller
}
if ($request->filled('warranty')) {
$header[] = 'Warranty';
$header[] = 'Warranty Expires';
$header[] = trans('admin/hardware/form.warranty');
$header[] = trans('admin/hardware/form.warranty_expires');
}
if ($request->filled('depreciation')) {
$header[] = 'Value';
$header[] = 'Diff';
$header[] = 'Fully Depreciated';
$header[] = trans('admin/hardware/table.book_value');
$header[] = trans('admin/hardware/table.diff');
$header[] = trans('admin/hardware/form.fully_depreciated');
}
if ($request->filled('checkout_date')) {
$header[] = trans('admin/hardware/table.checkout_date');
}
if ($request->filled('checkin_date')) {
$header[] = trans('admin/hardware/table.last_checkin_date');
}
if ($request->filled('expected_checkin')) {
$header[] = trans('admin/hardware/form.expected_checkin');
}
@@ -590,7 +594,7 @@ class ReportsController extends Controller
$executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
\Log::debug('Added headers: '.$executionTime);
$assets = \App\Models\Company::scopeCompanyables(Asset::select('assets.*'))->with(
$assets = Asset::select('assets.*')->with(
'location', 'assetstatus', 'company', 'defaultLoc', 'assignedTo',
'model.category', 'model.manufacturer', 'supplier');
@@ -639,10 +643,24 @@ class ReportsController extends Controller
}
if (($request->filled('created_start')) && ($request->filled('created_end'))) {
$assets->whereBetween('assets.created_at', [$request->input('created_start'), $request->input('created_end')]);
$created_start = \Carbon::parse($request->input('created_start'))->startOfDay();
$created_end = \Carbon::parse($request->input('created_end'))->endOfDay();
$assets->whereBetween('assets.created_at', [$created_start, $created_end]);
}
if (($request->filled('checkout_date_start')) && ($request->filled('checkout_date_end'))) {
$assets->whereBetween('assets.last_checkout', [$request->input('checkout_date_start'), $request->input('checkout_date_end')]);
$checkout_start = \Carbon::parse($request->input('checkout_date_start'))->startOfDay();
$checkout_end = \Carbon::parse($request->input('checkout_date_end'))->endOfDay();
$assets->whereBetween('assets.last_checkout', [$checkout_start, $checkout_end]);
}
if (($request->filled('checkin_date_start'))) {
$assets->whereBetween('last_checkin', [
Carbon::parse($request->input('checkin_date_start'))->startOfDay(),
// use today's date is `checkin_date_end` is not provided
Carbon::parse($request->input('checkin_date_end', now()))->endOfDay(),
]);
}
if (($request->filled('expected_checkin_start')) && ($request->filled('expected_checkin_end'))) {
@@ -650,7 +668,10 @@ class ReportsController extends Controller
}
if (($request->filled('last_audit_start')) && ($request->filled('last_audit_end'))) {
$assets->whereBetween('assets.last_audit_date', [$request->input('last_audit_start'), $request->input('last_audit_end')]);
$last_audit_start = \Carbon::parse($request->input('last_audit_start'))->startOfDay();
$last_audit_end = \Carbon::parse($request->input('last_audit_end'))->endOfDay();
$assets->whereBetween('assets.last_audit_date', [$last_audit_start, $last_audit_end]);
}
if (($request->filled('next_audit_start')) && ($request->filled('next_audit_end'))) {
@@ -826,6 +847,12 @@ class ReportsController extends Controller
$row[] = ($asset->last_checkout) ? $asset->last_checkout : '';
}
if ($request->filled('checkin_date')) {
$row[] = ($asset->last_checkin)
? Carbon::parse($asset->last_checkin)->format('Y-m-d')
: '';
}
if ($request->filled('expected_checkin')) {
$row[] = ($asset->expected_checkin) ? $asset->expected_checkin : '';
}
@@ -994,7 +1021,12 @@ class ReportsController extends Controller
$assetsForReport = $acceptances
->filter(function ($acceptance) {
return $acceptance->checkoutable_type == 'App\Models\Asset';
$acceptance_checkoutable_flag = false;
if ($acceptance->checkoutable){
$acceptance_checkoutable_flag = $acceptance->checkoutable->checkedOutToUser();
}
return $acceptance->checkoutable_type == 'App\Models\Asset' && $acceptance_checkoutable_flag;
})
->map(function($acceptance) {
return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance];

View File

@@ -590,6 +590,7 @@ class SettingsController extends Controller
$setting->date_display_format = $request->input('date_display_format');
$setting->time_display_format = $request->input('time_display_format');
$setting->digit_separator = $request->input('digit_separator');
$setting->name_display_format = $request->input('name_display_format');
if ($setting->save()) {
return redirect()->route('settings.index')
@@ -827,6 +828,14 @@ class SettingsController extends Controller
if (is_null($setting = Setting::getSettings())) {
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
}
$setting->label2_enable = $request->input('label2_enable');
$setting->label2_template = $request->input('label2_template');
$setting->label2_title = $request->input('label2_title');
$setting->label2_asset_logo = $request->input('label2_asset_logo');
$setting->label2_1d_type = $request->input('label2_1d_type');
$setting->label2_2d_type = $request->input('label2_2d_type');
$setting->label2_2d_target = $request->input('label2_2d_target');
$setting->label2_fields = $request->input('label2_fields');
$setting->labels_per_page = $request->input('labels_per_page');
$setting->labels_width = $request->input('labels_width');
$setting->labels_height = $request->input('labels_height');
@@ -875,7 +884,7 @@ class SettingsController extends Controller
}
if ($setting->save()) {
return redirect()->route('settings.index')
return redirect()->route('settings.labels.index')
->with('success', trans('admin/settings/message.update.success'));
}
@@ -1136,7 +1145,7 @@ class SettingsController extends Controller
public function postBackups()
{
if (! config('app.lock_passwords')) {
Artisan::call('snipeit:backup', ['--filename' => 'manual-backup-'.date('Y-m-d-H:i:s')]);
Artisan::call('snipeit:backup', ['--filename' => 'manual-backup-'.date('Y-m-d-H-i-s')]);
$output = Artisan::output();
// Backup completed

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Users;
use App\Helpers\StorageHelper;
use App\Http\Controllers\Controller;
use App\Http\Requests\AssetFileRequest;
use App\Models\Actionlog;
@@ -139,18 +140,25 @@ class UserFilesController extends Controller
// the license is valid
if (isset($user->id)) {
$this->authorize('view', $user);
$log = Actionlog::find($fileId);
$file = $log->get_src('users');
return Response::download($file); //FIXME this doesn't use the new StorageHelper yet, but it's complicated...
// Display the file inline
if (request('inline') == 'true') {
$headers = [
'Content-Disposition' => 'inline',
];
return Storage::download('private_uploads/users/'.$log->filename, $log->filename, $headers);
}
return Storage::download('private_uploads/users/'.$log->filename);
}
// Prepare the error message
$error = trans('admin/users/message.user_not_found', ['id' => $userId]);
// Redirect to the licence management page
return redirect()->route('users.index')->with('error', $error);
// Redirect to the user management page if the user doesn't exist
return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', ['id' => $userId]));
}
}

View File

@@ -133,6 +133,9 @@ class UsersController extends Controller
// we have to invoke the
app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar');
\Log::info("About to call customFill, in the 'store' controller!!!");
$user->customFill($request, Auth::user());
if ($user->save()) {
if ($request->filled('groups')) {
$user->groups()->sync($request->input('groups'));
@@ -300,6 +303,8 @@ class UsersController extends Controller
// Handle uploaded avatar
app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar');
\Log::debug("calling custom fill from the UPDATE method!");
$user->customFill($request, Auth::user());
//\Log::debug(print_r($user, true));
// Was the user updated?

View File

@@ -82,7 +82,7 @@ class ViewAssetsController extends Controller
return view('account/requestable-assets', compact('assets', 'models'));
}
public function getRequestItem(Request $request, $itemType, $itemId = null)
public function getRequestItem(Request $request, $itemType, $itemId = null, $cancel_by_admin = false, $requestingUser = null)
{
$item = null;
$fullItemType = 'App\\Models\\'.studly_case($itemType);
@@ -119,16 +119,16 @@ class ViewAssetsController extends Controller
$settings = Setting::getSettings();
if ($item_request = $item->isRequestedBy($user)) {
$item->cancelRequest();
$data['item_quantity'] = $item_request->qty;
if (($item_request = $item->isRequestedBy($user)) || $cancel_by_admin) {
$item->cancelRequest($requestingUser);
$data['item_quantity'] = ($item_request) ? $item_request->qty : 1;
$logaction->logaction('request_canceled');
if (($settings->alert_email != '') && ($settings->alerts_enabled == '1') && (! config('app.lock_passwords'))) {
$settings->notify(new RequestAssetCancelation($data));
}
return redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.canceled'));
return redirect()->back()->with('success')->with('success', trans('admin/hardware/message.requests.canceled'));
} else {
$item->request();
if (($settings->alert_email != '') && ($settings->alerts_enabled == '1') && (! config('app.lock_passwords'))) {

View File

@@ -18,13 +18,12 @@ class Kernel extends HttpKernel
\Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Fideloper\Proxy\TrustProxies::class,
\App\Http\Middleware\CheckForSetup::class,
\App\Http\Middleware\CheckForDebug::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\SecurityHeaders::class,
\App\Http\Middleware\PreventBackHistory::class,
\Fruitcake\Cors\HandleCors::class,
\Illuminate\Http\Middleware\HandleCors::class,
];

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class CategoryEditForm extends Component
{
public $defaultEulaText;
public $eulaText;
public $originalSendCheckInEmailValue;
public $requireAcceptance;
public $sendCheckInEmail;
public $useDefaultEula;
public function mount()
{
$this->originalSendCheckInEmailValue = $this->sendCheckInEmail;
if ($this->eulaText || $this->useDefaultEula) {
$this->sendCheckInEmail = 1;
}
}
public function render()
{
return view('livewire.category-edit-form');
}
public function updated($property, $value)
{
if (! in_array($property, ['eulaText', 'useDefaultEula'])) {
return;
}
$this->sendCheckInEmail = $this->eulaText || $this->useDefaultEula ? 1 : $this->originalSendCheckInEmailValue;
}
public function getShouldDisplayEmailMessageProperty(): bool
{
return $this->eulaText || $this->useDefaultEula;
}
public function getEmailMessageProperty(): string
{
if ($this->useDefaultEula) {
return trans('admin/categories/general.email_will_be_sent_due_to_global_eula');
}
return trans('admin/categories/general.email_will_be_sent_due_to_category_eula');
}
public function getEulaTextDisabledProperty()
{
return (bool)$this->useDefaultEula;
}
public function getSendCheckInEmailDisabledProperty()
{
return $this->eulaText || $this->useDefaultEula;
}
}

View File

@@ -2,6 +2,8 @@
namespace App\Http\Livewire;
use App\Models\Asset;
use App\Models\DefaultValuesForCustomFields;
use Livewire\Component;
use App\Models\CustomFieldset;
@@ -30,7 +32,7 @@ class CustomFieldSetDefaultValuesForModel extends Component
$this->fields = CustomFieldset::find($this->fieldset_id)->fields;
}
$this->add_default_values = ($this->model->defaultValues->count() > 0);
$this->add_default_values = (DefaultValuesForCustomFields::forPivot($this->model, Asset::class)->count() > 0);
}
public function updatedFieldsetId()

View File

@@ -100,7 +100,7 @@ class Importer extends Component
if ($type == "asset") {
// add Custom Fields after a horizontal line
$results['-'] = "———" . trans('admin/custom_fields/general.custom_fields') . "———’";
foreach (CustomField::orderBy('name')->get() as $field) {
foreach (CustomField::where('type', \App\Models\Asset::class)->orderBy('name')->get() as $field) { // TODO - generalize?
$results[$field->db_column_name()] = $field->name;
}
}
@@ -214,8 +214,8 @@ class Importer extends Component
'model_notes' => trans('general.item_notes', ['item' => trans('admin/hardware/form.model')]),
'manufacturer' => trans('general.manufacturer'),
'order_number' => trans('general.order_number'),
'notes' => trans('general.notes'),
'image' => trans('general.importer.image_filename'),
'asset_eol_date' => trans('admin/hardware/form.eol_date'),
/**
* Checkout fields:
* Assets can be checked out to other assets, people, or locations, but we currently
@@ -285,6 +285,9 @@ class Importer extends Component
'maintained' => trans('admin/licenses/form.maintained'),
'checkout_class' => trans('general.importer.checkout_type'),
'serial' => trans('general.license_serial'),
'email' => trans('general.importer.checked_out_to_email'),
'username' => trans('general.importer.checked_out_to_username'),
'manufacturer' => trans('general.manufacturer'),
];
$this->users_fields = [
@@ -314,7 +317,7 @@ class Importer extends Component
'gravatar' => trans('general.importer.gravatar'),
'start_date' => trans('general.start_date'),
'end_date' => trans('general.end_date'),
'employee_number' => trans('general.employee_number'),
'employee_num' => trans('general.employee_number'),
];
$this->locations_fields = [

View File

@@ -2,7 +2,7 @@
namespace App\Http\Middleware;
use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
@@ -10,7 +10,7 @@ class TrustProxies extends Middleware
/**
* The trusted proxies for this application.
*
* @var array|string|null
* @var array<int, string>|string|null
*/
protected $proxies;
@@ -19,5 +19,10 @@ class TrustProxies extends Middleware
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB;
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
}

View File

@@ -34,12 +34,14 @@ class CustomFieldRequest extends FormRequest
case 'POST':
{
$rules['name'] = 'required|unique:custom_fields';
$rules['tab'] = 'required';
break;
}
// Save all fields
case 'PUT':
$rules['name'] = 'required';
$rules['tab'] = 'required';
break;
// Save only what's passed

View File

@@ -32,6 +32,7 @@ class SaveUserRequest extends FormRequest
public function rules()
{
$rules = [
'department_id' => 'nullable|exists:departments,id',
'manager_id' => 'nullable|exists:users,id',
];

View File

@@ -32,7 +32,7 @@ class AccessoriesTransformer
'model_number' => ($accessory->model_number) ? e($accessory->model_number) : null,
'category' => ($accessory->category) ? ['id' => $accessory->category->id, 'name'=> e($accessory->category->name)] : null,
'location' => ($accessory->location) ? ['id' => $accessory->location->id, 'name'=> e($accessory->location->name)] : null,
'notes' => ($accessory->notes) ? e($accessory->notes) : null,
'notes' => ($accessory->notes) ? Helper::parseEscapedMarkedownInline($accessory->notes) : null,
'qty' => ($accessory->qty) ? (int) $accessory->qty : null,
'purchase_date' => ($accessory->purchase_date) ? Helper::getFormattedDateObject($accessory->purchase_date, 'date') : null,
'purchase_cost' => Helper::formatCurrencyOutput($accessory->purchase_cost),

View File

@@ -3,7 +3,12 @@ namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Actionlog;
use App\Models\CustomField;
use App\Models\Setting;
use App\Models\Company;
use App\Models\Supplier;
use App\Models\Location;
use App\Models\AssetModel;
use Illuminate\Database\Eloquent\Collection;
class ActionlogsTransformer
@@ -38,6 +43,7 @@ class ActionlogsTransformer
public function transformActionlog (Actionlog $actionlog, $settings = null)
{
$icon = $actionlog->present()->icon();
$custom_field = CustomField::all();
if ($actionlog->filename!='') {
$icon = e(\App\Helpers\Helper::filetype_icon($actionlog->filename));
}
@@ -46,13 +52,24 @@ class ActionlogsTransformer
if (($actionlog->log_meta) && ($actionlog->log_meta!='')) {
$meta_array = json_decode($actionlog->log_meta);
$clean_meta = [];
if ($meta_array) {
foreach ($meta_array as $fieldname => $fieldata) {
$clean_meta[$fieldname]['old'] = $this->clean_field($fieldata->old);
$clean_meta[$fieldname]['new'] = $this->clean_field($fieldata->new);
if( str_starts_with($fieldname, '_snipeit_')){
if( $custom_field->where('db_column', '=', $fieldname)->where('field_encrypted', true)){
$clean_meta[$fieldname]['old'] = "encrypted";
$clean_meta[$fieldname]['new'] = "encrypted";
}
}
else {
$clean_meta[$fieldname]['old'] = $this->clean_field($fieldata->old);
$clean_meta[$fieldname]['new'] = $this->clean_field($fieldata->new);
}
}
}
$clean_meta= $this->changedInfo($clean_meta);
}
$file_url = '';
@@ -110,14 +127,15 @@ class ActionlogsTransformer
'type' => e($actionlog->targetType()),
] : null,
'note' => ($actionlog->note) ? e($actionlog->note): null,
'note' => ($actionlog->note) ? Helper::parseEscapedMarkedownInline($actionlog->note): null,
'signature_file' => ($actionlog->accept_signature) ? route('log.signature.view', ['filename' => $actionlog->accept_signature ]) : null,
'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta: null,
'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'),
];
//\Log::info("Clean Meta is: ".print_r($clean_meta,true));
// \Log::info("Clean Meta is: ".print_r($clean_meta,true));
//dd($array);
return $array;
}
@@ -132,6 +150,80 @@ class ActionlogsTransformer
}
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
/**
* This takes the ids of the changed attributes and returns the names instead for the history view of an Asset
*
* @param array $clean_meta
* @return array
*/
public function changedInfo(array $clean_meta)
{ $location = Location::withTrashed()->get();
$supplier = Supplier::withTrashed()->get();
$model = AssetModel::withTrashed()->get();
$company = Company::get();
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['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');
$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');
$newModel = $model->find($clean_meta['model_id']['new']);
$newModelName = $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 */
$clean_meta['Model'] = $clean_meta['model_id'];
unset($clean_meta['model_id']);
}
if(array_key_exists('company_id', $clean_meta)) {
$oldCompany = $company->find($clean_meta['company_id']['old']);
$oldCompanyName = $oldCompany->name ?? trans('admin/companies/message.deleted');
$newCompany = $company->find($clean_meta['company_id']['new']);
$newCompanyName = $newCompany->name ?? trans('admin/companies/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');
$clean_meta['Company'] = $clean_meta['company_id'];
unset($clean_meta['company_id']);
}
if(array_key_exists('supplier_id', $clean_meta)) {
$oldSupplier = $supplier->find($clean_meta['supplier_id']['old']);
$oldSupplierName = $oldSupplier->name ?? trans('admin/suppliers/message.deleted');
$newSupplier = $supplier->find($clean_meta['supplier_id']['new']);
$newSupplierName = $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');
$clean_meta['Supplier'] = $clean_meta['supplier_id'];
unset($clean_meta['supplier_id']);
}
if(array_key_exists('asset_eol_date', $clean_meta)) {
$clean_meta['EOL date'] = $clean_meta['asset_eol_date'];
unset($clean_meta['asset_eol_date']);
}
return $clean_meta;
}

View File

@@ -49,7 +49,7 @@ class AssetMaintenancesTransformer
'id' => (int) $assetmaintenance->asset->defaultLoc->id,
'name'=> e($assetmaintenance->asset->defaultLoc->name),
] : null,
'notes' => ($assetmaintenance->notes) ? e($assetmaintenance->notes) : null,
'notes' => ($assetmaintenance->notes) ? Helper::parseEscapedMarkedownInline($assetmaintenance->notes) : null,
'supplier' => ($assetmaintenance->supplier) ? ['id' => $assetmaintenance->supplier->id, 'name'=> e($assetmaintenance->supplier->name)] : null,
'cost' => Helper::formatCurrencyOutput($assetmaintenance->cost),
'asset_maintenance_type' => e($assetmaintenance->asset_maintenance_type),

View File

@@ -47,6 +47,7 @@ class AssetModelsTransformer
] : null,
'image' => ($assetmodel->image != '') ? Storage::disk('public')->url('models/'.e($assetmodel->image)) : null,
'model_number' => e($assetmodel->model_number),
'min_amt' => ($assetmodel->min_amt) ? (int) $assetmodel->min_amt : null,
'depreciation' => ($assetmodel->depreciation) ? [
'id' => (int) $assetmodel->depreciation->id,
'name'=> e($assetmodel->depreciation->name),
@@ -63,7 +64,7 @@ class AssetModelsTransformer
'default_fieldset_values' => $default_field_values,
'eol' => ($assetmodel->eol > 0) ? $assetmodel->eol.' months' : 'None',
'requestable' => ($assetmodel->requestable == '1') ? true : false,
'notes' => e($assetmodel->notes),
'notes' => Helper::parseEscapedMarkedownInline($assetmodel->notes),
'created_at' => Helper::getFormattedDateObject($assetmodel->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($assetmodel->updated_at, 'datetime'),
'deleted_at' => Helper::getFormattedDateObject($assetmodel->deleted_at, 'datetime'),

View File

@@ -2,6 +2,7 @@
namespace App\Http\Transformers;
use App\Helpers\CustomFieldHelper;
use App\Helpers\Helper;
use App\Models\Asset;
use App\Models\Setting;
@@ -38,7 +39,7 @@ class AssetsTransformer
'byod' => ($asset->byod ? true : false),
'model_number' => (($asset->model) && ($asset->model->model_number)) ? e($asset->model->model_number) : null,
'eol' => ($asset->model->eol != '') ? $asset->model->eol : null,
'eol' => (($asset->model) && ($asset->model->eol != '')) ? $asset->model->eol : null,
'asset_eol_date' => ($asset->asset_eol_date != '') ? Helper::getFormattedDateObject($asset->asset_eol_date, 'date') : null,
'status_label' => ($asset->assetstatus) ? [
'id' => (int) $asset->assetstatus->id,
@@ -58,7 +59,7 @@ class AssetsTransformer
'id' => (int) $asset->supplier->id,
'name'=> e($asset->supplier->name),
] : null,
'notes' => ($asset->notes) ? e($asset->notes) : null,
'notes' => ($asset->notes) ? Helper::parseEscapedMarkedownInline($asset->notes) : null,
'order_number' => ($asset->order_number) ? e($asset->order_number) : null,
'company' => ($asset->company) ? [
'id' => (int) $asset->company->id,
@@ -92,52 +93,11 @@ class AssetsTransformer
'checkout_counter' => (int) $asset->checkout_counter,
'requests_counter' => (int) $asset->requests_counter,
'user_can_checkout' => (bool) $asset->availableForCheckout(),
'book_value' => Helper::formatCurrencyOutput($asset->getLinearDepreciatedValue()),
];
if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields->count() > 0)) {
$fields_array = [];
foreach ($asset->model->fieldset->fields as $field) {
if ($field->isFieldDecryptable($asset->{$field->db_column})) {
$decrypted = Helper::gracefulDecrypt($field, $asset->{$field->db_column});
$value = (Gate::allows('superadmin')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));
if ($field->format == 'DATE'){
if (Gate::allows('superadmin')){
$value = Helper::getFormattedDateObject($value, 'date', false);
} else {
$value = strtoupper(trans('admin/custom_fields/general.encrypted'));
}
}
$fields_array[$field->name] = [
'field' => e($field->db_column),
'value' => e($value),
'field_format' => $field->format,
'element' => $field->element,
];
} else {
$value = $asset->{$field->db_column};
if (($field->format == 'DATE') && (!is_null($value)) && ($value!='')){
$value = Helper::getFormattedDateObject($value, 'date', false);
}
$fields_array[$field->name] = [
'field' => e($field->db_column),
'value' => e($value),
'field_format' => $field->format,
'element' => $field->element,
];
}
$array['custom_fields'] = $fields_array;
}
} else {
$array['custom_fields'] = new \stdClass; // HACK to force generation of empty object instead of empty list
}
$array['custom_fields'] = CustomFieldHelper::transform($asset->model->fieldset,$asset);
$permissions_array['available_actions'] = [
'checkout' => ($asset->deleted_at=='' && Gate::allows('checkout', Asset::class)) ? true : false,

View File

@@ -26,6 +26,9 @@ class CompaniesTransformer
$array = [
'id' => (int) $company->id,
'name' => e($company->name),
'phone' => ($company->phone!='') ? e($company->phone): null,
'fax' => ($company->fax!='') ? e($company->fax): null,
'email' => ($company->email!='') ? e($company->email): null,
'image' => ($company->image) ? Storage::disk('public')->url('companies/'.e($company->image)) : null,
'created_at' => Helper::getFormattedDateObject($company->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($company->updated_at, 'datetime'),

View File

@@ -46,7 +46,7 @@ class ComponentsTransformer
'id' => (int) $component->company->id,
'name' => e($component->company->name),
] : null,
'notes' => ($component->notes) ? e($component->notes) : null,
'notes' => ($component->notes) ? Helper::parseEscapedMarkedownInline($component->notes) : null,
'created_at' => Helper::getFormattedDateObject($component->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($component->updated_at, 'datetime'),
'user_can_checkout' => ($component->numRemaining() > 0) ? 1 : 0,

View File

@@ -39,7 +39,7 @@ class ConsumablesTransformer
'purchase_cost' => Helper::formatCurrencyOutput($consumable->purchase_cost),
'purchase_date' => Helper::getFormattedDateObject($consumable->purchase_date, 'date'),
'qty' => (int) $consumable->qty,
'notes' => ($consumable->notes) ? e($consumable->notes) : null,
'notes' => ($consumable->notes) ? Helper::parseEscapedMarkedownInline($consumable->notes) : null,
'created_at' => Helper::getFormattedDateObject($consumable->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($consumable->updated_at, 'datetime'),
];

View File

@@ -49,6 +49,7 @@ class CustomFieldsTransformer
'required' => (($field->pivot) && ($field->pivot->required=='1')) ? true : false,
'display_in_user_view' => ($field->display_in_user_view =='1') ? true : false,
'auto_add_to_fieldsets' => ($field->auto_add_to_fieldsets == '1') ? true : false,
'show_in_listview' => ($field->show_in_listview == '1') ? true : false,
'created_at' => Helper::getFormattedDateObject($field->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($field->updated_at, 'datetime'),
];

View File

@@ -3,6 +3,8 @@
namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\CustomFieldset;
use Illuminate\Database\Eloquent\Collection;
@@ -21,8 +23,13 @@ class CustomFieldsetsTransformer
public function transformCustomFieldset(CustomFieldset $fieldset)
{
$fields = $fieldset->fields;
$models = $fieldset->models;
$models = [];
$modelsArray = [];
if ($fieldset->type == Asset::class) {
\Log::debug("Item pivot id is: ".$fieldset->item_pivot_id);
$models = AssetModel::where('fieldset_id', $fieldset->id)->get();
\Log::debug("And the models object count is: ".$models->count());
}
foreach ($models as $model) {
$modelsArray[] = [
@@ -30,15 +37,21 @@ class CustomFieldsetsTransformer
'name' => e($model->name),
];
}
\Log::debug("Models array is: ".print_r($modelsArray,true));
$array = [
'id' => (int) $fieldset->id,
'name' => e($fieldset->name),
'fields' => (new CustomFieldsTransformer)->transformCustomFields($fields, $fieldset->fields_count),
'models' => (new DatatablesTransformer)->transformDatatables($modelsArray, $fieldset->models_count),
'customizables' => (new DatatablesTransformer)->transformDatatables($fieldset->customizables(),count($fieldset->customizables())),
'created_at' => Helper::getFormattedDateObject($fieldset->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($fieldset->updated_at, 'datetime'),
'type' => $fieldset->type,
];
if ($fieldset->type == Asset::class) {
// TODO - removeme - legacy column just for Assets?
$array['models'] = (new DatatablesTransformer)->transformDatatables($modelsArray, count($modelsArray));
}
return $array;
}

View File

@@ -26,6 +26,8 @@ class DepartmentsTransformer
$array = [
'id' => (int) $department->id,
'name' => e($department->name),
'phone' => ($department->phone!='') ? e($department->phone): null,
'fax' => ($department->fax!='') ? e($department->fax): null,
'image' => ($department->image) ? Storage::disk('public')->url(app('departments_upload_url').e($department->image)) : null,
'company' => ($department->company) ? [
'id' => (int) $department->company->id,

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Labels\Label;
use App\Models\Labels\Sheet;
use App\Models\Labels\RectangleSheet;
use Illuminate\Support\Collection;
class LabelsTransformer
{
public function transformLabels(Collection $labels, $total)
{
$array = [];
foreach ($labels as $label) {
$array[] = self::transformLabel($label);
}
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
public function transformLabel(Label $label)
{
$array = [
'name' => $label->getName(),
'unit' => $label->getUnit(),
'width' => number_format($label->getWidth(), 2),
'height' => number_format($label->getHeight(), 2),
'margin_top' => $label->getMarginTop(),
'margin_bottom' => $label->getMarginBottom(),
'margin_left' => $label->getMarginLeft(),
'margin_right' => $label->getMarginRight(),
'support_asset_tag' => $label->getSupportAssetTag(),
'support_1d_barcode' => $label->getSupport1DBarcode(),
'support_2d_barcode' => $label->getSupport2DBarcode(),
'support_fields' => $label->getSupportFields(),
'support_logo' => $label->getSupportLogo(),
'support_title' => $label->getSupportTitle(),
];
if ($label instanceof Sheet) {
$array['sheet_info'] = [
'label_width' => $label->getLabelWidth(),
'label_height' => $label->getLabelHeight(),
'label_margin_top' => $label->getLabelMarginTop(),
'label_margin_bottom' => $label->getLabelMarginBottom(),
'label_margin_left' => $label->getLabelMarginLeft(),
'label_margin_right' => $label->getLabelMarginRight(),
'labels_per_page' => $label->getLabelsPerPage(),
'label_border' => $label->getLabelBorder(),
];
}
if ($label instanceof RectangleSheet) {
$array['rectanglesheet_info'] = [
'columns' => $label->getColumns(),
'rows' => $label->getRows(),
'column_spacing' => $label->getLabelColumnSpacing(),
'row_spacing' => $label->getLabelRowSpacing(),
];
}
return $array;
}
}

View File

@@ -34,7 +34,7 @@ class LicensesTransformer
'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null,
'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost),
'purchase_cost_numeric' => $license->purchase_cost,
'notes' => e($license->notes),
'notes' => Helper::parseEscapedMarkedownInline($license->notes),
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
'seats' => (int) $license->seats,
'free_seats_count' => (int) $license->free_seats_count,

View File

@@ -43,6 +43,8 @@ class LocationsTransformer
'state' => ($location->state) ? e($location->state) : null,
'country' => ($location->country) ? e($location->country) : null,
'zip' => ($location->zip) ? e($location->zip) : null,
'phone' => ($location->phone!='') ? e($location->phone): null,
'fax' => ($location->fax!='') ? e($location->fax): null,
'assigned_assets_count' => (int) $location->assigned_assets_count,
'assets_count' => (int) $location->assets_count,
'rtd_assets_count' => (int) $location->rtd_assets_count,

View File

@@ -43,7 +43,7 @@ class SuppliersTransformer
'licenses_count' => (int) $supplier->licenses_count,
'consumables_count' => (int) $supplier->consumables_count,
'components_count' => (int) $supplier->components_count,
'notes' => ($supplier->notes) ? e($supplier->notes) : null,
'notes' => ($supplier->notes) ? Helper::parseEscapedMarkedownInline($supplier->notes) : null,
'created_at' => Helper::getFormattedDateObject($supplier->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($supplier->updated_at, 'datetime'),

View File

@@ -2,7 +2,10 @@
namespace App\Http\Transformers;
use App\Helpers\CustomFieldHelper;
use App\Helpers\Helper;
use App\Models\CustomField;
use App\Models\CustomFieldset;
use App\Models\User;
use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
@@ -24,7 +27,7 @@ class UsersTransformer
$array = [
'id' => (int) $user->id,
'avatar' => e($user->present()->gravatar),
'name' => e($user->first_name).' '.e($user->last_name),
'name' => e($user->getFullNameAttribute()),
'first_name' => e($user->first_name),
'last_name' => e($user->last_name),
'username' => e($user->username),
@@ -53,7 +56,7 @@ class UsersTransformer
'id' => (int) $user->userloc->id,
'name'=> e($user->userloc->name),
] : null,
'notes'=> e($user->notes),
'notes'=> Helper::parseEscapedMarkedownInline($user->notes),
'permissions' => $user->decodePermissions(),
'activated' => ($user->activated == '1') ? true : false,
'autoassign_licenses' => ($user->autoassign_licenses == '1') ? true : false,
@@ -77,6 +80,8 @@ class UsersTransformer
'deleted_at' => ($user->deleted_at) ? Helper::getFormattedDateObject($user->deleted_at, 'datetime') : null,
];
$array['custom_fields'] = CustomFieldHelper::transform(CustomFieldset::where('type',User::class)->first(), $user);
$permissions_array['available_actions'] = [
'update' => (Gate::allows('update', User::class) && ($user->deleted_at == '')),
'delete' => (Gate::allows('delete', User::class) && ($user->assets_count == 0) && ($user->licenses_count == 0) && ($user->accessories_count == 0)),

View File

@@ -12,7 +12,10 @@ class AssetImporter extends ItemImporter
public function __construct($filename)
{
parent::__construct($filename);
$this->defaultStatusLabelId = Statuslabel::first()->id;
if (!is_null(Statuslabel::first())) {
$this->defaultStatusLabelId = Statuslabel::first()->id;
}
}
protected function handle($row)
@@ -20,19 +23,20 @@ class AssetImporter extends ItemImporter
// ItemImporter handles the general fetching.
parent::handle($row);
// FIXME : YUP!!!!! This shit needs to go (?) Yeah?
if ($this->customFields) {
foreach ($this->customFields as $customField) {
$customFieldValue = $this->array_smart_custom_field_fetch($row, $customField);
$customFieldValue = $this->array_smart_custom_field_fetch($row, $customField); // TODO/FIXME - this might require a new 'mode' on customFill()?
if ($customFieldValue) {
if ($customField->field_encrypted == 1) {
if ($customField->field_encrypted == 1) { // FIXME - repeated code.
$this->item['custom_fields'][$customField->db_column_name()] = \Crypt::encrypt($customFieldValue);
$this->log('Custom Field '.$customField->name.': '.\Crypt::encrypt($customFieldValue));
} else {
$this->item['custom_fields'][$customField->db_column_name()] = $customFieldValue;
$this->log('Custom Field '.$customField->name.': '.$customFieldValue);
}
} else {
} else { // FIXME - think this through? Do we want to blank this? Is that how other stuff works?
// Clear out previous data.
$this->item['custom_fields'][$customField->db_column_name()] = null;
}

View File

@@ -120,7 +120,7 @@ abstract class Importer
* @author Daniel Meltzer
* @since 5.0
*/
protected function populateCustomFields($headerRow)
protected function populateCustomFields($headerRow) // FIXME - what in the actual fuck is this.
{
// Stolen From https://adamwathan.me/2016/07/14/customizing-keys-when-mapping-collections/
// This 'inverts' the fields such that we have a collection of fields indexed by name.

View File

@@ -27,15 +27,24 @@ class LicenseImporter extends ItemImporter
* @since 4.0
* @param array $row
* @return License|mixed|null
* updated @author Jes Vinsmoke
* @since 6.1
*
*/
public function createLicenseIfNotExists(array $row)
{
$editingLicense = false;
$license = License::where('name', $this->item['name'])
$license = License::where('serial', $this->item['serial'])->where('name', $this->item['name'])
->first();
if ($license) {
if (! $this->updating) {
$this->log('A matching License '.$this->item['name'].' with serial '.$this->item['serial'].' already exists');
if($this->item['serial'] != "") {
$this->log('A matching License ' . $this->item['name'] . ' with serial ' . $this->item['serial'] . ' already exists');
}
else {
$this->log('A matching License ' . $this->item['name'] . ' with no serial number already exists');
}
return;
}
@@ -57,6 +66,12 @@ class LicenseImporter extends ItemImporter
$this->item['maintained'] = $this->findCsvMatch($row, 'maintained');
$this->item['purchase_order'] = $this->findCsvMatch($row, 'purchase_order');
$this->item['reassignable'] = $this->findCsvMatch($row, 'reassignable');
$this->item['manufacturer'] = $this->createOrFetchManufacturer($this->findCsvMatch($row, 'manufacturer'));
if($this->item['reassignable'] == "")
{
$this->item['reassignable'] = 1;
}
$this->item['seats'] = $this->findCsvMatch($row, 'seats');
$this->item["termination_date"] = null;

View File

@@ -33,7 +33,7 @@ class LogListener
*/
public function onCheckoutableCheckedIn(CheckoutableCheckedIn $event)
{
$event->checkoutable->logCheckin($event->checkedOutTo, $event->note, $event->action_date);
$event->checkoutable->logCheckin($event->checkedOutTo, $event->note, $event->action_date, $event->originalValues);
}
/**
@@ -46,7 +46,7 @@ class LogListener
*/
public function onCheckoutableCheckedOut(CheckoutableCheckedOut $event)
{
$event->checkoutable->logCheckout($event->note, $event->checkedOutTo, $event->checkoutable->last_checkout);
$event->checkoutable->logCheckout($event->note, $event->checkedOutTo, $event->checkoutable->last_checkout, $event->originalValues);
}
/**

View File

@@ -349,6 +349,22 @@ class Accessory extends SnipeModel
return (int) $remaining;
}
/**
* Run after the checkout acceptance was declined by the user
*
* @param User $acceptedBy
* @param string $signature
*/
public function declinedCheckout(User $declinedBy, $signature)
{
if (is_null($accessory_user = \DB::table('accessories_users')->where('assigned_to', $declinedBy->id)->where('accessory_id', $this->id)->latest('created_at'))) {
// Redirect to the accessory management page with error
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
}
$accessory_user->limit(1)->delete();
}
/**
* Query builder scope to order on company
*

View File

@@ -9,6 +9,8 @@ use App\Helpers\Helper;
use App\Http\Traits\UniqueSerialTrait;
use App\Http\Traits\UniqueUndeletedTrait;
use App\Models\Traits\Acceptable;
use App\Models\Traits\Customizable;
use App\Models\Traits\HasCustomFields;
use App\Models\Traits\Searchable;
use App\Presenters\Presentable;
use AssetPresenter;
@@ -18,6 +20,7 @@ use DB;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use Watson\Validating\ValidatingTrait;
@@ -38,8 +41,19 @@ class Asset extends Depreciable
public const ASSET = 'asset';
public const USER = 'user';
use Acceptable;
use Acceptable, HasCustomFields;
public function getFieldsetKey(): object|int|null {
return $this->model;
}
public static function getFieldsetUsers(int $fieldset_id): array {
$models = [];
foreach(AssetModel::where("fieldset_id",$fieldset_id)->get() as $model) {
$models[route('models.show', $model->id)] = $model->name.(($model->model_number) ? ' ('.$model->model_number.')' : '');
}
return $models;
}
/**
* Run after the checkout acceptance was declined by the user
*
@@ -73,6 +87,7 @@ class Asset extends Depreciable
protected $casts = [
'purchase_date' => 'date',
'last_checkout' => 'datetime',
'last_checkin' => 'datetime',
'expected_checkin' => 'date',
'last_audit_date' => 'datetime',
'next_audit_date' => 'date',
@@ -82,7 +97,6 @@ class Asset extends Depreciable
'location_id' => 'integer',
'rtd_company_id' => 'integer',
'supplier_id' => 'integer',
'byod' => 'boolean',
'created_at' => 'datetime',
'updated_at' => 'datetime',
'deleted_at' => 'datetime',
@@ -105,6 +119,7 @@ class Asset extends Depreciable
'purchase_cost' => 'numeric|nullable|gte:0',
'supplier_id' => 'exists:suppliers,id|nullable',
'asset_eol_date' => 'date|max:10|min:10|nullable',
'byod' => 'boolean',
];
/**
@@ -187,40 +202,6 @@ class Asset extends Depreciable
$this->attributes['expected_checkin'] = $value;
}
/**
* This handles the custom field validation for assets
*
* @var array
*/
public function save(array $params = [])
{
if ($this->model_id != '') {
$model = AssetModel::find($this->model_id);
if (($model) && ($model->fieldset)) {
foreach ($model->fieldset->fields as $field){
if($field->format == 'BOOLEAN'){
$this->{$field->db_column} = filter_var($this->{$field->db_column}, FILTER_VALIDATE_BOOLEAN);
}
}
$this->rules += $model->fieldset->validation_rules();
foreach ($this->model->fieldset->fields as $field){
if($field->format == 'BOOLEAN'){
$this->{$field->db_column} = filter_var($this->{$field->db_column}, FILTER_VALIDATE_BOOLEAN);
}
}
}
}
return parent::save($params);
}
public function getDisplayNameAttribute()
{
return $this->present()->name();
@@ -332,6 +313,13 @@ class Asset extends Depreciable
}
}
$originalValues = $this->getRawOriginal();
// attempt to detect change in value if different from today's date
if ($checkout_at && strpos($checkout_at, date('Y-m-d')) === false) {
$originalValues['action_date'] = date('Y-m-d H:i:s');
}
if ($this->save()) {
if (is_int($admin)) {
$checkedOutBy = User::findOrFail($admin);
@@ -340,7 +328,7 @@ class Asset extends Depreciable
} else {
$checkedOutBy = Auth::user();
}
event(new CheckoutableCheckedOut($this, $target, $checkedOutBy, $note));
event(new CheckoutableCheckedOut($this, $target, $checkedOutBy, $note, $originalValues));
$this->increment('checkout_counter', 1);
@@ -390,7 +378,7 @@ class Asset extends Depreciable
*/
public function depreciation()
{
return $this->model->belongsTo(\App\Models\Depreciation::class, 'depreciation_id');
return $this->hasOneThrough(\App\Models\Depreciation::class,\App\Models\AssetModel::class,'id','id','model_id','depreciation_id');
}
@@ -785,24 +773,17 @@ class Asset extends Depreciable
* @since [v4.0]
* @return string | false
*/
public static function autoincrement_asset()
public static function autoincrement_asset(int $additional_increment = 0)
{
$settings = \App\Models\Setting::getSettings();
if ($settings->auto_increment_assets == '1') {
$temp_asset_tag = \DB::table('assets')
->where('physical', '=', '1')
->max('asset_tag');
$asset_tag_digits = preg_replace('/\D/', '', $temp_asset_tag);
$asset_tag = preg_replace('/^0*/', '', $asset_tag_digits);
if ($settings->zerofill_count > 0) {
return $settings->auto_increment_prefix.self::zerofill($settings->next_auto_tag_base, $settings->zerofill_count);
return $settings->auto_increment_prefix.self::zerofill($settings->next_auto_tag_base + $additional_increment, $settings->zerofill_count);
}
return $settings->auto_increment_prefix.$settings->next_auto_tag_base;
return $settings->auto_increment_prefix.($settings->next_auto_tag_base + $additional_increment);
} else {
return false;
}
@@ -1440,6 +1421,12 @@ class Asset extends Depreciable
});
}
if ($fieldname == 'rtd_location') {
$query->whereHas('defaultLoc', function ($query) use ($search_val) {
$query->where('locations.name', 'LIKE', '%'.$search_val.'%');
});
}
if ($fieldname =='assigned_to') {
$query->whereHasMorph('assignedTo', [User::class], function ($query) use ($search_val) {
$query->where(function ($query) use ($search_val) {
@@ -1516,7 +1503,7 @@ class Asset extends Depreciable
*
* In short, this set of statements tells the query builder to ONLY query against an
* actual field that's being passed if it doesn't meet known relational fields. This
* allows us to query custom fields directly in the assetsv table
* allows us to query custom fields directly in the assets table
* (regardless of their name) and *skip* any fields that we already know can only be
* searched through relational searches that we do earlier in this method.
*
@@ -1566,7 +1553,7 @@ class Asset extends Depreciable
*/
public function scopeOrderModelNumber($query, $order)
{
return $query->join('models', 'assets.model_id', '=', 'models.id')->orderBy('models.model_number', $order);
return $query->leftJoin('models as model_number_sort', 'assets.model_id', '=', 'model_number_sort.id')->orderBy('model_number_sort.model_number', $order);
}

View File

@@ -29,6 +29,7 @@ class AssetModel extends SnipeModel
protected $rules = [
'name' => 'required|min:1|max:255',
'model_number' => 'max:255|nullable',
'min_amt' => 'integer|min:0|nullable',
'category_id' => 'required|integer|exists:categories,id',
'manufacturer_id' => 'integer|exists:manufacturers,id|nullable',
'eol' => 'integer:min:0|max:240|nullable',
@@ -65,6 +66,7 @@ class AssetModel extends SnipeModel
'fieldset_id',
'image',
'manufacturer_id',
'min_amt',
'model_number',
'name',
'notes',
@@ -148,19 +150,13 @@ class AssetModel extends SnipeModel
*/
public function fieldset()
{
// this is actually OK - we don't *need* to do this, but it's okay to make references from Model to fieldset
return $this->belongsTo(\App\Models\CustomFieldset::class, 'fieldset_id');
}
/**
* Establishes the model -> custom field default values relationship
*
* @author hannah tinkler
* @since [v4.3]
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function defaultValues()
public function customFields()
{
return $this->belongsToMany(\App\Models\CustomField::class, 'models_custom_fields')->withPivot('default_value');
return $this->fieldset()->first()->fields();
}
/**

View File

@@ -18,7 +18,7 @@ class CheckoutRequest extends Model
public function requestingUser()
{
return $this->user()->first();
return $this->user()->withTrashed()->first();
}
public function requestedItem()

View File

@@ -24,6 +24,9 @@ final class Company extends SnipeModel
// Declare the rules for the model validation
protected $rules = [
'name' => 'required|min:1|max:255|unique:companies,name',
'fax' => 'min:7|max:35|nullable',
'phone' => 'min:7|max:35|nullable',
'email' => 'email|max:150|nullable',
];
protected $presenter = \App\Presenters\CompanyPresenter::class;
@@ -45,7 +48,7 @@ final class Company extends SnipeModel
*
* @var array
*/
protected $searchableAttributes = ['name', 'created_at', 'updated_at'];
protected $searchableAttributes = ['name', 'phone', 'fax', 'email', 'created_at', 'updated_at'];
/**
* The relations and their attributes that should be included when searching the model.
@@ -59,7 +62,12 @@ final class Company extends SnipeModel
*
* @var array
*/
protected $fillable = ['name'];
protected $fillable = [
'name',
'phone',
'fax',
'email',
];
private static function isFullMultipleCompanySupportEnabled()
{

View File

@@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\Rule;
use Schema;
use Watson\Validating\ValidatingTrait;
class CustomField extends Model
{
use HasFactory;
@@ -17,7 +16,7 @@ class CustomField extends Model
UniqueUndeletedTrait;
/**
* Custom field predfined formats
* Custom field predefined formats
*
* @var array
*/
@@ -53,6 +52,8 @@ class CustomField extends Model
'element' => 'required|in:text,listbox,textarea,checkbox,radio',
'field_encrypted' => 'nullable|boolean',
'auto_add_to_fieldsets' => 'boolean',
'show_in_listview' => 'boolean',
'type' => 'required'
];
/**
@@ -71,33 +72,23 @@ class CustomField extends Model
'is_unique',
'display_in_user_view',
'auto_add_to_fieldsets',
'show_in_listview',
];
/**
* This is confusing, since it's actually the custom fields table that
* we're usually modifying, but since we alter the assets table, we have to
* say that here, otherwise the new fields get added onto the custom fields
* table instead of the assets table.
*
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
* @since [v3.0]
*/
public static $table_name = 'assets';
/**
* Convert the custom field's name property to a db-safe string.
*
* We could probably have used str_slug() here but not sure what it would
* do with previously existing values. - @snipe
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.4]
* @return string
* @since [v3.4]
* @author [A. Gianotto] [<snipe@snipe.net>]
*/
public static function name_to_db_name($name)
{
return '_snipeit_'.preg_replace('/[^a-zA-Z0-9]/', '_', strtolower($name));
return '_snipeit_' . preg_replace('/[^a-zA-Z0-9]/', '_', strtolower($name));
}
/**
@@ -108,23 +99,22 @@ class CustomField extends Model
* if they have changed, so we handle that here so that we don't have to remember
* to do it in the controllers.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.4]
* @return bool
* @since [v3.4]
* @author [A. Gianotto] [<snipe@snipe.net>]
*/
public static function boot()
{
parent::boot();
self::created(function ($custom_field) {
// Column already exists on the assets table - nothing to do here.
// This *shouldn't* happen in the wild.
if (Schema::hasColumn(self::$table_name, $custom_field->db_column)) {
if (Schema::hasColumn($custom_field->getTableName(), $custom_field->db_column)) {
return false;
}
// Update the column name in the assets table
Schema::table(self::$table_name, function ($table) use ($custom_field) {
Schema::table($custom_field->getTableName(), function ($table) use ($custom_field) {
$table->text($custom_field->convertUnicodeDbSlug())->nullable();
});
@@ -137,7 +127,7 @@ class CustomField extends Model
// Column already exists on the assets table - nothing to do here.
if ($custom_field->isDirty('name')) {
if (Schema::hasColumn(self::$table_name, $custom_field->convertUnicodeDbSlug())) {
if (Schema::hasColumn($custom_field->getTableName(), $custom_field->convertUnicodeDbSlug())) {
return true;
}
@@ -147,7 +137,7 @@ class CustomField extends Model
$platform->registerDoctrineTypeMapping('enum', 'string');
// Rename the field if the name has changed
Schema::table(self::$table_name, function ($table) use ($custom_field) {
Schema::table($custom_field->getTableName(), function ($table) use ($custom_field) {
$table->renameColumn($custom_field->convertUnicodeDbSlug($custom_field->getOriginal('name')), $custom_field->convertUnicodeDbSlug());
});
@@ -163,12 +153,19 @@ class CustomField extends Model
// Drop the assets column if we've deleted it from custom fields
self::deleting(function ($custom_field) {
return Schema::table(self::$table_name, function ($table) use ($custom_field) {
return Schema::table($custom_field->getTableName(), function ($table) use ($custom_field) {
$table->dropColumn($custom_field->db_column);
});
});
}
public function getTableName()
{
$type = $this->type;
$instance = new $type();
return $instance->getTable();
}
/**
* Establishes the customfield -> fieldset relationship
*
@@ -180,6 +177,11 @@ class CustomField extends Model
{
return $this->belongsToMany(\App\Models\CustomFieldset::class);
}
public function assetModels()
{
return $this->fieldset()->with('models')->get()->pluck('models')->flatten()->unique('id');
}
/**
* Establishes the customfield -> admin user relationship
@@ -194,31 +196,23 @@ class CustomField extends Model
}
/**
* Establishes the customfield -> default values relationship
*
* @author Hannah Tinkler
* @since [v3.0]
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function defaultValues()
{
return $this->belongsToMany(\App\Models\AssetModel::class, 'models_custom_fields')->withPivot('default_value');
}
/**
* Returns the default value for a given model using the defaultValues
* Returns the default value for a given 'item' using the defaultValues
* relationship
*
* @param int $modelId
* @return string
*/
public function defaultValue($modelId)
public function defaultValue($pivot_id)
{
return $this->defaultValues->filter(function ($item) use ($modelId) {
return $item->pivot->asset_model_id == $modelId;
})->map(function ($item) {
return $item->pivot->default_value;
})->first();
/*
below, you might think you need to add:
where('type', $this->type),
but the type can be inferred from by the custom_field itself (which also has a type)
can't use forPivot() here because we don't have an object yet. (TODO?)
*/
DefaultValuesForCustomFields::where('item_pivot_id', $pivot_id)->where('custom_field_id',$this->id)->first()?->default_value; //TODO - php8-only operator!
}
/**

View File

@@ -20,6 +20,7 @@ class CustomFieldset extends Model
*/
public $rules = [
'name' => 'required|unique:custom_fieldsets',
''
];
/**
@@ -48,11 +49,13 @@ class CustomFieldset extends Model
*
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
* @since [v3.0]
* @return \Illuminate\Database\Eloquent\Relations\Relation
* @return \Illuminate\Database\Eloquent\Collection
*/
public function models()
public function customizables() // TODO - I don't like this name, but I can't think of anything better
{
return $this->hasMany(\App\Models\AssetModel::class, 'fieldset_id');
$customizable_class_name = $this->type; //TODO - copypasta from Customizable trait?
\Log::debug("Customizable Class name is: ".$customizable_class_name);
return $customizable_class_name::getFieldsetUsers($this->id);
}
/**
@@ -77,6 +80,7 @@ class CustomFieldset extends Model
*/
public function validation_rules()
{
\Log::debug("CALLING validation_rules FOR customfiledsets!");
$rules = [];
foreach ($this->fields as $field) {
$rule = [];
@@ -90,7 +94,12 @@ class CustomFieldset extends Model
$rule[] = 'unique_undeleted';
}
array_push($rule, $field->attributes['format']);
\Log::debug("Field Format for".$field->name." is: ".$field->format);
if($field->format == 'DATE') { //we do a weird mutator thing, it's confusing - but, yes, it's all-caps
$rule[] = 'date_format:Y-m-d';
} else {
array_push($rule, $field->attributes['format']);
}
$rules[$field->db_column_name()] = $rule;
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Watson\Validating\ValidatingTrait;
class DefaultValuesForCustomFields extends Model
{
use HasFactory, ValidatingTrait;
protected $rules = [
'type' => 'required'
];
public $timestamps = false;
public function field() {
return $this->belongsTo('custom_fields');
}
// There is, effectively, another 'relation' here, but it's weirdly polymorphic
// and impossible to represent in Laravel.
// we have a 'type', and we have an 'item_pivot_id' -
// For example, in Assets the 'type' would be App\Models\Asset, and the 'item_pivot_id' would be a model_id
// I can't come up with any way to represent this in Laravel/Eloquent
// TODO: might be getting overly-fancy here; maybe just want to do an ID? Instead of an Eloquent Model?
public function scopeForPivot(Builder $query, Model $item, string $class) {
return $query->where('item_pivot_id', $item->id)->where('type', $class);
}
}

View File

@@ -43,6 +43,8 @@ class Department extends SnipeModel
protected $fillable = [
'user_id',
'name',
'phone',
'fax',
'location_id',
'company_id',
'manager_id',
@@ -56,7 +58,7 @@ class Department extends SnipeModel
*
* @var array
*/
protected $searchableAttributes = ['name', 'notes'];
protected $searchableAttributes = ['name', 'notes', 'phone', 'fax'];
/**
* The relations and their attributes that should be included when searching the model.

View File

@@ -68,7 +68,7 @@ class Depreciable extends SnipeModel
*/
public function getLinearDepreciatedValue() // TODO - for testing it might be nice to have an optional $relative_to param here, defaulted to 'now'
{
if ($this->purchase_date) {
if (($this->get_depreciation()) && ($this->purchase_date)) {
$months_passed = ($this->purchase_date->diff(now())->m)+($this->purchase_date->diff(now())->y*12);
} else {
return null;
@@ -127,7 +127,7 @@ class Depreciable extends SnipeModel
$yearsPast = 0;
}
return round($yearsPast / $deprecationYears * $this->purchase_cost, 2);
return $this->purchase_cost - round($yearsPast / $deprecationYears * $this->purchase_cost, 2);
}
/**

View File

@@ -0,0 +1,234 @@
<?php
namespace App\Models\Labels;
use App\Helpers\Helper;
use App\Models\Setting;
class DefaultLabel extends RectangleSheet
{
private const BARCODE1D_SIZE = 0.15;
private const BARCODE2D_SIZE = 0.76;
private const BARCODE2D_MARGIN = 0.075;
private const LOGO_SIZE = [0.75, 0.50];
private const LOGO_MARGIN = 0.05;
private const TEXT_MARGIN = 0.04;
private float $textSize;
private float $labelWidth;
private float $labelHeight;
private float $labelSpacingH;
private float $labelSpacingV;
private float $pageMarginTop;
private float $pageMarginBottom;
private float $pageMarginLeft;
private float $pageMarginRight;
private float $pageWidth;
private float $pageHeight;
private int $columns;
private int $rows;
public function __construct() {
$settings = Setting::getSettings();
$this->textSize = Helper::convertUnit($settings->labels_fontsize, 'pt', 'in');
$this->labelWidth = $settings->labels_width;
$this->labelHeight = $settings->labels_height;
$this->labelSpacingH = $settings->labels_display_sgutter;
$this->labelSpacingV = $settings->labels_display_bgutter;
$this->pageMarginTop = $settings->labels_pmargin_top;
$this->pageMarginBottom = $settings->labels_pmargin_bottom;
$this->pageMarginLeft = $settings->labels_pmargin_left;
$this->pageMarginRight = $settings->labels_pmargin_right;
$this->pageWidth = $settings->labels_pagewidth;
$this->pageHeight = $settings->labels_pageheight;
$usableWidth = $this->pageWidth - $this->pageMarginLeft - $this->pageMarginRight;
$usableHeight = $this->pageHeight - $this->pageMarginTop - $this->pageMarginBottom;
$this->columns = ($usableWidth + $this->labelSpacingH) / ($this->labelWidth + $this->labelSpacingH);
$this->rows = ($usableHeight + $this->labelSpacingV) / ($this->labelHeight + $this->labelSpacingV);
// Make sure the columns and rows are never zero, since that scenario should never happen
if ($this->columns == 0) {
$this->columns = 1;
}
if ($this->rows == 0) {
$this->rows = 1;
}
}
public function getUnit() { return 'in'; }
public function getPageWidth() { return $this->pageWidth; }
public function getPageHeight() { return $this->pageHeight; }
public function getPageMarginTop() { return $this->pageMarginTop; }
public function getPageMarginBottom() { return $this->pageMarginBottom; }
public function getPageMarginLeft() { return $this->pageMarginLeft; }
public function getPageMarginRight() { return $this->pageMarginRight; }
public function getColumns() { return $this->columns; }
public function getRows() { return $this->rows; }
public function getLabelBorder() { return 0; }
public function getLabelWidth() { return $this->labelWidth; }
public function getLabelHeight() { return $this->labelHeight; }
public function getLabelMarginTop() { return 0; }
public function getLabelMarginBottom() { return 0; }
public function getLabelMarginLeft() { return 0; }
public function getLabelMarginRight() { return 0; }
public function getLabelColumnSpacing() { return $this->labelSpacingH; }
public function getLabelRowSpacing() { return $this->labelSpacingV; }
public function getSupportAssetTag() { return false; }
public function getSupport1DBarcode() { return true; }
public function getSupport2DBarcode() { return true; }
public function getSupportFields() { return 4; }
public function getSupportTitle() { return true; }
public function getSupportLogo() { return true; }
public function preparePDF($pdf) {}
public function write($pdf, $record) {
$asset = $record->get('asset');
$settings = Setting::getSettings();
$textY = 0;
$textX1 = 0;
$textX2 = $this->getLabelWidth();
// 1D Barcode
if ($record->get('barcode1d')) {
static::write1DBarcode(
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
0.05, $this->getLabelHeight() - self::BARCODE1D_SIZE,
$this->getLabelWidth() - 0.1, self::BARCODE1D_SIZE
);
}
// 2D Barcode
if ($record->get('barcode2d')) {
static::write2DBarcode(
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
0, 0, self::BARCODE2D_SIZE, self::BARCODE2D_SIZE
);
$textX1 += self::BARCODE2D_SIZE + self::BARCODE2D_MARGIN;
}
// Logo
if ($record->get('logo')) {
$logoSize = static::writeImage(
$pdf, $record->get('logo'),
$this->labelWidth - self::LOGO_SIZE[0], 0,
self::LOGO_SIZE[0], self::LOGO_SIZE[1],
'R', 'T', 300, true, false, 0
);
$textX2 -= ($logoSize[0] + self::LOGO_MARGIN);
}
$textW = $textX2 - $textX1;
// Title
if ($record->get('title')) {
static::writeText(
$pdf, $record->get('title'),
$textX1, 0,
'freesans', 'b', $this->textSize, 'L',
$textW, $this->textSize,
true, 0
);
$textY += $this->textSize + self::TEXT_MARGIN;
}
// Fields
$fieldsDone = 0;
if ($settings->labels_display_name && $fieldsDone < $this->getSupportFields()) {
if ($asset->name) {
static::writeText(
$pdf, 'N: '.$asset->name,
$textX1, $textY,
'freesans', '', $this->textSize, 'L',
$textW, $this->textSize,
true, 0
);
$textY += $this->textSize + self::TEXT_MARGIN;
$fieldsDone++;
}
}
if ($settings->labels_display_company_name && $fieldsDone < $this->getSupportFields()) {
if ($asset->company) {
static::writeText(
$pdf, 'C: '.$asset->company->name,
$textX1, $textY,
'freesans', '', $this->textSize, 'L',
$textW, $this->textSize,
true, 0
);
$textY += $this->textSize + self::TEXT_MARGIN;
$fieldsDone++;
}
}
if ($settings->labels_display_tag && $fieldsDone < $this->getSupportFields()) {
if ($asset->asset_tag) {
static::writeText(
$pdf, 'T: '.$asset->asset_tag,
$textX1, $textY,
'freesans', '', $this->textSize, 'L',
$textW, $this->textSize,
true, 0
);
$textY += $this->textSize + self::TEXT_MARGIN;
$fieldsDone++;
}
}
if ($settings->labels_display_serial && $fieldsDone < $this->getSupportFields()) {
if ($asset->serial) {
static::writeText(
$pdf, 'S: '.$asset->serial,
$textX1, $textY,
'freesans', '', $this->textSize, 'L',
$textW, $this->textSize,
true, 0
);
$textY += $this->textSize + self::TEXT_MARGIN;
$fieldsDone++;
}
}
if ($settings->labels_display_model && $fieldsDone < $this->getSupportFields()) {
if ($asset->model) {
static::writeText(
$pdf, 'M: '.$asset->model->name,
$textX1, $textY,
'freesans', '', $this->textSize, 'L',
$textW, $this->textSize,
true, 0
);
$textY += $this->textSize + self::TEXT_MARGIN;
$fieldsDone++;
}
}
}
}
?>

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models\Labels;
use App\Models\Asset;
use Illuminate\Support\Collection;
class Field {
protected Collection $options;
public function getOptions() { return $this->options; }
public function setOptions($options) {
$tempCollect = collect($options);
if (!$tempCollect->contains(fn($o) => !is_subclass_of($o, FieldOption::class))) {
$this->options = $options;
}
}
public function toArray(Asset $asset) { return Field::makeArray($this, $asset); }
/* Statics */
public static function makeArray(Field $field, Asset $asset) {
return $field->getOptions()
->map(fn($option) => $option->toArray($asset))
->filter(fn($result) => $result['value'] != null);
}
public static function makeString(Field $option) {
return implode('|', $option->getOptions());
}
public static function fromString(string $theString) {
$field = new Field();
$field->options = collect(explode('|', $theString))
->filter(fn($optionString) => !empty($optionString))
->map(fn($optionString) => FieldOption::fromString($optionString));
return $field;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Models\Labels;
use App\Models\Asset;
use Illuminate\Support\Collection;
class FieldOption {
protected string $label;
public function getLabel() { return $this->label; }
protected string $dataSource;
public function getDataSource() { return $this->dataSource; }
public function getValue(Asset $asset) {
$dataPath = collect(explode('.', $this->dataSource));
return $dataPath->reduce(function ($myValue, $path) {
try { return $myValue ? $myValue->{$path} : ${$myValue}; }
catch (\Exception $e) { return $myValue; }
}, $asset);
}
public function toArray(Asset $asset=null) { return FieldOption::makeArray($this, $asset); }
public function toString() { return FieldOption::makeString($this); }
/* Statics */
public static function makeArray(FieldOption $option, Asset $asset=null) {
return [
'label' => $option->getLabel(),
'dataSource' => $option->getDataSource(),
'value' => $asset ? $option->getValue($asset) : null
];
}
public static function makeString(FieldOption $option) {
return $option->getLabel() . '=' . $option->getDataSource();
}
public static function fromString(string $theString) {
$parts = explode('=', $theString);
if (count($parts) == 2) {
$option = new FieldOption();
$option->label = $parts[0];
$option->dataSource = $parts[1];
return $option;
}
}
}

602
app/Models/Labels/Label.php Normal file
View File

@@ -0,0 +1,602 @@
<?php
namespace App\Models\Labels;
use App\Helpers\Helper;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use TCPDF;
use TCPDF_STATIC;
/**
* Model for Labels.
*
* @version v1.0
*/
abstract class Label
{
/**
* Returns the unit of measure used
* 'pt', 'mm', 'cm', 'in'
*
* @return string
*/
public abstract function getUnit();
/**
* Returns the label's width in getUnit() units
*
* @return float
*/
public abstract function getWidth();
/**
* Returns the label's height in getUnit() units
*
* @return float
*/
public abstract function getHeight();
/**
* Returns the label's top margin in getUnit() units
*
* @return float
*/
public abstract function getMarginTop();
/**
* Returns the label's bottom margin in getUnit() units
*
* @return float
*/
public abstract function getMarginBottom();
/**
* Returns the label's left margin in getUnit() units
*
* @return float
*/
public abstract function getMarginLeft();
/**
* Returns the label's right margin in getUnit() units
*
* @return float
*/
public abstract function getMarginRight();
/**
* Returns whether the template supports an asset tag.
*
* @return bool
*/
public abstract function getSupportAssetTag();
/**
* Returns whether the template supports a 1D barcode.
*
* @return bool
*/
public abstract function getSupport1DBarcode();
/**
* Returns whether the template supports a 2D barcode.
*
* @return bool
*/
public abstract function getSupport2DBarcode();
/**
* Returns the number of fields the template supports.
*
* @return int
*/
public abstract function getSupportFields();
/**
* Returns whether the template supports a logo.
*
* @return bool
*/
public abstract function getSupportLogo();
/**
* Returns whether the template supports a title.
*
* @return bool
*/
public abstract function getSupportTitle();
/**
* Make changes to the PDF properties here. OPTIONAL.
*
* @param TCPDF $pdf The TCPDF instance
*/
public abstract function preparePDF(TCPDF $pdf);
/**
* Write single data record as content here.
*
* @param TCPDF $pdf The TCPDF instance
* @param Collection $record A data record
*/
public abstract function write(TCPDF $pdf, Collection $record);
/**
* Handle the data here. Override for multiple-per-page handling
*
* @param TCPDF $pdf The TCPDF instance
* @param Collection $data The data
*/
public function writeAll(TCPDF $pdf, Collection $data) {
$data->each(function ($record, $index) use ($pdf) {
$pdf->AddPage();
$this->write($pdf, $record);
});
}
/**
* Returns the qualified class name relative to the Label class's namespace.
*
* @return string
*/
public final function getName() {
$refClass = new \ReflectionClass(Label::class);
return str_replace($refClass->getNamespaceName() . '\\', '', get_class($this));
}
/**
* Returns the label's orientation as a string.
* 'L' = Landscape
* 'P' = Portrait
*
* @return string
*/
public final function getOrientation() {
return ($this->getWidth() >= $this->getHeight()) ? 'L' : 'P';
}
/**
* Returns the label's printable area as an object.
*
* @return object [ 'x1'=>0.00, 'y1'=>0.00, 'x2'=>0.00, 'y2'=>0.00, 'w'=>0.00, 'h'=>0.00 ]
*/
public final function getPrintableArea() {
return (object)[
'x1' => $this->getMarginLeft(),
'y1' => $this->getMarginTop(),
'x2' => $this->getWidth() - $this->getMarginRight(),
'y2' => $this->getHeight() - $this->getMarginBottom(),
'w' => $this->getWidth() - $this->getMarginLeft() - $this->getMarginRight(),
'h' => $this->getHeight() - $this->getMarginTop() - $this->getMarginBottom(),
];
}
/**
* Write a text cell.
*
* @param TCPDF $pdf The TCPDF instance
* @param string $text The text to write. Supports 'some **bold** text'.
* @param float $x X position of top-left
* @param float $y Y position of top-left
* @param string $font The font family
* @param string $style The font style
* @param int $size The font size in getUnit() units
* @param string $align Align text in the box. 'L' left, 'R' right, 'C' center.
* @param float $width Force text box width. NULL to auto-fit.
* @param float $height Force text box height. NULL to auto-fit.
* @param bool $squash Squash text if it's too big
* @param int $border Thickness of border. Default = 0.
* @param int $spacing Letter spacing. Default = 0.
*/
public final function writeText(TCPDF $pdf, $text, $x, $y, $font=null, $style=null, $size=null, $align='L', $width=null, $height=null, $squash=false, $border=0, $spacing=0) {
$prevFamily = $pdf->getFontFamily();
$prevStyle = $pdf->getFontStyle();
$prevSizePt = $pdf->getFontSizePt();
$text = !empty($text) ? $text : '';
$fontFamily = !empty($font) ? $font : $prevFamily;
$fontStyle = !empty($style) ? $style : $prevStyle;
if ($size) $fontSizePt = Helper::convertUnit($size, $this->getUnit(), 'pt', true);
else $fontSizePt = $prevSizePt;
$pdf->SetFontSpacing($spacing);
$parts = collect(explode('**', $text))
->map(function ($part, $index) use ($pdf, $fontFamily, $fontStyle, $fontSizePt) {
$modStyle = ($index % 2 == 1) ? 'B' : $fontStyle;
$pdf->setFont($fontFamily, $modStyle, $fontSizePt);
return [
'text' => $part,
'text_width' => $pdf->GetStringWidth($part),
'font_family' => $fontFamily,
'font_style' => $modStyle,
'font_size' => $fontSizePt,
];
});
$textWidth = $parts->reduce(function ($carry, $part) { return $carry += $part['text_width']; });
$cellWidth = !empty($width) ? $width : $textWidth;
if ($squash && ($textWidth > 0)) {
$scaleFactor = min(1.0, $cellWidth / $textWidth);
$parts = $parts->map(function ($part, $index) use ($scaleFactor) {
$part['text_width'] = $part['text_width'] * $scaleFactor;
return $part;
});
}
$cellHeight = !empty($height) ? $height : Helper::convertUnit($fontSizePt, 'pt', $this->getUnit());
if ($border) {
$prevLineWidth = $pdf->getLineWidth();
$pdf->setLineWidth($border);
$pdf->Rect($x, $y, $cellWidth, $cellHeight);
$pdf->setLineWidth($prevLineWidth);
}
switch($align) {
case 'R': $startX = ($x + $cellWidth) - min($cellWidth, $textWidth); break;
case 'C': $startX = ($x + ($cellWidth / 2)) - (min($cellWidth, $textWidth) / 2); break;
case 'L':
default: $startX = $x; break;
}
$parts->reduce(function ($currentX, $part) use ($pdf, $y, $cellHeight) {
$pdf->SetXY($currentX, $y);
$pdf->setFont($part['font_family'], $part['font_style'], $part['font_size']);
$pdf->Cell($part['text_width'], $cellHeight, $part['text'], 0, 0, '', false, '', 1, true);
return $currentX += $part['text_width'];
}, $startX);
$pdf->SetFont($prevFamily, $prevStyle, $prevSizePt);
$pdf->SetFontSpacing(0);
}
/**
* Write an image.
*
* @param TCPDF $pdf The TCPDF instance
* @param string $image The image to write
* @param float $x X position of top-left
* @param float $y Y position of top-left
* @param float $width The container width
* @param float $height The container height
* @param string $halign Align text in the box. 'L' left, 'R' right, 'C' center. Default 'L'.
* @param string $valign Align text in the box. 'T' top, 'B' bottom, 'C' center. Default 'T'.
* @param int $dpi Pixels per inch
* @param bool $resize Resize to fit container
* @param bool $stretch Stretch (vs Scale) to fit container
* @param int $border Thickness of border. Default = 0.
*
* @return array Returns the final calculated size [w,h]
*/
public final function writeImage(TCPDF $pdf, $image, $x, $y, $width=null, $height=null, $halign='L', $valign='L', $dpi=300, $resize=false, $stretch=false, $border=0) {
if (empty($image)) return [0,0];
$imageInfo = getimagesize($image);
if (!$imageInfo) return [0,0]; // TODO: SVG or other
$imageWidthPx = $imageInfo[0];
$imageHeightPx = $imageInfo[1];
$imageType = image_type_to_extension($imageInfo[2], false);
$imageRatio = $imageWidthPx / $imageHeightPx;
$dpu = Helper::convertUnit($dpi, $this->getUnit(), 'in');
$imageWidth = $imageWidthPx / $dpu;
$imageHeight = $imageHeightPx / $dpu;
$outputWidth = $imageWidth;
$outputHeight = $imageHeight;
if ($resize) {
// Assign specified parameters
$limitWidth = $width;
$limitHeight = $height;
// If not, try calculating from the other dimension
$limitWidth = ($limitWidth > 0) ? $limitWidth : ($limitHeight / $imageRatio);
$limitHeight = ($limitHeight > 0) ? $limitHeight : ($limitWidth * $imageRatio);
// If not, just use the image size
$limitWidth = ($limitWidth > 0) ? $limitWidth : $imageWidth;
$limitHeight = ($limitHeight > 0) ? $limitHeight : $imageHeight;
$scaleWidth = $limitWidth / $imageWidth;
$scaleHeight = $limitHeight / $imageHeight;
// If non-stretch, make both scales factors equal
if (!$stretch) {
// Do we need to scale down at all? That's most important.
if (($scaleWidth < 1.0) || ($scaleHeight < 1.0)) {
// Choose largest scale-down
$scaleWidth = min($scaleWidth, $scaleHeight);
} else {
// Choose smallest scale-up
$scaleWidth = min(max($scaleWidth, 1.0), max($scaleHeight, 1.0));
}
$scaleHeight = $scaleWidth;
}
$outputWidth = $imageWidth * $scaleWidth;
$outputHeight = $imageHeight * $scaleHeight;
}
// Container
$containerWidth = !empty($width) ? $width : $outputWidth;
$containerHeight = !empty($height) ? $height : $outputHeight;
// Horizontal Position
switch ($halign) {
case 'R': $originX = ($x + $containerWidth) - $outputWidth; break;
case 'C': $originX = ($x + ($containerWidth / 2)) - ($outputWidth / 2); break;
case 'L':
default: $originX = $x; break;
}
// Vertical Position
switch ($valign) {
case 'B': $originY = ($y + $containerHeight) - $outputHeight; break;
case 'C': $originY = ($y + ($containerHeight / 2)) - ($outputHeight / 2); break;
case 'T':
default: $originY = $y; break;
}
// Actual Image
$pdf->Image($image, $originX, $originY, $outputWidth, $outputHeight, $imageType, '', '', true);
// Border
if ($border) {
$prevLineWidth = $pdf->getLineWidth();
$pdf->setLineWidth($border);
$pdf->Rect($x, $y, $containerWidth, $containerHeight);
$pdf->setLineWidth($prevLineWidth);
}
return [ $outputWidth, $outputHeight ];
}
/**
* Write a 1D barcode.
*
* @param TCPDF $pdf The TCPDF instance
* @param string $value The barcode content
* @param string $type The barcode type
* @param float $x X position of top-left
* @param float $y Y position of top-left
* @param float $width The container width
* @param float $height The container height
*/
public final function write1DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width, $height) {
if (empty($value)) return;
try {
$pdf->write1DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch'=>true]);
} catch (\Exception $e) {
\Log::error('The 1D barcode ' . $value . ' is not compliant with the barcode type '. $type);
}
}
/**
* Write a 2D barcode.
*
* @param TCPDF $pdf The TCPDF instance
* @param string $value The barcode content
* @param string $type The barcode type
* @param float $x X position of top-left
* @param float $y Y position of top-left
* @param float $width The container width
* @param float $height The container height
*/
public final function write2DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width, $height) {
if (empty($value)) return;
$pdf->write2DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch'=>true]);
}
/**
* Checks the template is internally valid
*/
public final function validate() {
$this->validateUnits();
$this->validateSize();
$this->validateMargins();
$this->validateSupport();
}
private function validateUnits() {
$validUnits = [ 'pt', 'mm', 'cm', 'in' ];
$unit = $this->getUnit();
if (!in_array(strtolower($unit), $validUnits)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_value', [
'name' => 'getUnit()',
'expected' => '[ \''.implode('\', \'', $validUnits).'\' ]',
'actual' => '\''.$unit.'\''
]));
}
}
private function validateSize() {
$width = $this->getWidth();
if (!is_numeric($width) || is_string($width)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
'name' => 'getWidth()',
'expected' => 'float',
'actual' => gettype($width)
]));
}
$height = $this->getHeight();
if (!is_numeric($height) || is_string($height)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
'name' => 'getHeight()',
'expected' => 'float',
'actual' => gettype($height)
]));
}
}
private function validateMargins() {
$marginTop = $this->getMarginTop();
if (!is_numeric($marginTop) || is_string($marginTop)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
'name' => 'getMarginTop()',
'expected' => 'float',
'actual' => gettype($marginTop)
]));
}
$marginBottom = $this->getMarginBottom();
if (!is_numeric($marginBottom) || is_string($marginBottom)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
'name' => 'getMarginBottom()',
'expected' => 'float',
'actual' => gettype($marginBottom)
]));
}
$marginLeft = $this->getMarginLeft();
if (!is_numeric($marginLeft) || is_string($marginLeft)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
'name' => 'getMarginLeft()',
'expected' => 'float',
'actual' => gettype($marginLeft)
]));
}
$marginRight = $this->getMarginRight();
if (!is_numeric($marginRight) || is_string($marginRight)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
'name' => 'getMarginRight()',
'expected' => 'float',
'actual' => gettype($marginRight)
]));
}
}
private function validateSupport() {
$support1D = $this->getSupport1DBarcode();
if (!is_bool($support1D)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
'name' => 'getSupport1DBarcode()',
'expected' => 'boolean',
'actual' => gettype($support1D)
]));
}
$support2D = $this->getSupport2DBarcode();
if (!is_bool($support2D)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
'name' => 'getSupport2DBarcode()',
'expected' => 'boolean',
'actual' => gettype($support2D)
]));
}
$supportFields = $this->getSupportFields();
if (!is_int($supportFields)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
'name' => 'getSupportFields()',
'expected' => 'integer',
'actual' => gettype($supportFields)
]));
}
$supportLogo = $this->getSupportLogo();
if (!is_bool($supportLogo)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
'name' => 'getSupportLogo()',
'expected' => 'boolean',
'actual' => gettype($supportLogo)
]));
}
$supportTitle = $this->getSupportTitle();
if (!is_bool($supportTitle)) {
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
'name' => 'getSupportTitle()',
'expected' => 'boolean',
'actual' => gettype($supportTitle)
]));
}
}
/**
* Public Static Functions
*/
/**
* Find size of a page by its format.
*
* @param string $format Format name (eg: 'A4', 'LETTER', etc.)
* @param string $orientation 'L' for Landscape, 'P' for Portrait ('L' default)
* @param string $unit Unit of measure to return in ('mm' default)
*
* @return object (object)[ 'width' => (float)123.4, 'height' => (float)123.4 ]
*/
public static function fromFormat($format, $orientation='L', $unit='mm', $round=false) {
$size = collect(TCPDF_STATIC::getPageSizeFromFormat(strtoupper($format)))
->sort()
->map(function ($value) use ($unit) {
return Helper::convertUnit($value, 'pt', $unit);
})
->toArray();
$width = ($orientation == 'L') ? $size[1] : $size[0];
$height = ($orientation == 'L') ? $size[0] : $size[1];
return (object)[
'width' => ($round !== false) ? round($width, $round) : $width,
'height' => ($round !== false) ? round($height, $round) : $height,
];
}
/**
* Find a Label by its path (or just return them all).
*
* Unlike most Models, these are defined by their existence as non-
* abstract classes stored in Models\Labels.
*
* @param string|Arrayable|array|null $path Label path[s]
* @return Collection|Label|null
*/
public static function find($name=null) {
// Find many
if (is_array($name) || $name instanceof Arrayable) {
$labels = collect($name)
->map(function ($thisname) {
return static::find($thisname);
})
->whereNotNull();
return ($labels->count() > 0) ? $labels : null;
}
// Find one
if ($name !== null) {
return static::find()
->sole(function ($label) use ($name) {
return $label->getName() == $name;
});
}
// Find all
return collect(File::allFiles(__DIR__))
->map(function ($file) {
preg_match_all('/\/*(.+?)(?:\/|\.)/', $file->getRelativePathName(), $matches);
return __NAMESPACE__ . '\\' . implode('\\', $matches[1]);
})
->filter(function ($name) {
if (!class_exists($name)) return false;
$refClass = new \ReflectionClass($name);
if ($refClass->isAbstract()) return false;
return $refClass->isSubclassOf(Label::class);
})
->map(function ($name) {
return new $name();
});
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Models\Labels;
abstract class RectangleSheet extends Sheet
{
/**
* Returns the number of columns per sheet
*
* @return int
*/
public abstract function getColumns();
/**
* Returns the number of rows per sheet
*
* @return int
*/
public abstract function getRows();
/**
* Returns the spacing between columns
*
* @return int
*/
public abstract function getLabelColumnSpacing();
/**
* Returns the spacing between rows
*
* @return int
*/
public abstract function getLabelRowSpacing();
public function getLabelsPerPage() { return $this->getColumns() * $this->getRows(); }
public function getLabelPosition($index) {
$printIndex = $index + $this->getLabelIndexOffset();
$row = (int)($printIndex / $this->getColumns());
$col = $printIndex - ($row * $this->getColumns());
$x = $this->getPageMarginLeft() + (($this->getLabelWidth() + $this->getLabelColumnSpacing()) * $col);
$y = $this->getPageMarginTop() + (($this->getLabelHeight() + $this->getLabelRowSpacing()) * $row);
return [ $x, $y ];
}
}
?>

209
app/Models/Labels/Sheet.php Normal file
View File

@@ -0,0 +1,209 @@
<?php
namespace App\Models\Labels;
abstract class Sheet extends Label
{
protected int $indexOffset = 0;
public function getWidth() { return $this->getPageWidth(); }
public function getHeight() { return $this->getPageHeight(); }
public function getMarginTop() { return $this->getPageMarginTop(); }
public function getMarginBottom() { return $this->getPageMarginBottom(); }
public function getMarginLeft() { return $this->getPageMarginLeft(); }
public function getMarginRight() { return $this->getPageMarginRight(); }
/**
* Returns the page width in getUnit() units
*
* @return float
*/
public abstract function getPageWidth();
/**
* Returns the page height in getUnit() units
*
* @return float
*/
public abstract function getPageHeight();
/**
* Returns the page top margin in getUnit() units
*
* @return float
*/
public abstract function getPageMarginTop();
/**
* Returns the page bottom margin in getUnit() units
*
* @return float
*/
public abstract function getPageMarginBottom();
/**
* Returns the page left margin in getUnit() units
*
* @return float
*/
public abstract function getPageMarginLeft();
/**
* Returns the page right margin in getUnit() units
*
* @return float
*/
public abstract function getPageMarginRight();
/**
* Returns the page width in getUnit() units
*
* @return float
*/
public abstract function getLabelWidth();
/**
* Returns each label's height in getUnit() units
*
* @return float
*/
public abstract function getLabelHeight();
/**
* Returns each label's top margin in getUnit() units
*
* @return float
*/
public abstract function getLabelMarginTop();
/**
* Returns each label's bottom margin in getUnit() units
*
* @return float
*/
public abstract function getLabelMarginBottom();
/**
* Returns each label's left margin in getUnit() units
*
* @return float
*/
public abstract function getLabelMarginLeft();
/**
* Returns each label's right margin in getUnit() units
*
* @return float
*/
public abstract function getLabelMarginRight();
/**
* Returns the number of labels each page supports
*
* @return int
*/
public abstract function getLabelsPerPage();
/**
* Returns label position based on its index
*
* @param int $index
*
* @return array [x,y]
*/
public abstract function getLabelPosition(int $index);
/**
* Returns the border to draw around labels
*
* @return int
*/
public abstract function getLabelBorder();
/**
* Handle the data here. Override for multiple-per-page handling
*
* @param TCPDF $pdf The TCPDF instance
* @param Collection $data The data
*/
public function writeAll($pdf, $data) {
$prevPageNumber = -1;
foreach ($data->toArray() as $recordIndex => $record) {
$pageNumber = (int)($recordIndex / $this->getLabelsPerPage());
if ($pageNumber != $prevPageNumber) {
$pdf->AddPage();
$prevPageNumber = $pageNumber;
}
$pageIndex = $recordIndex - ($this->getLabelsPerPage() * $pageNumber);
$position = $this->getLabelPosition($pageIndex);
$pdf->StartTemplate();
$this->write($pdf, $data->get($recordIndex));
$template = $pdf->EndTemplate();
$pdf->printTemplate($template, $position[0], $position[1]);
if ($this->getLabelBorder()) {
$prevLineWidth = $pdf->GetLineWidth();
$borderThickness = $this->getLabelBorder();
$borderOffset = $borderThickness / 2;
$borderX = $position[0]- $borderOffset;
$borderY = $position[1] - $borderOffset;
$borderW = $this->getLabelWidth() + $borderThickness;
$borderH = $this->getLabelHeight() + $borderThickness;
$pdf->setLineWidth($borderThickness);
$pdf->Rect($borderX, $borderY, $borderW, $borderH);
$pdf->setLineWidth($prevLineWidth);
}
}
}
/**
* Returns each label's orientation as a string.
* 'L' = Landscape
* 'P' = Portrait
*
* @return string
*/
public final function getLabelOrientation() {
return ($this->getLabelWidth() >= $this->getLabelHeight()) ? 'L' : 'P';
}
/**
* Returns each label's printable area as an object.
*
* @return object [ 'x1'=>0.00, 'y1'=>0.00, 'x2'=>0.00, 'y2'=>0.00, 'w'=>0.00, 'h'=>0.00 ]
*/
public final function getLabelPrintableArea() {
return (object)[
'x1' => $this->getLabelMarginLeft(),
'y1' => $this->getLabelMarginTop(),
'x2' => $this->getLabelWidth() - $this->getLabelMarginRight(),
'y2' => $this->getLabelHeight() - $this->getLabelMarginBottom(),
'w' => $this->getLabelWidth() - $this->getLabelMarginLeft() - $this->getLabelMarginRight(),
'h' => $this->getLabelHeight() - $this->getLabelMarginTop() - $this->getLabelMarginBottom(),
];
}
/**
* Returns label index offset (skip positions)
*
* @return int
*/
public function getLabelIndexOffset() { return $this->indexOffset; }
/**
* Sets label index offset (skip positions)
*
* @param int $offset
*
*/
public function setLabelIndexOffset(int $offset) { $this->indexOffset = $offset; }
}
?>

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Models\Labels\Sheets\Avery;
use App\Helpers\Helper;
use App\Models\Labels\RectangleSheet;
abstract class L7162 extends RectangleSheet
{
private const PAPER_FORMAT = 'A4';
private const PAPER_ORIENTATION = 'P';
/* Data in pt from Word Template */
private const COLUMN1_X = 13.25;
private const COLUMN2_X = 301.25;
private const ROW1_Y = 37.00;
private const ROW2_Y = 133.00;
private const LABEL_W = 280.80;
private const LABEL_H = 96.00;
private float $pageWidth;
private float $pageHeight;
private float $pageMarginLeft;
private float $pageMarginTop;
private float $columnSpacing;
private float $rowSpacing;
private float $labelWidth;
private float $labelHeight;
public function __construct() {
$paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 0);
$this->pageWidth = $paperSize->width;
$this->pageHeight = $paperSize->height;
$this->pageMarginLeft = Helper::convertUnit(self::COLUMN1_X, 'pt', $this->getUnit());
$this->pageMarginTop = Helper::convertUnit(self::ROW1_Y, 'pt', $this->getUnit());
$columnSpacingPt = self::COLUMN2_X - self::COLUMN1_X - self::LABEL_W;
$this->columnSpacing = Helper::convertUnit($columnSpacingPt, 'pt', $this->getUnit());
$rowSpacingPt = self::ROW2_Y - self::ROW1_Y - self::LABEL_H;
$this->rowSpacing = Helper::convertUnit($rowSpacingPt, 'pt', $this->getUnit());
$this->labelWidth = Helper::convertUnit(self::LABEL_W, 'pt', $this->getUnit());
$this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
}
public function getPageWidth() { return $this->pageWidth; }
public function getPageHeight() { return $this->pageHeight; }
public function getPageMarginTop() { return $this->pageMarginTop; }
public function getPageMarginBottom() { return $this->pageMarginTop; }
public function getPageMarginLeft() { return $this->pageMarginLeft; }
public function getPageMarginRight() { return $this->pageMarginLeft; }
public function getColumns() { return 2; }
public function getRows() { return 8; }
public function getLabelColumnSpacing() { return $this->columnSpacing; }
public function getLabelRowSpacing() { return $this->rowSpacing; }
public function getLabelWidth() { return $this->labelWidth; }
public function getLabelHeight() { return $this->labelHeight; }
public function getLabelBorder() { return 0; }
}
?>

View File

@@ -0,0 +1,100 @@
<?php
namespace App\Models\Labels\Sheets\Avery;
class L7162_A extends L7162
{
private const BARCODE_MARGIN = 1.60;
private const TAG_SIZE = 4.60;
private const TITLE_SIZE = 4.20;
private const TITLE_MARGIN = 1.40;
private const LABEL_SIZE = 2.20;
private const LABEL_MARGIN = - 0.50;
private const FIELD_SIZE = 4.60;
private const FIELD_MARGIN = 0.30;
public function getUnit() { return 'mm'; }
public function getLabelMarginTop() { return 1.0; }
public function getLabelMarginBottom() { return 1.0; }
public function getLabelMarginLeft() { return 1.0; }
public function getLabelMarginRight() { return 1.0; }
public function getSupportAssetTag() { return true; }
public function getSupport1DBarcode() { return false; }
public function getSupport2DBarcode() { return true; }
public function getSupportFields() { return 4; }
public function getSupportLogo() { return false; }
public function getSupportTitle() { return true; }
public function preparePDF($pdf) {}
public function write($pdf, $record) {
$pa = $this->getLabelPrintableArea();
$usableWidth = $pa->w;
$usableHeight = $pa->h;
$currentX = $pa->x1;
$currentY = $pa->y1;
$titleShiftX = 0;
$barcodeSize = $pa->h - self::TAG_SIZE;
if ($record->has('barcode2d')) {
static::writeText(
$pdf, $record->get('tag'),
$pa->x1, $pa->y2 - self::TAG_SIZE,
'freemono', 'b', self::TAG_SIZE, 'C',
$barcodeSize, self::TAG_SIZE, true, 0
);
static::write2DBarcode(
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
$pa->x1, $pa->y1,
$barcodeSize, $barcodeSize
);
$currentX += $barcodeSize + self::BARCODE_MARGIN;
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
} else {
static::writeText(
$pdf, $record->get('tag'),
$pa->x1, $pa->y1,
'freemono', 'b', self::TITLE_SIZE, 'L',
$barcodeSize, self::TITLE_SIZE, true, 0
);
$titleShiftX = $barcodeSize;
}
if ($record->has('title')) {
static::writeText(
$pdf, $record->get('title'),
$currentX + $titleShiftX, $currentY,
'freesans', '', self::TITLE_SIZE, 'L',
$usableWidth, self::TITLE_SIZE, true, 0
);
$currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
}
foreach ($record->get('fields') as $field) {
static::writeText(
$pdf, $field['label'],
$currentX, $currentY,
'freesans', '', self::LABEL_SIZE, 'L',
$usableWidth, self::LABEL_SIZE, true, 0
);
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
static::writeText(
$pdf, $field['value'],
$currentX, $currentY,
'freemono', 'B', self::FIELD_SIZE, 'L',
$usableWidth, self::FIELD_SIZE, true, 0, 0.3
);
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
}
}
}
?>

View File

@@ -0,0 +1,103 @@
<?php
namespace App\Models\Labels\Sheets\Avery;
class L7162_B extends L7162
{
private const BARCODE_SIZE = 6.00;
private const BARCODE_MARGIN = 1.40;
private const TAG_SIZE = 3.20;
private const LOGO_MAX_WIDTH = 25.00;
private const LOGO_MARGIN = 2.20;
private const TITLE_SIZE = 4.20;
private const TITLE_MARGIN = 1.20;
private const LABEL_SIZE = 2.20;
private const LABEL_MARGIN = - 0.50;
private const FIELD_SIZE = 4.20;
private const FIELD_MARGIN = 0.30;
public function getUnit() { return 'mm'; }
public function getLabelMarginTop() { return 1.0; }
public function getLabelMarginBottom() { return 0; }
public function getLabelMarginLeft() { return 1.0; }
public function getLabelMarginRight() { return 1.0; }
public function getSupportAssetTag() { return true; }
public function getSupport1DBarcode() { return true; }
public function getSupport2DBarcode() { return false; }
public function getSupportFields() { return 3; }
public function getSupportLogo() { return true; }
public function getSupportTitle() { return true; }
public function preparePDF($pdf) {}
public function write($pdf, $record) {
$pa = $this->getLabelPrintableArea();
$usableWidth = $pa->w;
$usableHeight = $pa->h;
$currentX = $pa->x1;
$currentY = $pa->y1;
if ($record->has('barcode1d')) {
static::write1DBarcode(
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
$pa->x1, $pa->y2 - self::BARCODE_SIZE,
$usableWidth, self::BARCODE_SIZE
);
$usableHeight -= self::BARCODE_SIZE + self::BARCODE_MARGIN;
}
if ($record->has('logo')) {
$logoSize = static::writeImage(
$pdf, $record->get('logo'),
$pa->x1, $pa->y1,
self::LOGO_MAX_WIDTH, $usableHeight,
'L', 'T', 300, true, false, 0.1
);
$currentX += $logoSize[0] + self::LOGO_MARGIN;
$usableWidth -= $logoSize[0] + self::LOGO_MARGIN;
}
if ($record->has('title')) {
static::writeText(
$pdf, $record->get('title'),
$currentX, $currentY,
'freesans', '', self::TITLE_SIZE, 'L',
$usableWidth, self::TITLE_SIZE, true, 0
);
$currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
}
foreach ($record->get('fields') as $field) {
static::writeText(
$pdf, $field['label'],
$currentX, $currentY,
'freesans', '', self::LABEL_SIZE, 'L',
$usableWidth, self::LABEL_SIZE, true, 0
);
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
static::writeText(
$pdf, $field['value'],
$currentX, $currentY,
'freemono', 'B', self::FIELD_SIZE, 'L',
$usableWidth, self::FIELD_SIZE, true, 0, 0.3
);
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
}
static::writeText(
$pdf, $record->get('tag'),
$currentX, $pa->y2 - self::BARCODE_SIZE - self::BARCODE_MARGIN - self::TAG_SIZE,
'freemono', 'b', self::TAG_SIZE, 'R',
$usableWidth, self::TAG_SIZE, true, 0, 0.3
);
}
}
?>

Some files were not shown because too many files have changed in this diff Show More