Skip to content
This repository has been archived by the owner on Feb 20, 2025. It is now read-only.

Commit

Permalink
Added inventiry managment
Browse files Browse the repository at this point in the history
  • Loading branch information
teilin committed Apr 10, 2021
1 parent be0197d commit 5749e2d
Show file tree
Hide file tree
Showing 15 changed files with 1,090 additions and 1 deletion.
45 changes: 45 additions & 0 deletions app/Http/Controllers/InventoryCommentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Http\Controllers;

use App\Models\InventoryComment;
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class InventoryCommentController extends BaseController
{
public function commentsByInventory($inventory_id)
{
$comments = InventoryComment::where('inventory_id',$inventory_id)->get();
return response()->json($comments);
}

public function create(Request $request, $inventory_id)
{
$comment = new InventoryComment;
$comment->comment = $request->comment;
$comment->user_id = $request->user_id;
$comment->inventory_id = $inventory_id;
$comment->save();
return response()->json($comment);
}

public function update(Request $request, $id)
{
$comment = InventoryComment::find($id);
if($request->input('comment')) {
$comment->comment = $request->input('comment');
}
$comment->save();
return response()->json($comment);
}

public function destroy($id)
{
$comment = InventoryComment::find($id);
$comment->delete();

return response()->json('inventory comment removed successfully');
}
}
?>
65 changes: 65 additions & 0 deletions app/Http/Controllers/InventoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Http\Controllers;

use App\Models\Inventory;
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class InventoryController extends BaseController
{
public function inventoryByLocation($storagelocation_id)
{
$storagelocations = Inventory::where('storagelocation_id', $storagelocation_id)->get();
return response()->json($storagelocations);
}

public function create(Request $request, $storagelocation_id)
{
$inventory = new Inventory;
$inventory->inventoryCategoryCodeSetId = $request->inventoryCategoryCodeSetId;
$inventory->inventoryCategoryCodeId = $request->inventoryCategoryCodeId;
$inventory->name = $request->name;
$inventory->storagelocation_id = $storagelocation_id;
$inventory->description = $request->description;
$inventory->save();
return response()->json($inventory);
}

public function show($id)
{
$inventory = Inventory::find($id);
return response()->json($inventory);
}

public function update(Request $request, $id)
{
$inventory = Inventory::find($id);
if($request->input('inventoryCategoryCodeSetId')) {
$inventory->inventoryCategoryCodeSetId = $request->input('inventoryCategoryCodeSetId');
}
if($request->input('inventoryCategoryCodeId')) {
$inventory->inventoryCategoryCodeId = $request->input('inventoryCategoryCodeId');
}
if($request->input('name')) {
$inventory->name = $request->input('name');
}
if($request->input('storagelocation_id')) {
$inventory->storagelocation_id = $request->input('storagelocation_id');
}
if($request->input('description')) {
$inventory->description = $request->input('description');
}
$inventory->save();
return response()->json($inventory);
}

public function destroy($id)
{
$inventory = Inventory::find($id);
$inventory->delete();

return response()->json('inventory removed successfully');
}
}
?>
36 changes: 36 additions & 0 deletions app/Http/Controllers/InventoryCountController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Controllers;

use App\Models\InventoryCount;
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class InventoryCountController extends BaseController
{
public function countsByInventory($inventory_id)
{
$counts = InventoryCount::where('inventory_id',$inventory_id)->get();
return response()->json($counts);
}

public function create(Request $request, $inventory_id)
{
$count = new InventoryCount;
$count->inventory_id = $inventory_id;
$count->counted_at = $request->counted_at;
$count->count = $request->count;
$count->user_id = $request->user_id;
$count->save();
return response()->json($count);
}

public function destroy($id)
{
$count = InventoryCount::find($id);
$count->delete();

return response()->json('inventory count removed successfully');
}
}
?>
66 changes: 66 additions & 0 deletions app/Http/Controllers/StorageLocationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Http\Controllers;

use App\Models\StorageLocation;
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class StorageLocationController extends BaseController
{
/**
* Create a new controller instance.
*
* @return void
*/
public function index()
{
$storagelocations = StorageLocation::all();
return response()->json($storagelocations);
}

public function create(Request $request)
{
$location = new StorageLocation;
$location->name = $request->name;
$location->description = $request->description;
$location->long = $request->long;
$location->lat = $request->lat;
$location->save();
return response()->json($location);
}

public function show($id)
{
$location = StorageLocation::find($id);
return response()->json($location);
}

public function update(Request $request, $id)
{
$location = StorageLocation::find($id);
if($request->input('name')) {
$location->name = $request->input('name');
}
if($request->input('description')) {
$location->description = $request->input('description');
}
if($request->input('long')) {
$location->long = $request->input('long');
}
if($request->input('lat')) {
$location->lat = $request->input('lat');
}
$location->save();
return response()->json($location);
}

public function destroy($id)
{
$location = StorageLocation::find($id);
$location->delete();

return response()->json('location removed successfully');
}
}
?>
37 changes: 37 additions & 0 deletions app/Models/Inventory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Inventory extends Model
{
use SoftDeletes;

protected $table = 'inventory';

protected $fillable = [
'inventoryCategoryCodeSetId',
'inventoryCategoryCodeId',
'name',
'storagelocation_id',
'description'
];
protected $hidden = [];

public function storagelocation()
{
return $this->belongsTo(StorageLocation::class, 'storagelocation_id', 'id');
}

public function comments()
{
return $this->hasMany(InventoryComment::class, 'inventory_id', 'id');
}

public function counts()
{
return $this->hasMany(InventoryCount::class, 'inventory_id', 'id');
}
}
?>
25 changes: 25 additions & 0 deletions app/Models/InventoryComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class InventoryComment extends Model
{
use SoftDeletes;

protected $table = 'inventorycomment';

protected $fillable = [
'comment',
'user_id',
'inventory_id'
];
protected $hidden = [];

public function inventory()
{
return $this->belongsTo(Inventory::class, 'inventory_id', 'id');
}
}
?>
26 changes: 26 additions & 0 deletions app/Models/InventoryCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class InventoryCount extends Model
{
use SoftDeletes;

protected $table = 'inventorycounting';

protected $fillable = [
'inventory_id',
'counted_at',
'count',
'user_id'
];
protected $hidden = [];

public function inventory()
{
return $this->belongsTo(Inventory::class, 'inventory_id', 'id');
}
}
?>
21 changes: 21 additions & 0 deletions app/Models/StorageLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class StorageLocation extends Model
{
use SoftDeletes;

protected $table = 'storagelocation';

protected $fillable = ['name','description','long', 'lat'];
protected $hidden = [];

public function inventories()
{
return $this->hasMany(Inventory::class, 'storagelocation_id', 'id');
}
}
?>
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"require": {
"php": "^7.3|^8.0",
"auth0/auth0-php": "^7.6",
"doctrine/dbal": "^3.0",
"grimzy/laravel-mysql-spatial": "^5.0",
"guzzlehttp/guzzle": "^7.3",
"laravel/lumen-framework": "^8.0"
},
Expand Down
Loading

0 comments on commit 5749e2d

Please sign in to comment.