Skip to content

A free open source IT asset/license management system

Display qty in history

Marcus Moore8a595aa26910
diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php
index 027997197b..bdc2fcdcac 100644
--- a/app/Http/Transformers/ActionlogsTransformer.php
+++ b/app/Http/Transformers/ActionlogsTransformer.php
@@ -80,7 +80,7 @@ class ActionlogsTransformer
// this is a custom field
if (str_starts_with($fieldname, '_snipeit_')) {
-
+
foreach ($custom_fields as $custom_field) {
if ($custom_field->db_column == $fieldname) {
@@ -185,7 +185,7 @@ class ActionlogsTransformer
'name' => e($actionlog->target->display_name) ?? null,
'type' => e($actionlog->targetType()),
] : null,
-
+ 'qty' => $this->getQuantity($actionlog),
'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,
@@ -336,6 +336,19 @@ class ActionlogsTransformer
}
+ private function getQuantity(Actionlog $actionlog): ?int
+ {
+ if (!$actionlog->qty) {
+ return null;
+ }
+
+ // only a few action types will have a quantity we are interested in.
+ if (!in_array($actionlog->action_type, ['checkout', 'accepted', 'declined', 'checkin from'])) {
+ return null;
+ }
+
+ return (int) $actionlog->qty;
+ }
}
diff --git a/app/Presenters/HistoryPresenter.php b/app/Presenters/HistoryPresenter.php
index 9b9968ebd2..9fbd8fbd76 100644
--- a/app/Presenters/HistoryPresenter.php
+++ b/app/Presenters/HistoryPresenter.php
@@ -117,6 +117,13 @@ class HistoryPresenter extends Presenter
'visible' => true,
'formatter' => 'fileDownloadButtonsFormatter',
],
+ [
+ 'field' => 'qty',
+ 'searchable' => false,
+ 'sortable' => true,
+ 'visible' => true,
+ 'title' => trans('general.quantity'),
+ ],
[
'field' => 'note',
'searchable' => true,
@@ -169,4 +176,4 @@ class HistoryPresenter extends Presenter
return json_encode($merged);
}
-}
\ No newline at end of file
+}