mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 21:54:14 -08:00
Changed checkout method to be more generic, for checkin and checkout
This commit is contained in:
parent
66a5050143
commit
8179fc2f90
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Models\Assetlog;
|
use App\Models\Actionlog;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use Config;
|
use Config;
|
||||||
|
@ -12,6 +12,7 @@ use Parsedown;
|
||||||
use Watson\Validating\ValidatingTrait;
|
use Watson\Validating\ValidatingTrait;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
|
use App\Helpers\Helper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model for Assets.
|
* Model for Assets.
|
||||||
|
@ -95,7 +96,8 @@ class Asset extends Depreciable
|
||||||
|
|
||||||
if ($this->save()) {
|
if ($this->save()) {
|
||||||
|
|
||||||
$log_id = $this->createCheckoutLog($checkout_at, $admin, $user, $expected_checkin, $note);
|
// $action, $admin, $user, $expected_checkin = null, $note = null, $checkout_at = null
|
||||||
|
$log_id = $this->createLogRecord('checkout', $this, $admin, $user, $expected_checkin, $note, $checkout_at);
|
||||||
|
|
||||||
if ((($this->requireAcceptance()=='1') || ($this->getEula())) && ($user->email!='')) {
|
if ((($this->requireAcceptance()=='1') || ($this->getEula())) && ($user->email!='')) {
|
||||||
$this->checkOutNotifyMail($log_id, $user, $checkout_at, $expected_checkin, $note);
|
$this->checkOutNotifyMail($log_id, $user, $checkout_at, $expected_checkin, $note);
|
||||||
|
@ -113,7 +115,6 @@ class Asset extends Depreciable
|
||||||
|
|
||||||
public function checkOutNotifyMail($log_id, $user, $checkout_at, $expected_checkin, $note)
|
public function checkOutNotifyMail($log_id, $user, $checkout_at, $expected_checkin, $note)
|
||||||
{
|
{
|
||||||
|
|
||||||
$data['log_id'] = $log_id;
|
$data['log_id'] = $log_id;
|
||||||
$data['eula'] = $this->getEula();
|
$data['eula'] = $this->getEula();
|
||||||
$data['first_name'] = $user->first_name;
|
$data['first_name'] = $user->first_name;
|
||||||
|
@ -176,24 +177,39 @@ class Asset extends Depreciable
|
||||||
return $this->rules;
|
return $this->rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createCheckoutLog($checkout_at = null, $admin, $user, $expected_checkin = null, $note = null)
|
|
||||||
|
public function createLogRecord($action, $asset, $admin, $user, $expected_checkin = null, $note = null, $checkout_at = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
$logaction = new \App\Models\Actionlog();
|
$logaction = new Actionlog();
|
||||||
$logaction->asset_id = $this->id;
|
$logaction->asset_id = $this->id;
|
||||||
$logaction->checkedout_to = $this->assigned_to;
|
$logaction->checkedout_to = $this->assigned_to;
|
||||||
$logaction->asset_type = 'hardware';
|
$logaction->asset_type = 'hardware';
|
||||||
|
$logaction->note = $note;
|
||||||
|
if ($checkout_at) {
|
||||||
|
$logaction->created_at = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', date('Y-m-d H:i:s', strtotime($checkout_at)));
|
||||||
|
} else {
|
||||||
|
$logaction->created_at = \Carbon\Carbon::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action=="checkout") {
|
||||||
if ($user) {
|
if ($user) {
|
||||||
$logaction->location_id = $user->location_id;
|
$logaction->location_id = $user->location_id;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
$logaction->adminlog()->associate($admin);
|
// Update the asset data to null, since it's being checked in
|
||||||
|
$logaction->checkedout_to = $asset->assigned_to;
|
||||||
|
$logaction->checkedout_to = '';
|
||||||
|
$logaction->asset_id = $asset->id;
|
||||||
|
$logaction->location_id = null;
|
||||||
|
$logaction->asset_type = 'hardware';
|
||||||
$logaction->note = $note;
|
$logaction->note = $note;
|
||||||
if ($checkout_at) {
|
$logaction->user_id = $admin->id;
|
||||||
$logaction->created_at = $checkout_at;
|
|
||||||
}
|
}
|
||||||
$log = $logaction->logaction('checkout');
|
$logaction->adminlog()->associate($admin);
|
||||||
return $logaction->id;
|
$log = $logaction->logaction($action);
|
||||||
|
|
||||||
|
return $logaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue