Skip to content

Commit 75c8323

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 4ddee4a + 72be171 commit 75c8323

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

app/Http/Controllers/Api/AssetModelsController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function index(Request $request) : JsonResponse | array
4646
'manufacturer',
4747
'requestable',
4848
'assets_count',
49+
'assets_assigned_count',
50+
'assets_archived_count',
4951
'remaining',
5052
'category',
5153
'fieldset',
@@ -75,7 +77,9 @@ public function index(Request $request) : JsonResponse | array
7577
])
7678
->with('category', 'depreciation', 'manufacturer', 'fieldset.fields.defaultValues', 'adminuser')
7779
->withCount('assets as assets_count')
78-
->withCount('availableAssets as remaining');
80+
->withCount('availableAssets as remaining')
81+
->withCount('assignedAssets as assets_assigned_count')
82+
->withCount('archivedAssets as assets_archived_count');
7983

8084
if ($request->input('status')=='deleted') {
8185
$assetmodels->onlyTrashed();

app/Http/Transformers/AssetModelsTransformer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@ public function transformAssetModel(AssetModel $assetmodel)
4848
'image' => ($assetmodel->image != '') ? Storage::disk('public')->url('models/'.e($assetmodel->image)) : null,
4949
'model_number' => ($assetmodel->model_number ? e($assetmodel->model_number): null),
5050
'min_amt' => ($assetmodel->min_amt) ? (int) $assetmodel->min_amt : null,
51-
'remaining' => (int) $assetmodel->available_assets_count,
51+
5252
'depreciation' => ($assetmodel->depreciation) ? [
5353
'id' => (int) $assetmodel->depreciation->id,
5454
'name'=> e($assetmodel->depreciation->name),
5555
] : null,
5656
'assets_count' => (int) $assetmodel->assets_count,
57+
'assets_assigned_count' => (int) $assetmodel->assets_assigned_count,
58+
'assets_archived_count' => (int) $assetmodel->assets_archived_count,
59+
'remaining' => (int) ($assetmodel->assets_count - $assetmodel->assets_assigned_count),
5760
'category' => ($assetmodel->category) ? [
5861
'id' => (int) $assetmodel->category->id,
5962
'name'=> e($assetmodel->category->name),

app/Models/AssetModel.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,17 @@ public function assets()
125125

126126
public function availableAssets()
127127
{
128-
return $this->hasMany(\App\Models\Asset::class, 'model_id')->whereNull('assets.assigned_to')->RTD();
128+
return $this->hasMany(\App\Models\Asset::class, 'model_id')->RTD();
129+
}
130+
131+
public function assignedAssets()
132+
{
133+
return $this->hasMany(\App\Models\Asset::class, 'model_id')->Deployed();
134+
}
135+
136+
public function archivedAssets()
137+
{
138+
return $this->hasMany(\App\Models\Asset::class, 'model_id')->Archived();
129139
}
130140

131141
/**

app/Presenters/AssetModelPresenter.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,16 @@ public static function dataTableLayout()
8989
'class' => 'text-right text-padding-number-cell',
9090
'footerFormatter' => 'qtySumFormatter',
9191
],
92-
92+
[
93+
'field' => 'assets_assigned_count',
94+
'searchable' => false,
95+
'sortable' => true,
96+
'switchable' => true,
97+
'title' => trans('general.assigned'),
98+
'visible' => true,
99+
'class' => 'text-right text-padding-number-cell',
100+
'footerFormatter' => 'qtySumFormatter',
101+
],
93102
[
94103
'field' => 'remaining',
95104
'searchable' => false,
@@ -100,6 +109,16 @@ public static function dataTableLayout()
100109
'class' => 'text-right text-padding-number-cell',
101110
'footerFormatter' => 'qtySumFormatter',
102111
],
112+
[
113+
'field' => 'assets_archived_count',
114+
'searchable' => false,
115+
'sortable' => true,
116+
'switchable' => true,
117+
'title' => trans('general.archived'),
118+
'visible' => true,
119+
'class' => 'text-right text-padding-number-cell',
120+
'footerFormatter' => 'qtySumFormatter',
121+
],
103122
[
104123
'field' => 'depreciation',
105124
'searchable' => false,

0 commit comments

Comments
 (0)