Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c579063
remove lock json
weiliang79 Oct 2, 2022
e4355d8
feat: change faker repo
weiliang79 Oct 2, 2022
1636200
remove yarn.lock
weiliang79 Oct 2, 2022
3411328
feat: migrate Mix to Vite
weiliang79 Oct 2, 2022
33c386a
remove laravel mix
weiliang79 Oct 2, 2022
ecb0859
feat: update react ver
weiliang79 Oct 2, 2022
3ed262f
feat: update packages
weiliang79 Oct 2, 2022
30fd8b2
feat: update adminLTE
weiliang79 Oct 2, 2022
b683d7e
feat: update sweetAlert2
weiliang79 Oct 2, 2022
36bf9e8
gitignore remove and commit lock json
weiliang79 Oct 2, 2022
ca810ff
remove mix config
weiliang79 Oct 2, 2022
70d4678
gitignore remove and commit yarn.lock
weiliang79 Oct 3, 2022
3035b15
feat: change settings table
weiliang79 Oct 3, 2022
71c1d64
feat: changed login function
weiliang79 Oct 3, 2022
c42bfcc
fix: default route and logout
weiliang79 Oct 3, 2022
da216a9
comment function that lead errors
weiliang79 Oct 3, 2022
ad60c10
feat: role model
weiliang79 Oct 3, 2022
e7e4594
comment unwanted features
weiliang79 Oct 4, 2022
74aa6c2
Merge remote-tracking branch 'origin/master'
weiliang79 Oct 4, 2022
8868962
feat: updated web.php
weiliang79 Oct 4, 2022
703a765
feat: add sweetAlert
weiliang79 Oct 4, 2022
a056290
feat: add and modify models
weiliang79 Oct 4, 2022
d1c1f07
feat: add main system url
weiliang79 Oct 4, 2022
fd4f8db
feat: product page migrated
weiliang79 Oct 4, 2022
4e6d906
feat: product details page
weiliang79 Oct 4, 2022
c00ce46
feat: product options list on details page
weiliang79 Oct 4, 2022
3448ea0
comment settings page
weiliang79 Oct 4, 2022
26448bc
comment settings features
weiliang79 Oct 4, 2022
104c5aa
comment customers features
weiliang79 Oct 4, 2022
d368bf0
comment right navbar item
weiliang79 Oct 4, 2022
3bfa3fb
comment route lead to error
weiliang79 Oct 5, 2022
5eea8a0
feat: add laravel santum
weiliang79 Oct 5, 2022
5001e05
update composer lock
weiliang79 Oct 5, 2022
54b8935
feat: order, detail, student model
weiliang79 Oct 5, 2022
d675fc8
feat: order page
weiliang79 Oct 5, 2022
49048df
feat: add dateformat package
weiliang79 Oct 6, 2022
60e19b5
feat: pos page (not done)
weiliang79 Oct 6, 2022
ce84fde
feat: POS page (not done)
weiliang79 Oct 8, 2022
8ca496b
feat: update columns and add new model
weiliang79 Oct 8, 2022
a2078c5
feat: POS page
weiliang79 Oct 8, 2022
4da7f54
changes: remove comments and add orderBy
weiliang79 Oct 8, 2022
a16c3ed
feat: order details page add status column in table
weiliang79 Oct 8, 2022
db020cc
feat: add badges
weiliang79 Oct 8, 2022
bee3f27
feat: home page with count
weiliang79 Oct 8, 2022
ab5b3d4
feat: store name and logo
weiliang79 Oct 8, 2022
044fe81
remove: unwanted database migration
weiliang79 Oct 8, 2022
f1d4de0
remove: unwanted models
weiliang79 Oct 8, 2022
18bd25f
remove: unwanted controllers
weiliang79 Oct 8, 2022
09f4201
remove: unwanted views
weiliang79 Oct 8, 2022
4197ac8
feat: handle img load fail
weiliang79 Oct 8, 2022
b281949
uncomment needed function
weiliang79 Oct 10, 2022
14c75e1
code documentation for model.
weiliang79 Oct 20, 2022
0537781
code documentation for controller.
weiliang79 Oct 20, 2022
70b4720
update gitignore
weiliang79 Oct 20, 2022
3818085
code formatting
weiliang79 Oct 21, 2022
9def33d
update readme.md
weiliang79 Nov 3, 2022
839c330
add necessary variable in .env.example
weiliang79 Nov 4, 2022
93555d7
fix: if food seller has not verified or have store information during…
weiliang79 Nov 9, 2022
4ad56e1
Merge branch 'master' of https://github.com/weiliang79/fyp-laravel-pos
weiliang79 Nov 9, 2022
f9215f6
fix: wrong store validation
weiliang79 Nov 9, 2022
71801c1
fix: query wrong order time
weiliang79 Nov 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
MAIN_SYSTEM_URL=

