mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
commit
0c02ff70f6
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -50,3 +50,4 @@ tests/_support/_generated/*
|
|||
/storage/oauth-public.key
|
||||
|
||||
*.cache
|
||||
.vagrant
|
18
Vagrantfile
vendored
18
Vagrantfile
vendored
|
@ -81,4 +81,22 @@ Vagrant.configure("2") do |config|
|
|||
fedora26.vm.provision :shell, :inline => "wget #{SNIPEIT_SH_URL}"
|
||||
fedora26.vm.provision :shell, :inline => "chmod 755 snipeit.sh"
|
||||
end
|
||||
|
||||
config.vm.define "freebsd" do |freebsd|
|
||||
freebsd.vm.box = "freebsd/FreeBSD-11.2-RELEASE"
|
||||
freebsd.vm.hostname = 'freebsd12'
|
||||
freebsd.vm.network "forwarded_port", guest: 80, host: 8080
|
||||
freebsd.vm.network "forwarded_port", guest:3306, host:3306 # mysql
|
||||
freebsd.vm.network "private_network", type: "dhcp"
|
||||
freebsd.ssh.shell = "sh"
|
||||
freebsd.vm.base_mac = "080027D14C66"
|
||||
freebsd.vm.synced_folder ".", "/vagrant", :nfs => true, id: "vagrant-root",
|
||||
:mount_options => ['rw', 'vers=3', 'tcp', 'actimeo=2']
|
||||
freebsd.vm.provision "shell", inline: <<-SHELL
|
||||
pkg install -y python27;
|
||||
SHELL
|
||||
freebsd.vm.provision "ansible" do |ansible|
|
||||
ansible.playbook = "ansible/freebsd/vagrant_playbook.yml"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
260
ansible/freebsd/vagrant_playbook.yml
Normal file
260
ansible/freebsd/vagrant_playbook.yml
Normal file
|
@ -0,0 +1,260 @@
|
|||
---
|
||||
- name: Set up local server
|
||||
hosts: all
|
||||
remote_user: vagrant
|
||||
become_user: root
|
||||
become_method: sudo
|
||||
vars:
|
||||
- ansible_python_interpreter: /usr/local/bin/python2.7
|
||||
gather_facts: no
|
||||
|
||||
# Tasks
|
||||
tasks:
|
||||
|
||||
#
|
||||
# Update the PKG database
|
||||
#
|
||||
- name: Upgrade PKG database
|
||||
raw: sudo pkg upgrade -y
|
||||
|
||||
#
|
||||
# Mount the shared folders
|
||||
#
|
||||
- name: Update Vagrant Shared Folders
|
||||
command: "{{ item }}"
|
||||
with_items:
|
||||
- sysrc rpc_lockd_enable=YES
|
||||
- sysrc rpc_statd_enable=YES
|
||||
become: true
|
||||
|
||||
#
|
||||
# Install required utilities
|
||||
#
|
||||
- name: Install Utilities
|
||||
pkgng:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
with_items:
|
||||
- openssl
|
||||
- node
|
||||
- npm
|
||||
- git
|
||||
- nano
|
||||
- wget
|
||||
- bash
|
||||
become: true
|
||||
|
||||
#
|
||||
# Install php and php dependancies
|
||||
#
|
||||
- name: Install PHP dependancies
|
||||
pkgng:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
with_items:
|
||||
- php72
|
||||
- php72-zip
|
||||
- php72-zlib
|
||||
- php72-extensions
|
||||
- php72-mbstring
|
||||
- php72-openssl
|
||||
# - php72-mysqli
|
||||
- php72-curl
|
||||
- php72-soap
|
||||
- php72-pdo_mysql
|
||||
# - php72-pdo_pgsql
|
||||
- php72-ldap
|
||||
- php72-curl
|
||||
- php72-fileinfo
|
||||
- php72-bcmath
|
||||
- php72-gd
|
||||
become: true
|
||||
|
||||
#
|
||||
# Create a php.ini file
|
||||
#
|
||||
- name: PHP INI check
|
||||
stat:
|
||||
path: /usr/local/etc/php.ini
|
||||
register: php_ini_exits
|
||||
|
||||
- name: Create PHP ini
|
||||
command: cp /usr/local/etc/php.ini-development /usr/local/etc/php.ini
|
||||
become: true
|
||||
when: not php_ini_exits.stat.exists
|
||||
|
||||
- name: Enable PHP-FPM auto-start
|
||||
command: sysrc php_fpm_enable=YES
|
||||
become: true
|
||||
|
||||
- name: Start PHP-FPM service
|
||||
service:
|
||||
name: php-fpm
|
||||
state: started
|
||||
become: true
|
||||
|
||||
#
|
||||
# Install the lastest version of composer
|
||||
#
|
||||
- name: Composer check
|
||||
stat:
|
||||
path: /usr/local/bin/composer
|
||||
register: composer_exits
|
||||
|
||||
- name: Install Composer
|
||||
shell: |
|
||||
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
|
||||
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
||||
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
|
||||
|
||||
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
|
||||
then
|
||||
>&2 echo 'ERROR: Invalid installer signature'
|
||||
rm composer-setup.php
|
||||
exit 1
|
||||
fi
|
||||
|
||||
php composer-setup.php --quiet
|
||||
RESULT=$?
|
||||
rm composer-setup.php
|
||||
mv composer.phar /usr/local/bin/composer
|
||||
exit $RESULT
|
||||
when: not composer_exits.stat.exists
|
||||
become: true
|
||||
|
||||
#
|
||||
# Install MySQL Server
|
||||
|
||||
- name: Install MySQL 5.7
|
||||
pkgng:
|
||||
name: mysql57-server
|
||||
state: present
|
||||
become: true
|
||||
register: sql_server
|
||||
|
||||
- name: Start MySQL server
|
||||
service:
|
||||
name: mysql-server
|
||||
state: started
|
||||
become: true
|
||||
|
||||
- name: MySQL 5.7 auto-start
|
||||
command: sysrc mysql_enable=YES
|
||||
become: true
|
||||
when: sql_server.changed == true
|
||||
|
||||
- name: Get MySQL root password
|
||||
command: tail -1 /root/.mysql_secret
|
||||
register: myql_root_pwd
|
||||
become: true
|
||||
when: sql_server.changed == true
|
||||
|
||||
- name: Change MySQL root password
|
||||
command: mysqladmin -u root -p'{{myql_root_pwd.stdout}}' password vagrant
|
||||
when: sql_server.changed == true
|
||||
|
||||
- name: Enable remote mysql
|
||||
replace:
|
||||
path: /usr/local/etc/mysql/my.cnf
|
||||
regexp: "127.0.0.1"
|
||||
replace: "0.0.0.0"
|
||||
become: true
|
||||
when: sql_server.changed == true
|
||||
|
||||
- name: Grant user vagrant privelages
|
||||
shell: mysql -u root -pvagrant -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'vagrant' WITH GRANT OPTION; FLUSH PRIVILEGES;"
|
||||
become: true
|
||||
when: sql_server.changed == true
|
||||
ignore_errors: true
|
||||
|
||||
- name: Restart MySQL server
|
||||
service:
|
||||
name: mysql-server
|
||||
state: restarted
|
||||
become: true
|
||||
|
||||
|
||||
#
|
||||
# Install Apache Web Server
|
||||
#
|
||||
- name: Install Apache 2.4
|
||||
pkgng:
|
||||
name: apache24
|
||||
state: present
|
||||
become: true
|
||||
register: apache24_server
|
||||
|
||||
- name: Apache 2.4 auto-start
|
||||
command: sysrc apache24_enable=YES
|
||||
become: true
|
||||
when: apache24_server.changed == true
|
||||
|
||||
- name: Enable Apache modules
|
||||
replace:
|
||||
path: /usr/local/etc/apache24/httpd.conf
|
||||
regexp: "#{{ item }}"
|
||||
replace: "{{ item }}"
|
||||
become: true
|
||||
with_items:
|
||||
- LoadModule rewrite_module libexec/apache24/mod_rewrite.so
|
||||
- LoadModule vhost_alias_module libexec/apache24/mod_vhost_alias.so
|
||||
- LoadModule deflate_module libexec/apache24/mod_deflate.so
|
||||
- LoadModule expires_module libexec/apache24/mod_expires.so
|
||||
- LoadModule mpm_worker_module libexec/apache24/mod_mpm_worker.so
|
||||
- LoadModule proxy_fcgi_module libexec/apache24/mod_proxy_fcgi.so
|
||||
- LoadModule proxy_module libexec/apache24/mod_proxy.so
|
||||
- Include etc/apache24/extra/httpd-vhosts.conf
|
||||
when: apache24_server.changed == true
|
||||
|
||||
- name: Disable Apache modules
|
||||
replace:
|
||||
path: /usr/local/etc/apache24/httpd.conf
|
||||
regexp: "{{ item }}"
|
||||
replace: "#{{ item }}"
|
||||
become: true
|
||||
with_items:
|
||||
- LoadModule mpm_prefork_module libexec/apache24/mod_mpm_prefork.so
|
||||
when: apache24_server.changed == true
|
||||
|
||||
- name: Backup vhosts
|
||||
command: cp /usr/local/etc/apache24/extra/httpd-vhosts.conf /usr/local/etc/apache24/extra/httpd-vhosts.conf.bak
|
||||
become: true
|
||||
when: apache24_server.changed == true
|
||||
|
||||
- name: Truncate vhosts
|
||||
command: truncate -s 0 /usr/local/etc/apache24/extra/httpd-vhosts.conf
|
||||
become: true
|
||||
when: apache24_server.changed == true
|
||||
|
||||
- name: Set up vhost
|
||||
blockinfile:
|
||||
path: "/usr/local/etc/apache24/extra/httpd-vhosts.conf"
|
||||
block: |
|
||||
<VirtualHost *>
|
||||
DocumentRoot /usr/local/www/apache24/data/public
|
||||
ServerName vagrant.app
|
||||
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/local/www/apache24/data/public/$1
|
||||
DirectoryIndex /index.php index.php
|
||||
<Directory /usr/local/www/apache24/data/public>
|
||||
Options -Indexes +FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
</VirtualHost>
|
||||
become: true
|
||||
when: apache24_server.changed == true
|
||||
|
||||
- name: Map apache dir to local folder
|
||||
shell: |
|
||||
if ! [ -L /var/www ]; then
|
||||
rm -rf /usr/local/www/apache24/data;
|
||||
ln -fs /vagrant /usr/local/www/apache24/data;
|
||||
fi
|
||||
become: true
|
||||
when: apache24_server.changed == true
|
||||
|
||||
- name: Start Apache 2.4 server
|
||||
service:
|
||||
name: apache24
|
||||
state: started
|
||||
become: true
|
|
@ -169,6 +169,11 @@ class LdapSync extends Command
|
|||
$item['activated'] = ( in_array($results[$i]['useraccountcontrol'][0], $enabled_accounts) ) ? 1 : 0;
|
||||
} else {
|
||||
$item['activated'] = 0;
|
||||
|
||||
// If there is no activated flag, assume this is handled via the OU and activate the users
|
||||
if (empty($ldap_result_active_flag)) {
|
||||
$item['activated'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// User exists
|
||||
|
|
|
@ -351,6 +351,8 @@ class SettingsController extends Controller
|
|||
$setting->thumbnail_max_h = $request->input('thumbnail_max_h');
|
||||
$setting->privacy_policy_link = $request->input('privacy_policy_link');
|
||||
|
||||
$setting->depreciation_method = $request->input('depreciation_method');
|
||||
|
||||
if (Input::get('per_page')!='') {
|
||||
$setting->per_page = $request->input('per_page');
|
||||
} else {
|
||||
|
|
|
@ -143,7 +143,6 @@ class UsersController extends Controller
|
|||
$user->permissions = json_encode($permissions_array);
|
||||
|
||||
if ($user->save()) {
|
||||
|
||||
if ($request->filled('groups')) {
|
||||
$user->groups()->sync($request->input('groups'));
|
||||
} else {
|
||||
|
@ -151,7 +150,7 @@ class UsersController extends Controller
|
|||
}
|
||||
|
||||
if (($request->input('email_user') == 1) && ($request->filled('email'))) {
|
||||
// Send the credentials through email
|
||||
// Send the credentials through email
|
||||
$data = array();
|
||||
$data['email'] = e($request->input('email'));
|
||||
$data['username'] = e($request->input('username'));
|
||||
|
@ -172,9 +171,9 @@ class UsersController extends Controller
|
|||
{
|
||||
$output = null;
|
||||
foreach ($permissions as $key => $permission) {
|
||||
$output[$key] = array_filter($permission, function ($p) {
|
||||
return $p['display'] === true;
|
||||
});
|
||||
$output[$key] = array_filter($permission, function ($p) {
|
||||
return $p['display'] === true;
|
||||
});
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
@ -191,9 +190,7 @@ class UsersController extends Controller
|
|||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
|
||||
if ($user = User::find($id)) {
|
||||
|
||||
$this->authorize('update', $user);
|
||||
$permissions = config('permissions');
|
||||
|
||||
|
@ -209,8 +206,6 @@ class UsersController extends Controller
|
|||
|
||||
$error = trans('admin/users/message.user_not_found', compact('id'));
|
||||
return redirect()->route('users.index')->with('error', $error);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,7 +230,6 @@ class UsersController extends Controller
|
|||
}
|
||||
|
||||
try {
|
||||
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
if ($user->id == $request->input('manager_id')) {
|
||||
|
@ -250,9 +244,6 @@ class UsersController extends Controller
|
|||
$orig_superuser = $orig_permissions_array['superuser'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return redirect()->route('users.index')
|
||||
->with('error', trans('admin/users/message.user_not_found', compact('id')));
|
||||
|
@ -273,7 +264,7 @@ class UsersController extends Controller
|
|||
$user->email = $request->input('email');
|
||||
|
||||
|
||||
// Update the user
|
||||
// Update the user
|
||||
$user->first_name = $request->input('first_name');
|
||||
$user->last_name = $request->input('last_name');
|
||||
$user->two_factor_optin = $request->input('two_factor_optin') ?: 0;
|
||||
|
@ -398,7 +389,7 @@ class UsersController extends Controller
|
|||
public function getRestore($id = null)
|
||||
{
|
||||
$this->authorize('edit', User::class);
|
||||
// Get user information
|
||||
// Get user information
|
||||
if (!$user = User::onlyTrashed()->find($id)) {
|
||||
return redirect()->route('users.index')->with('error', trans('admin/users/messages.user_not_found'));
|
||||
}
|
||||
|
@ -422,7 +413,7 @@ class UsersController extends Controller
|
|||
*/
|
||||
public function show($userId = null)
|
||||
{
|
||||
if(!$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId)) {
|
||||
if (!$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId)) {
|
||||
// Redirect to the user management page
|
||||
return redirect()->route('users.index')
|
||||
->with('error', trans('admin/users/message.user_not_found', ['id' => $userId]));
|
||||
|
@ -536,7 +527,6 @@ class UsersController extends Controller
|
|||
*/
|
||||
public function getExportUserCsv()
|
||||
{
|
||||
|
||||
$this->authorize('view', User::class);
|
||||
\Debugbar::disable();
|
||||
|
||||
|
@ -544,76 +534,74 @@ class UsersController extends Controller
|
|||
// Open output stream
|
||||
$handle = fopen('php://output', 'w');
|
||||
|
||||
User::with('assets', 'accessories', 'consumables', 'department', 'licenses', 'manager', 'groups', 'userloc', 'company','throttle')
|
||||
User::with('assets', 'accessories', 'consumables', 'department', 'licenses', 'manager', 'groups', 'userloc', 'company')
|
||||
->orderBy('created_at', 'DESC')
|
||||
->chunk(500, function($users) use($handle) {
|
||||
$headers=[
|
||||
// strtolower to prevent Excel from trying to open it as a SYLK file
|
||||
strtolower(trans('general.id')),
|
||||
trans('admin/companies/table.title'),
|
||||
trans('admin/users/table.title'),
|
||||
trans('admin/users/table.employee_num'),
|
||||
trans('admin/users/table.name'),
|
||||
trans('admin/users/table.username'),
|
||||
trans('admin/users/table.email'),
|
||||
trans('admin/users/table.manager'),
|
||||
trans('admin/users/table.location'),
|
||||
trans('general.department'),
|
||||
trans('general.assets'),
|
||||
trans('general.licenses'),
|
||||
trans('general.accessories'),
|
||||
trans('general.consumables'),
|
||||
trans('admin/users/table.groups'),
|
||||
trans('general.notes'),
|
||||
trans('admin/users/table.activated'),
|
||||
trans('general.created_at')
|
||||
];
|
||||
|
||||
fputcsv($handle, $headers);
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user_groups = '';
|
||||
|
||||
foreach ($user->groups as $user_group) {
|
||||
$user_groups .= $user_group->name.', ';
|
||||
}
|
||||
|
||||
// Add a new row with data
|
||||
$values = [
|
||||
$user->id,
|
||||
($user->company) ? $user->company->name : '',
|
||||
$user->jobtitle,
|
||||
$user->employee_num,
|
||||
$user->present()->fullName(),
|
||||
$user->username,
|
||||
$user->email,
|
||||
($user->manager) ? $user->manager->present()->fullName() : '',
|
||||
($user->userloc) ? $user->userloc->name : '',
|
||||
($user->department) ? $user->department->name : '',
|
||||
$user->assets->count(),
|
||||
$user->licenses->count(),
|
||||
$user->accessories->count(),
|
||||
$user->consumables->count(),
|
||||
$user_groups,
|
||||
$user->notes,
|
||||
($user->activated=='1') ? trans('general.yes') : trans('general.no'),
|
||||
$user->created_at,
|
||||
|
||||
->chunk(500, function ($users) use ($handle) {
|
||||
$headers=[
|
||||
// strtolower to prevent Excel from trying to open it as a SYLK file
|
||||
strtolower(trans('general.id')),
|
||||
trans('admin/companies/table.title'),
|
||||
trans('admin/users/table.title'),
|
||||
trans('admin/users/table.employee_num'),
|
||||
trans('admin/users/table.name'),
|
||||
trans('admin/users/table.username'),
|
||||
trans('admin/users/table.email'),
|
||||
trans('admin/users/table.manager'),
|
||||
trans('admin/users/table.location'),
|
||||
trans('general.department'),
|
||||
trans('general.assets'),
|
||||
trans('general.licenses'),
|
||||
trans('general.accessories'),
|
||||
trans('general.consumables'),
|
||||
trans('admin/users/table.groups'),
|
||||
trans('general.notes'),
|
||||
trans('admin/users/table.activated'),
|
||||
trans('general.created_at')
|
||||
];
|
||||
|
||||
fputcsv($handle, $values);
|
||||
}
|
||||
});
|
||||
fputcsv($handle, $headers);
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user_groups = '';
|
||||
|
||||
foreach ($user->groups as $user_group) {
|
||||
$user_groups .= $user_group->name.', ';
|
||||
}
|
||||
|
||||
// Add a new row with data
|
||||
$values = [
|
||||
$user->id,
|
||||
($user->company) ? $user->company->name : '',
|
||||
$user->jobtitle,
|
||||
$user->employee_num,
|
||||
$user->present()->fullName(),
|
||||
$user->username,
|
||||
$user->email,
|
||||
($user->manager) ? $user->manager->present()->fullName() : '',
|
||||
($user->userloc) ? $user->userloc->name : '',
|
||||
($user->department) ? $user->department->name : '',
|
||||
$user->assets->count(),
|
||||
$user->licenses->count(),
|
||||
$user->accessories->count(),
|
||||
$user->consumables->count(),
|
||||
$user_groups,
|
||||
$user->notes,
|
||||
($user->activated=='1') ? trans('general.yes') : trans('general.no'),
|
||||
$user->created_at,
|
||||
];
|
||||
|
||||
fputcsv($handle, $values);
|
||||
}
|
||||
});
|
||||
|
||||
// Close the output stream
|
||||
fclose($handle);
|
||||
}, 200, [
|
||||
'Content-Type' => 'text/csv',
|
||||
'Content-Type' => 'text/csv; charset=UTF-8',
|
||||
'Content-Disposition' => 'attachment; filename="users-'.date('Y-m-d-his').'.csv"',
|
||||
]);
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -625,8 +613,7 @@ class UsersController extends Controller
|
|||
*/
|
||||
public function printInventory($id)
|
||||
{
|
||||
|
||||
$show_user = User::where('id',$id)->withTrashed()->first();
|
||||
$show_user = User::where('id', $id)->withTrashed()->first();
|
||||
$assets = Asset::where('assigned_to', $id)->where('assigned_type', User::class)->with('model', 'model.category')->get();
|
||||
$accessories = $show_user->accessories()->get();
|
||||
$consumables = $show_user->consumables()->get();
|
||||
|
@ -635,7 +622,5 @@ class UsersController extends Controller
|
|||
->with('accessories', $accessories)
|
||||
->with('consumables', $consumables)
|
||||
->with('show_user', $show_user);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,29 @@ class Depreciable extends SnipeModel
|
|||
if ($this->get_depreciation()->months <= 0) {
|
||||
return $this->purchase_cost;
|
||||
}
|
||||
$depreciation = 0;
|
||||
$setting = Setting::first();
|
||||
switch($setting->depreciation_method) {
|
||||
case 'half_1':
|
||||
$depreciation = $this->getHalfYearDepreciatedValue(true);
|
||||
break;
|
||||
|
||||
case 'half_2':
|
||||
$depreciation = $this->getHalfYearDepreciatedValue(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
$depreciation = $this->getLinearDepreciatedValue();
|
||||
}
|
||||
return $depreciation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float|int
|
||||
*/
|
||||
|
||||
public function getLinearDepreciatedValue()
|
||||
{
|
||||
// fraction of value left
|
||||
$months_remaining = $this->time_until_depreciated()->m + 12*$this->time_until_depreciated()->y; //UGlY
|
||||
$current_value = round(($months_remaining/ $this->get_depreciation()->months) * $this->purchase_cost, 2);
|
||||
|
@ -60,6 +82,62 @@ class Depreciable extends SnipeModel
|
|||
return $current_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param onlyHalfFirstYear Boolean always applied only second half of the first year
|
||||
* @return float|int
|
||||
*/
|
||||
public function getHalfYearDepreciatedValue($onlyHalfFirstYear = false)
|
||||
{
|
||||
// @link http://www.php.net/manual/en/class.dateinterval.php
|
||||
$current_date = $this->getDateTime();
|
||||
$purchase_date = date_create($this->purchase_date);
|
||||
$currentYear = $this->get_fiscal_year( $current_date );
|
||||
$purchaseYear = $this->get_fiscal_year( $purchase_date );
|
||||
$yearsPast = $currentYear - $purchaseYear;
|
||||
$deprecationYears = ceil($this->get_depreciation()->months / 12);
|
||||
if( $onlyHalfFirstYear ) {
|
||||
$yearsPast -= 0.5;
|
||||
}
|
||||
else if( !$this->is_first_half_of_year($purchase_date) ) {
|
||||
$yearsPast -= 0.5;
|
||||
}
|
||||
if( !$this->is_first_half_of_year($current_date) ) {
|
||||
$yearsPast += 0.5;
|
||||
}
|
||||
|
||||
if($yearsPast >= $deprecationYears) {
|
||||
$yearsPast = $deprecationYears;
|
||||
}
|
||||
else if($yearsPast < 0) {
|
||||
$yearsPast = 0;
|
||||
}
|
||||
return round($yearsPast / $deprecationYears * $this->purchase_cost, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $date
|
||||
* @return int
|
||||
*/
|
||||
protected function get_fiscal_year($date) {
|
||||
$year = intval($date->format('Y'));
|
||||
// also, maybe it'll have to set fiscal year date
|
||||
if($date->format('nj') === '1231') {
|
||||
return $year;
|
||||
}
|
||||
else {
|
||||
return $year - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $date
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_first_half_of_year($date) {
|
||||
$date0m0d = intval($date->format('md'));
|
||||
return ($date0m0d < 601) || ($date0m0d >= 1231);
|
||||
}
|
||||
|
||||
public function time_until_depreciated()
|
||||
{
|
||||
// @link http://www.php.net/manual/en/class.datetime.php
|
||||
|
@ -81,4 +159,10 @@ class Depreciable extends SnipeModel
|
|||
date_add($date, date_interval_create_from_date_string($this->get_depreciation()->months . ' months'));
|
||||
return $date; //date_format($date, 'Y-m-d'); //don't bake-in format, for internationalization
|
||||
}
|
||||
|
||||
// it's necessary for unit tests
|
||||
protected function getDateTime($time = null)
|
||||
{
|
||||
return new \DateTime($time);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,6 +139,10 @@ class AuthServiceProvider extends ServiceProvider
|
|||
return $user->hasAccess('self.edit_location');
|
||||
});
|
||||
|
||||
Gate::define('self.checkout_assets', function($user) {
|
||||
return $user->hasAccess('self.checkout_assets');
|
||||
});
|
||||
|
||||
Gate::define('backend.interact', function ($user) {
|
||||
return $user->can('view', Statuslabel::class)
|
||||
|| $user->can('view', AssetModel::class)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"name": "snipe/snipe-it",
|
||||
"description": "Open source asset management system built on Laravel.",
|
||||
"keywords": ["assets", "asset-management", "laravel"],
|
||||
"license": "AGPL-3",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"php": ">=7.1.3",
|
||||
|
|
|
@ -578,6 +578,13 @@ return array(
|
|||
'display' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'permission' => 'self.checkout_assets',
|
||||
'label' => 'Self-Checkout',
|
||||
'note' => 'This user may check out assets that are marked for self-checkout.',
|
||||
'display' => true,
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddDepreciationOptionToSettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->char('depreciation_method', 10)->nullable()->default('default');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->dropColumn('depreciation_method');
|
||||
});
|
||||
}
|
||||
}
|
8139
npm-shrinkwrap.json
generated
8139
npm-shrinkwrap.json
generated
File diff suppressed because it is too large
Load diff
|
@ -14,7 +14,7 @@
|
|||
"babel-preset-latest": "^6.24.1",
|
||||
"cross-env": "^5.0.5",
|
||||
"jquery": "^3.1.1",
|
||||
"laravel-mix": "2.1",
|
||||
"laravel-mix": "^2.1.14",
|
||||
"lodash": "^4.17.4",
|
||||
"vue": "2.4.4",
|
||||
"vue-loader": "^13.6.1",
|
||||
|
@ -22,6 +22,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "^5.2.0",
|
||||
"ajv": "^6.5.3",
|
||||
"blueimp-file-upload": "^9.18.0",
|
||||
"bootstrap": "^3.3.7",
|
||||
"bootstrap-colorpicker": "^2.5.1",
|
||||
|
@ -30,6 +31,7 @@
|
|||
"ekko-lightbox": "^5.1.1",
|
||||
"font-awesome": "^4.7.0",
|
||||
"icheck": "^1.0.2",
|
||||
"imagemin": "^5.3.1",
|
||||
"jquery-slimscroll": "^1.3.8",
|
||||
"jquery-ui": "^1.12.1",
|
||||
"jquery-ui-bundle": "^1.12.1",
|
||||
|
|
|
@ -19,6 +19,7 @@ return array(
|
|||
'status' => 'status',
|
||||
'title' => 'bate',
|
||||
'image' => 'Toestelbeeld',
|
||||
'days_without_acceptance' => 'Dae sonder aanvaarding'
|
||||
'days_without_acceptance' => 'Dae sonder aanvaarding',
|
||||
'monthly_depreciation' => 'Maandelikse Waardevermindering'
|
||||
|
||||
);
|
||||
|
|
|
@ -19,6 +19,7 @@ return array(
|
|||
'status' => 'Status',
|
||||
'title' => 'Asset ',
|
||||
'image' => 'Device Image',
|
||||
'days_without_acceptance' => 'Days Without Acceptance'
|
||||
'days_without_acceptance' => 'Days Without Acceptance',
|
||||
'monthly_depreciation' => 'Monthly Depreciation'
|
||||
|
||||
);
|
||||
|
|
|
@ -19,6 +19,7 @@ return array(
|
|||
'status' => 'Status',
|
||||
'title' => 'Asset ',
|
||||
'image' => 'Device Image',
|
||||
'days_without_acceptance' => 'Days Without Acceptance'
|
||||
'days_without_acceptance' => 'Days Without Acceptance',
|
||||
'monthly_depreciation' => 'Monthly Depreciation'
|
||||
|
||||
);
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
$settings->labels_width = $settings->labels_width - $settings->labels_display_sgutter;
|
||||
$settings->labels_height = $settings->labels_height - $settings->labels_display_bgutter;
|
||||
// Leave space on bottom for 1D barcode if necessary
|
||||
$qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->alt_barcode!='') ? $settings->labels_height - .3 : $settings->labels_height - .3;
|
||||
$qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->alt_barcode!='') ? $settings->labels_height - .3 : $settings->labels_height;
|
||||
// Leave space on left for QR code if necessary
|
||||
$qr_txt_size = ($settings->qr_code=='1' ? $settings->labels_width - $qr_size - .1: $settings->labels_width);
|
||||
$qr_txt_size = ($settings->qr_code=='1' ? $settings->labels_width - $qr_size - .1 : $settings->labels_width);
|
||||
?>
|
||||
|
||||
<style>
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
|
||||
|
||||
<div class="text-center" style="padding-top: 100px;">
|
||||
@if ($snipeSettings->privacy_policy_link!='')
|
||||
@if (($snipeSettings) && ($snipeSettings->privacy_policy_link!=''))
|
||||
<a target="_blank" rel="noopener" href="{{ $snipeSettings->privacy_policy_link }}" target="_new">{{ trans('admin/settings/general.privacy_policy') }}</a>
|
||||
@endif
|
||||
</div>
|
||||
|
|
|
@ -51,9 +51,10 @@
|
|||
<th class="col-sm-1">{{ trans('admin/hardware/table.location') }}</th>
|
||||
<th class="col-sm-1">{{ trans('admin/hardware/table.purchase_date') }}</th>
|
||||
<th class="col-sm-1">{{ trans('admin/hardware/table.eol') }}</th>
|
||||
<th class="col-sm-1">{{ trans('admin/hardware/table.purchase_cost') }}</th>
|
||||
<th class="col-sm-1">{{ trans('admin/hardware/table.book_value') }}</th>
|
||||
<th class="col-sm-1">{{ trans('admin/hardware/table.diff') }}</th>
|
||||
<th class="col-sm-1 align-right">{{ trans('admin/hardware/table.purchase_cost') }}</th>
|
||||
<th class="col-sm-1 align-right">{{ trans('admin/hardware/table.book_value') }}</th>
|
||||
<th class="col-sm-1 align-right">{{ trans('admin/hardware/table.monthly_depreciation') }}</th>
|
||||
<th class="col-sm-1 align-right">{{ trans('admin/hardware/table.diff') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -129,6 +130,17 @@
|
|||
|
||||
{{ \App\Helpers\Helper::formatCurrencyOutput($asset->getDepreciatedValue()) }}
|
||||
</td>
|
||||
<td class="align-right">
|
||||
@if ($asset->model->depreciation)
|
||||
@if ($asset->location && $asset->location->currency)
|
||||
{{ $asset->location->currency }}
|
||||
@else
|
||||
{{ $snipeSettings->default_currency }}
|
||||
@endif
|
||||
|
||||
{{ \App\Helpers\Helper::formatCurrencyOutput(($asset->model->eol > 0 ? ($asset->purchase_cost / $asset->model->eol) : 0)) }}
|
||||
@endif
|
||||
</td>
|
||||
<td class="align-right">
|
||||
@if ($asset->location && $asset->location->currency)
|
||||
{{ $asset->location->currency }}
|
||||
|
@ -142,6 +154,7 @@
|
|||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
@endif
|
||||
</tr>
|
||||
@endforeach
|
||||
|
|
|
@ -281,6 +281,20 @@
|
|||
{{ Form::checkbox('show_in_model_list[]', 'model_number', Input::old('show_in_model_list', $snipeSettings->modellistCheckedValue('model_number')),array('class' => 'minimal')) }} {{ trans('general.model_no') }}<br>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Depreciation method -->
|
||||
<div class="form-group {{ $errors->has('depreciation_method') ? 'error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
{{ Form::label('depreciation_method', trans('Depreciation method')) }}
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
{{ Form::select('depreciation_method', array(
|
||||
'default' => 'Linear (default)',
|
||||
'half_1' => 'Half-year convention, always applied',
|
||||
'half_2' => 'Half-year convention, applied with condition',
|
||||
), Input::old('username_format', $setting->depreciation_method)) }}
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.form-group -->
|
||||
|
||||
<!-- Privacy Policy Footer-->
|
||||
|
|
Loading…
Reference in a new issue