Restaurant Management System ( Part 2 )

Published Date: 18-Dec-2017 | Tags: Laravel 5.5  Bootstrap 3  Project  

In this tutorial, I will share you the relevent resources, database backup. And create some important files for further use.

Suppose that

  • You have already created a new laravel project  (install-laravel-55-on-windows-step-by-step)
  • You have already installed laravelcollective package. Visit here if you don't know how to install.
  • You have already installed maatwebsite/excel package. Visit here if you don't know how to install.

 

Step 1: Download Required Files

  • Please download this file public.rar and extract to your /public folder.
  • Please download this folder Lib.zip and extract to /app folder.
  • Please download this database file codovel_pos_db.zip and restore to your database.

* And make sure to configure your database connection.

database-configuration

please change the configuration base on your environment. 

 

Step 2: Create Middleware Files

In this system we have to manage access base on user role. So Super user, Admin and Cashier can access only its own tasks.

  • Create this file SuperAdmin.php in /app/Http/Middleware
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class SuperAdmin
{
    public function handle($request, Closure $next)
    {
        if (Auth::user()->role == 'SuperAdmin')
            return $next($request);
        return redirect('error');
    }
}
  • Create this file Admin.php in /app/Http/Middleware
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class Admin
{
    public function handle($request, Closure $next)
    {
        if (Auth::user()->role == 'Admin' || Auth::user()->role == 'SuperAdmin')
            return $next($request);
        return redirect('error');
    }
}
  • Create this file Cashier.php in /app/Http/Middleware
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class Cashier
{
    public function handle($request, Closure $next)
    {
        if (Auth::user()->role == 'Cashier')
            return $next($request);
        return redirect('error');
    }
}

 

Then go to this file /app/Http/Kernel.php and add 

protected $routeMiddleware = [
        ...
        ...
        'super_admin' => \App\Http\Middleware\SuperAdmin::class,
        'admin' => \App\Http\Middleware\Admin::class,
        'cashier' => \App\Http\Middleware\Cashier::class
    ];

 

Step 3: Create Admin Template and Login

As I have to use ajax within the system, so I have to create a template file and import all related resources to use.

Create app.blade.php in /resources/views/layouts.  (create folder layouts if it does not exist)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{config('app.name')}}</title>
    <!-- Styles -->
    <link href="{{ asset('bootstrap-3.3.7/css/bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ asset('bootstrap-3.3.7/css/bootstrap-theme.min.css') }}" rel="stylesheet">
    <link href="{{ asset('pickadate/themes/default.css') }}" rel="stylesheet">
    <link href="{{ asset('pickadate/themes/default.date.css') }}" rel="stylesheet">
    <link href="{{ asset('css/style.css') }}" rel="stylesheet">
    <style>
        .picker__select--month, .picker__select--year {
            height: inherit;
        }

        .form-control:disabled, .form-control[readonly] {
            background-color: white;
        }
    </style>
</head>
<body style="background: grey">
<div class="container-fluid" style="background: #eef2f4;border-bottom: 5px solid whitesmoke">
    <img src="{{asset('images/logo.png')}}" height="50px" width="100px"/>
    <button class="navbar-toggle collapsed" data-toggle="collapse"
            data-target="#menu" aria-expanded="false">
        <i style="color: darkgrey" class="glyphicon glyphicon-menu-hamburger"></i> Menu
    </button>
</div>
<div class="container-fluid" style="padding-bottom: 160px">
    <div class="row-fluid" style="margin-top: 10px">
        <div class="col-sm-4 col-md-3">
            <div class="collapse navbar-collapse" id="menu" style="background:darkslateblue">
                <div style="background: grey;margin: 15px 0;padding: 5px 0;text-align: center">
                    <table width="100%">
                        <tr>
                            <td width="30%" style="padding:0 5px 0 5px"><img
                                        src="{{url('images/default_profile.png')}}"
                                        width="100%"
                                        class="img-rounded"/></td>
                            <td>
                                <b style="font-size: 150%;color: yellow">{{ucwords(Auth::user()->username)}}</b><br/>
                                <a href="{{url('/logout')}}" style="font-size: 14px;color: whitesmoke;" onclick="event.preventDefault();
                                             document.getElementById('logout-form').submit();"><i
                                            class="glyphicon glyphicon-log-out"></i>
                                    Lougout</a>
                                <form id="logout-form" action="{{ route('logout') }}" method="POST"
                                      style="display: none;">
                                    {{ csrf_field() }}
                                </form>
                            </td>
                        </tr>
                    </table>
                </div>
                <ul class="nav nav-stacked" id="sidebar" style="margin-bottom: 100px">
                    <li class="nav_home">
                        <a href="#home"><i class="glyphicon glyphicon-dashboard"></i> Dashboard</a>
                    </li>
                    <li><a href="#" style="pointer-events: none"><i class="glyphicon glyphicon-th"></i> Main Data</a>
                        <ul class="nav" id="sidebar">
                            <li class="nav_table"><a href="#table"> Table</a></li>
                            <li class="nav_customer"><a href="#customer"> Customer</a></li>
                        </ul>
                    </li>
                    <li>
                        <a href="#" style="pointer-events: none"><i class="glyphicon glyphicon-th"></i> Item</a>
                        <ul class="nav" id="sidebar">
                            <li class="nav_item">
                                <a href="#item">Item List</a>
                            </li>
                            <li class="nav_item_category">
                                <a href="#item_category">Item Category</a>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <a href="#" style="pointer-events: none"><i class="glyphicon glyphicon-th"></i> Product</a>
                        <ul class="nav" id="sidebar">
                            <li class="nav_product">
                                <a href="#product">Product List</a>
                            </li>
                            <li class="nav_product_category">
                                <a href="#product_category">Product Category</a>
                            </li>
                            <li class="nav_recipe">
                                <a href="#recipe">Recipe</a>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <a href="#" style="pointer-events: none"><i class="glyphicon glyphicon-search"></i>
                            Report</a>
                        <ul class="nav" id="sidebar">
                            <li class="nav_report_stock-balance">
                                <a href="#report/stock-balance">Stock Balance Report</a>
                            </li>
                            <li class="nav_report_daily-summary">
                                <a href="#report/daily-summary">Daily Summary Report</a>
                            </li>
                            <li class="nav_report_sale-history">
                                <a href="#report/sale-history">Sale History Report</a>
                            </li>
                            <li class="nav_report_sale-deleted-report">
                                <a href="#report/sale-deleted-report">Sale Deleted Report</a>
                            </li>
                            <li class="nav_report_sale-detail">
                                <a href="#report/sale-detail">Sale Detail Report</a>
                            </li>
                            <li class="nav_report_sale-stock">
                                <a href="#report/sale-stock">Sale Stock Report</a>
                            </li>
                            <li class="nav_report_sale-discount">
                                <a href="#report/sale-discount">Sale Discount Report</a>
                            </li>
                            <li class="nav_report_sale-graph">
                                <a href="#report/sale-graph">Sale Graph Report</a>
                            </li>
                        </ul>
                    </li>
                    @if(Auth::user()->role=='SuperAdmin')
                        <li class="nav_user"><a href="#user"><i
                                        class="glyphicon glyphicon-user"></i> User Management</a></li>
                    @endif
                    <li class="nav_change-password"><a href="#change-password"><i
                                    class="glyphicon glyphicon-lock"></i>
                            Change
                            Password</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="col-sm-8 col-md-9" style="background: white;padding-top: 1px;padding-bottom: 50px" id="content">
        </div>
    </div>
</div>
<div class="loading"></div>
<!-- JavaScripts -->
<script src="{{ asset('js/jquery-3.1.1.min.js') }}"></script>
<script src="{{ asset('bootstrap-3.3.7/js/bootstrap.min.js') }}"></script>
<script src="{{ asset('js/routie.min.js') }}"></script>
<script src="{{ asset('js/script.js') }}"></script>
<script src="{{ asset('js/highcharts.js') }}"></script>
<script src="{{ asset('js/exporting.js') }}"></script>
<script src="{{ asset('pickadate/picker.js') }}"></script>
<script src="{{ asset('pickadate/picker.date.js') }}"></script>
</body>
</html>

 

Create or update login form /resources/views/auth/login.blade.php. (create folder auth if it does not exist)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{config('app.name')}}</title>
    <!-- Styles -->
    <link href="{{ asset('bootstrap-3.3.7/css/bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ asset('bootstrap-3.3.7/css/bootstrap-theme.min.css') }}" rel="stylesheet">
</head>
<body>
<div class="container-fluid" style="background: #eef2f4;border-bottom: 5px solid whitesmoke">
    <img src="{{asset('images/logo.png')}}" height="100px" width="150px"/>
</div>
<div class="container-fluid">
    <div class="row-fluid" style="margin-top: 10px">
        <div class="col-md-6 col-md-offset-3" style="padding-top: 1px;padding-bottom: 50px">
            <h1 class="page-header">Login</h1>
            <div class="row">
                <div class="col-sm-5 hidden-xs" style="text-align: center">
                    <img src="{{asset("images/login.png")}}"/>
                </div>
                <div class="col-sm-7">
                    {!! Form::open(['url'=>'/login']) !!}
                    <div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
                        {!! Form::label("username","Username") !!}
                        {!! Form::text("username",null,["class"=>"form-control","placeholder"=>"Username"]) !!}
                        {!! $errors->first('username','<span class="help-block">:message</span>') !!}
                    </div>

                    <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                        {!! Form::label("password","Password") !!}
                        {!! Form::password("password",["class"=>"form-control","placeholder"=>"Password"]) !!}
                        {!! $errors->first('password','<span class="help-block">:message</span>') !!}
                    </div>
                    <input type="hidden" name="active" value="1"/>
                    <div class="form-group">
                        {!! Form::submit("Login",["class"=>"btn btn-primary"]) !!}
                    </div>
                    {!! Form::close() !!}
                </div>
            </div>
        </div>
    </div>
</div>
<script src="{{ asset('js/jquery-3.1.1.min.js') }}"></script>
<script src="{{ asset('bootstrap-3.3.7/js/bootstrap.min.js') }}"></script>
</body>
</html>

 

Step 4: Create Route

This point is very important because I will place all route for the whole system in here. So next tutorials, you no need to care about route. This part seem abit hard to split, so I decide to put everything here.

Please go to add route in here /routes/web.php

<?php

Auth::routes();
Route::group(['middleware' => 'auth'], function () {
    Route::get('/', function () {
        if (Auth::user()->role == 'Admin' or Auth::user()->role == 'SuperAdmin')
            return view('layouts.app');
        elseif (Auth::user()->role == 'Cashier')
            return redirect('cashier');
        else
            return redirect('error');
    });
    Route::get('error', function () {
        return "Sorry, you are unauthorized to access this page.";
    });
    Route::group(['prefix' => 'user', 'middleware' => 'super_admin'], function () {
        Route::get('/', 'UserController@index');
        Route::match(['get', 'post'], 'create', 'UserController@create');
        Route::match(['get', 'put'], 'update/{id}', 'UserController@update');
        Route::delete('delete/{id}', 'UserController@delete');
    });
    Route::group(['middleware' => 'admin'], function () {
        Route::match(['get', 'put'], 'change-password', 'UserController@changePassword');
        Route::group(['prefix' => 'home'], function () {
            Route::get('/', 'HomeController@index');
            Route::match(['get', 'post'], 'exchange-rate', 'HomeController@exchangeRate');
        });
        Route::group(['prefix' => 'table'], function () {
            Route::get('/', 'TableController@index');
            Route::match(['get', 'post'], 'create', 'TableController@create');
            Route::match(['get', 'put'], 'update/{id}', 'TableController@update');
            Route::delete('delete/{id}', 'TableController@delete');
        });
        Route::group(['prefix' => 'customer'], function () {
            Route::get('/', 'CustomerController@index');
            Route::match(['get', 'post'], 'create', 'CustomerController@create');
            Route::match(['get', 'put'], 'update/{id}', 'CustomerController@update');
            Route::delete('delete/{id}', 'CustomerController@delete');
        });
        Route::group(['prefix' => 'item'], function () {
            Route::get('/', 'ItemController@index');
            Route::get('unit/{item_id}', 'ItemController@unit');
            Route::match(['get', 'post'], 'create', 'ItemController@create');
            Route::match(['get', 'put'], 'update/{id}', 'ItemController@update');
            Route::delete('delete/{id}', 'ItemController@delete');
        });
        Route::group(['prefix' => 'item_category'], function () {
            Route::get('/', 'ItemCategoryController@index');
            Route::match(['get', 'post'], 'create', 'ItemCategoryController@create');
            Route::match(['get', 'put'], 'update/{id}', 'ItemCategoryController@update');
            Route::delete('delete/{id}', 'ItemCategoryController@delete');
        });
        Route::group(['prefix' => 'product'], function () {
            Route::get('/', 'ProductController@index');
            Route::get('print', 'ProductController@printProducts');
            Route::match(['get', 'post'], 'create', 'ProductController@create');
            Route::match(['get', 'put'], 'update/{id}', 'ProductController@update');
            Route::delete('delete/{id}', 'ProductController@delete');
        });
        Route::group(['prefix' => 'product_category'], function () {
            Route::get('/', 'ProductCategoryController@index');
            Route::match(['get', 'post'], 'create', 'ProductCategoryController@create');
            Route::match(['get', 'put'], 'update/{id}', 'ProductCategoryController@update');
            Route::delete('delete/{id}', 'ProductCategoryController@delete');
        });
        Route::group(['prefix' => 'recipe'], function () {
            Route::get('/', 'RecipeController@index');
            Route::match(['get', 'post'], 'create', 'RecipeController@create');
            Route::match(['get', 'put'], 'update/{id}', 'RecipeController@update');
            Route::delete('delete/{id}', 'RecipeController@delete');
        });
        Route::group(['prefix' => 'report'], function () {
            Route::get('stock-balance', 'ReportController@stockBalance');
            Route::get('print-stock-balance', 'ReportController@printStockBalance');
            Route::get('stock-in', 'ReportController@stockIn');
            Route::get('stock-adjustment', 'ReportController@stockAdjustment');
            Route::get('daily-summary', 'ReportController@dailySummary');
            Route::get('print-daily-summary', 'ReportController@printDailySummary');
            Route::get('sale-history', 'ReportController@saleHistory');
            Route::get('sale-deleted-report', 'ReportController@saleDeletedReport');
            Route::get('sale-detail', 'ReportController@saleDetail');
            Route::get('export-detail-report', 'ReportController@exportDetailReport');
            Route::get('sale-stock', 'ReportController@saleStock');
            Route::get('sale-discount', 'ReportController@saleDiscount');
            Route::get('sale-graph', 'ReportController@saleGraph');
            Route::get('view-detail/{id}', 'ReportController@viewDetail');
        });
    });
    Route::group(['prefix' => 'cashier', 'middleware' => 'cashier'], function () {
        Route::get('/', 'CashierController@index');
        Route::get('products', 'CashierController@products');
        Route::get('table', 'CashierController@table');
        Route::get('select-table/{id}', 'CashierController@selectTable');
        Route::get('change-table', 'CashierController@changeTable');
        Route::get('switch-table/{id}', 'CashierController@switchTable');
        Route::get('order/{id}', 'CashierController@order');
        Route::get('update-description/{id}/{value}', 'CashierController@updateDescription');
        Route::get('update-quantity/{id}/{value}', 'CashierController@updateQuantity');
        Route::get('update-price/{id}/{value}', 'CashierController@updatePrice');
        Route::get('update-discount-detail/{id}/{value}', 'CashierController@updateDiscountDetail');
        Route::get('update-customer/{id}/{value}', 'CashierController@updateCustomer');
        Route::get('update-discount/{id}/{value}', 'CashierController@updateDiscount');
        Route::delete('delete/{id}', 'CashierController@delete');
        Route::match(['get', 'post'], 'open', 'CashierController@open');
        Route::match(['get', 'post'], 'pay', 'CashierController@pay');
        Route::get('return-order', 'CashierController@returnOrder');
        Route::get('print-payment', 'CashierController@printPayment');
        Route::get('print', 'CashierController@getPrint');
        Route::get('reload-order', 'CashierController@reloadOrder');
    });
});

 

Till this step, what I expect from you is that you can see the login screen when you run the project.

pos-login

Hope you can do it. 


Demo


Related Posts

© 2018 All Rights Reserved.