LOG_CHANNEL=stack

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<h1 align="center">POS System Using Laravel</h1>
</p>

Notice: This branch is modified to match [E-canteen Management System](https://github.com/weiliang79/fyp-e-canteen-management-system) workflow, if need to view the default POS system with upgraded from Laravel Mix to Vite, please go to [default branch](https://github.com/weiliang79/fyp-laravel-pos/tree/default).

The project was created while recording video "[Create POS System Using Laravel](https://www.youtube.com/watch?v=Y_NRk0lOOJc&list=PL2hV0q47BY-G9f5xG9Vq-wGjSyy1BekOv)"

## Installation
Expand Down
50 changes: 50 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
Expand Down Expand Up @@ -37,4 +39,52 @@ public function __construct()
{
$this->middleware('guest')->except('logout');
}

/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
return 'username';
}

/**
* The user has been authenticated.
*
* @param \Illuminate\Http\Request $request
* @param mixed $user
* @return mixed
*/
protected function authenticated(Request $request, $user)
{
if ($user->isAdmin()) {
Auth::logout();
return redirect()->route('login')->with('swal-warning', 'Only Food Seller can be login.');
}

if ($user->email === null || $user->email_verified_at === null) {
Auth::logout();
return redirect()->route('login')->with('swal-warning', 'Please verify the account and create store information at the main system first before login.');
}

if ($user->store === null) {
Auth::logout();
return redirect()->route('login')->with('swal-warning', 'Please create store information at the main system first before login.');
}

return redirect()->route('home')->with('swal-success', 'Login Successful.');
}

/**
* The user has logged out of the application.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
protected function loggedOut(Request $request)
{
return redirect()->route('login');
}
}
210 changes: 164 additions & 46 deletions app/Http/Controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,203 @@

namespace App\Http\Controllers;

use App\Models\Order;
use App\Models\OrderDetail;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\Product;
use App\Models\Student;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class CartController extends Controller
{
/**
* Show the POS page.
*
* @param Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\Response
*/
public function index(Request $request)
{
if ($request->wantsJson()) {
return response(
$request->user()->cart()->get()
);
}
return view('cart.index');
return view('cart.index', ['user_id' => Auth::user()->id]);
}

public function store(Request $request)
/**
* Get the given product's detail.
*
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function getProducts(Request $request)
{
$request->validate([
'barcode' => 'required|exists:products,barcode',
]);
$barcode = $request->barcode;

$product = Product::where('barcode', $barcode)->first();
$cart = $request->user()->cart()->where('barcode', $barcode)->first();
if ($cart) {
// check product quantity
if($product->quantity <= $cart->pivot->quantity) {
return response([
'message' => 'Product available only: '. $product->quantity,
], 400);
}
// update only quantity
$cart->pivot->quantity = $cart->pivot->quantity + 1;
$cart->pivot->save();
} else {
if($product->quantity < 1) {
return response([
'message' => 'Product out of stock',
], 400);
}
$request->user()->cart()->attach($product->id, ['quantity' => 1]);
$user = User::find(Auth::user()->id);
$products = Product::where('store_id', $user->store->id)
->where('status', true)
->with('productOptions.optionDetails')
->get();

if ($request->search) {
$products = Product::where('store_id', $user->store->id)->where('name', 'like', "%" . $request->search . "%")->get();
}

return response('', 204);
return response()->json([
'products' => $products
]);
}

public function changeQty(Request $request)
/**
* Get the products by a barcode.
*
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function getProductsByBarcode(Request $request)
{
$request->validate([
'product_id' => 'required|exists:products,id',
'quantity' => 'required|integer|min:1',
$user = User::find(Auth::user()->id);
$products = Product::where('store_id', $user->store->id)
->where('barcode', $request->barcode)
->where('status', true)
->with('productOptions.optionDetails')
->get();

if($products->count() == 0){
return response()->json(['message' => 'Product not found.'], 404);
}

return response()->json([
'products' => $products,
]);
}

/**
* Get the given student's order.
*
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function getStudentOrders(Request $request)
{
$student_number = $request->student_number;
$user = User::find(Auth::user()->id);
$productIds = $user->store->products()->pluck('id')->toArray();
$now = Carbon::now();

$student = Student::where('student_number', $student_number)->get();

if($student->count() == 0){
return response()->json([
'message' => 'Student not found.',
], 404);
}

$cart = $request->user()->cart()->where('id', $request->product_id)->first();
$student = Student::where('student_number', $student_number)->first();

if ($cart) {
$cart->pivot->quantity = $request->quantity;
$cart->pivot->save();
$orders = Order::whereHas('student', function ($query) use ($student_number) {
$query->where('student_number', $student_number);
})
->whereHas('orderDetails', function ($query) use ($productIds) {
$query->whereIn('product_id', $productIds)->where('is_pickup', false);
})
->where('status', '>=', Order::PAYMENT_SUCCESS)
->where('pick_up_start', '<=', $now)
->where('pick_up_end', '>=', $now)
->get();

foreach ($orders as $order) {
$details = OrderDetail::where('order_id', $order->id)->whereIn('product_id', $productIds)->get();
$orders->find($order->id)->order_details = $details;
}

return response([
'success' => true
return response()->json([
'orders' => $orders,
'student' => $student,
]);
}

public function delete(Request $request)
/**
* Update the student's existing order or create a new order.
*
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function store(Request $request)
{
$request->validate([
'product_id' => 'required|integer|exists:products,id'
'isNewOrder' => 'required|boolean',
'student_number' => 'required',
'order_details' => 'required_if:isNewOrder,==,true',
'order_ids' => 'required_if:isNewOrder,==,false',
]);
$request->user()->cart()->detach($request->product_id);

return response('', 204);
}
$user = User::find(Auth::user()->id);
$productIds = $user->store->products()->pluck('id')->toArray();

public function empty(Request $request)
{
$request->user()->cart()->detach();
if($request->isNewOrder){

$student = Student::where('student_number', $request->student_number)->first();
$orderDetails = $request->order_details;

$order = Order::create([
'student_id' => $student->id,
'pick_up_start' => Carbon::now(),
'pick_up_end' => Carbon::now(),
'total_price' => $request->total_price,
'status' => Order::PICKUP_ALL,
'is_sandbox_order' => $student->is_a_sandbox_student,
]);

$order->payments()->create([
'payment_type_id' => PaymentType::PAYMENT_CASH,
'amount' => $request->total_price,
'status' => Payment::STATUS_SUCCESS,
'is_sandbox_payment' => $student->is_a_sandbox_student,
]);

foreach($orderDetails as $detail){
$order->orderDetails()->create([
'product_id' => $detail['product_id'],
'product_options' => $detail['product_options'],
'price' => $detail['price'],
'notes' => $detail['notes'],
'is_pickup' => true,
]);
}

return response('', 204);
return response()->json(['message' => 'Order created successful.']);

} else {

$orders = Order::whereIn('id', $request->order_ids)->get();

foreach($orders as $order){
$details = $order->orderDetails()->whereIn('product_id', $productIds)->get();
foreach ($details as $detail) {
$detail->update([
'is_pickup' => true,
]);
}

if($order->orderDetails()->where('is_pickup', false)->count() == 0){
$order->update([
'status' => Order::PICKUP_ALL,
]);
} else {
$order->update([
'status' => Order::PICKUP_PARTIALLY,
]);
}
}

return response()->json(['message' => 'Orders update successful.']);
}
}

}
Loading