<repo_name>ayodvr/Laravel-POS-application<file_sep>/app/Http/Controllers/SalesController.php
<?php

namespace App\Http\Controllers;

use App\User;
use DB;
use App\Customers;
use App\Product;
use App\Sale;
use App\SaleItem;
use App\SalePayment;
use App\SaleTemp;
use App\Inventory;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use RealRashid\SweetAlert\Facades\Alert;
use Haruncpi\LaravelIdGenerator\IdGenerator;


class SalesController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $sales = Sale::orderBy('id', 'desc')->first();
        //dd($sales);
        $customers = Customers::all();
        return view('sales.index')->with('customers', $customers);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //dd($request->all());
        $this->validate($request,[

        'customer_id'=>'required',
        'payment_type'=>'required',
        'subtotal'=>'required',
        'payment'=>'required'
        ]);

        $saleItems = SaleTemp::all();
        //dd($saleItems);
        if(empty($saleItems->toArray())) {
            notify()->error("Please Add some Items to create sale!","Error");
            return back();
        }

        $sales = new Sale;
        $sales->customer_id = $request->customer_id;
        $sales->user_id = Auth::user()->id;
        $sales->payment_type = $request->payment_type;
        $discount = $request->discount;
        $discount_percent = $request->discount_percent;
        $subtotal = $request->subtotal;
        $sales->uuid = $this->realUniqId();
        

        $total_discount = $discount + ($discount_percent * $subtotal)/100;
        $sales->discount = $total_discount;
        $tax = $sales->tax = ($subtotal*0)/100;
        $total = $sales->grand_total = $subtotal + $tax - $total_discount;
        //insert payment data in the payment table
        $payment = $sales->payment = $request->payment;
        $dues= $sales->dues = $total - $payment;
        if ($dues > 0) {
            $sales->status = 0;
        } else {
            $sales->status = 1;
        }
        $sales->save();

        $customer = Customers::findOrFail($sales->customer_id);
        $customer->prev_balance = $customer->prev_balance + $sales->dues;
        $customer->update();
        if ($request->payment > 0) {
            $payment = new SalePayment;
            $paid = $payment->payment = $request->payment;
            $payment->dues = $total - $paid;
            $payment->payment_type = $request->payment;
            $payment->comments = $request->comments;
            $payment->sale_id = $sales->id;
            $payment->user_id = Auth::user()->id;
            $payment->save();
        }
        
        foreach ($saleItems as $value) {
            $saleItemsData = new SaleItem;
            $saleItemsData->sale_id = $sales->id;
            $saleItemsData->uuid = $sales->uuid;
            $saleItemsData->product_id = $value->product_id;
            $saleItemsData->cost_price = $value->cost_price;
            $saleItemsData->selling_price = $value->selling_price;
            $saleItemsData->quantity = $value->quantity;
            $saleItemsData->total_cost = $value->total_cost;
            $saleItemsData->total_selling = $value->total_selling;
            $saleItemsData->save(); 
            //process inventory
            $products = Product::find($value->product_id);
            if ($products->type == 1) {
                $inventories = new Inventory;
                $inventories->product_id = $value->product_id;
                $inventories->user_id = Auth::user()->id;
                $inventories->in_out_qty = -($value->quantity);
                $inventories->remarks = 'SALE' . $sales->id;
                $inventories->save();
                //process product quantity
                $products->quantity = $products->quantity - $value->quantity;
                $products->save();
            } 
        }

         //delete all data on SaleTemp model
         SaleTemp::truncate();
         $itemssale = SaleItem::where('sale_id', $saleItemsData->sale_id)->get();
        //  notify()->success("You have successfully added sales!","Success");
             return view('sales.complete')
                 ->with('sales', $sales)
                 ->with('saleItemsData', $saleItemsData)
                 ->with('saleItems', $itemssale);
    }

    public function realUniqId($lenght = 10) {
        // uniqid gives 13 chars, but you could adjust it to your needs.
        if (function_exists("random_bytes")) {
            $bytes = random_bytes(ceil($lenght / 2));
        } elseif (function_exists("openssl_random_pseudo_bytes")) {
            $bytes = openssl_random_pseudo_bytes(ceil($lenght / 2));
        } else {
            throw new Exception("no cryptographically secure random function available");
        }
        return substr(bin2hex($bytes), 0, $lenght);
  }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
<file_sep>/app/Http/Controllers/InventoryController.php
<?php

namespace App\Http\Controllers;

use App\Inventory;
use App\Product;
use Illuminate\Http\Request;

class InventoryController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $products = product::find($id);
        $inventories = Inventory::all();
        return view('inventory.edit')
            ->with('products', $products)
            ->with('inventory', $inventories);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request,[

        'in_out_qty' =>'required|numeric|max:999999999',
        'remarks'=>'required|max:255'
     ]);
        
        $products = product::find($id);
        $products->quantity = $products->quantity + $request->in_out_qty;
        $products->save();

        $inventories = new Inventory;
        $inventories->products_id = $id;
        $inventories->user_id = Auth::user()->id;
        $inventories->in_out_qty = $request->in_out_qty;
        $inventories->remarks = $request->remarks;
        $inventories->save();

        notify()->success("You have successfully updated product!","Success");
        return view('inventories.edit');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
<file_sep>/app/Http/Controllers/ProductsController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use RealRashid\SweetAlert\Facades\Alert;
use Haruncpi\LaravelIdGenerator\IdGenerator;
use App\Staffs;
use App\User;
use App\AdminProfile;
use DB;
use App\Customers;
use App\Suppliers;
use App\Product;
use App\Category;

class ProductsController extends Controller
{
     /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $products = Product::orderBy('id','asc')->get();
        $categories = Category::pluck('cat_name','id');
        //dd($categories);
        return view('products.index')->with('products',$products)->with('categories',$categories);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $category = Category::orderBy('id','desc')->get();

        return view('products.create')->with('category',$category);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request,[
         
            'prod_image'=>'image|nullable|max:1999',
            'name'=>'required|max:15',
            'cat_id'=>'required',
            'quantity'=>'required|max:185',
            'description'=>'required|max:499',
            'cost_price'=>'required',
            'selling_price'=>'required'
        ]);

             //Handle file uploads
        if($request->hasFile('prod_image')){
            //Get file name with the extension
            $fileNameWithExt = $request->file('prod_image')->getClientOriginalName();
            //Get just filename
            $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
            //Get just extension
            $extension = $request->file('prod_image')->getClientOriginalExtension();
            //Filename to store
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            //Upload image
            $path = $request->file('prod_image')->storeAs('public/prod_image',$fileNameToStore);
            } else {
            $fileNameToStore = 'noimage.jpg';
            }

            //dd($request->all());
            $product = new Product;
            
            $product->name = $request->name;
            $product->prod_image = $fileNameToStore;
            $product->quantity = $request->quantity;
            $product->description = $request->description;
            $product->cost_price = $request->cost_price;
            $product->selling_price = $request->selling_price;
            $product->cat_id = $request->cat_id;
            
            
            if($product->save()){

                notify()->success("Product Added!","Success");

            }

            return redirect()->back();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $product = Product::findorfail($id);
        $categories = Category::all();
        //dd($product);
        return view('products.edit')->with('product',$product)->with('categories',$categories);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request,[

            'prod_image'=>'image|nullable|max:1999',
            'name'=>'required|max:15',
            'quantity'=>'required|max:185',
            'description'=>'required|max:499',
            'cost_price'=>'required',
            'cat_id'=>'required',
            'selling_price'=>'required|max:185'  
        ]);

             //Handle file uploads
        if($request->hasFile('prod_image')){
            //Get file name with the extension
            $fileNameWithExt = $request->file('prod_image')->getClientOriginalName();
            //Get just filename
            $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
            //Get just extension
            $extension = $request->file('prod_image')->getClientOriginalExtension();
            //Filename to store
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            //Upload image
            $path = $request->file('prod_image')->storeAs('public/prod_image',$fileNameToStore);
            } else {
            $fileNameToStore = 'noimage.jpg';
            }
            //dd($request->all());
            $product = Product::find($id);
            
            $product->name = $request->name;
            $product->quantity = $request->quantity;
            $product->description = $request->description;
            $product->cost_price = $request->cost_price;
            $product->selling_price = $request->selling_price;
            $product->cat_id = $request->cat_id;
            
            if($request->hasFile('prod_image')){
                $product->prod_image = $fileNameToStore;
            }

            if($product->save()){
                
                notify()->success("Product Updated!","Success");

                return redirect()->route('products.index');
            }

            
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $product = Product::findorfail($id);

        $product->delete();
        
        notify()->success("Product Deleted!","Success");

        return redirect()->back();
    }


    public function dmp(Request $request){

        $id = $request->id;
       
        foreach ($id as $user){

            Product::where('id', $user)->delete();
        }
        notify()->success("Product Deleted!","Success");

        return redirect()->back();
    }
}
<file_sep>/routes/web.php
<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


// Route::get('/calendar',function (){
// return view('calendar');
// });

Route::get('/', function (){
    return view('auth/login');
});

Auth::routes();

Route::post('/pay', 'PaymentController@redirectToGateway')->name('pay');
Route::get('/payment/callback', 'PaymentController@handleGatewayCallback');

// Route::get('/payment-order', function (){
//     return view('sales.payments');
// });


Route ::group(['middleware'=>'auth'],function(){
    Route::get('changeStatus/{id}','StaffController@changeStatus')->name('changeStatus');
    Route::get('/staff_dashboard', 'StaffController@staff_dashboard')->name('staffs.staff_dashboard');
    Route::get('/staffs/trashed', 'StaffController@trashed')->name('staffs.trashed');
    Route::get('/staffs/kill/{id}', 'StaffController@kill')->name('staffs.kill');
    Route::get('/staffs/restore/{id}', 'StaffController@restore')->name('staffs.restore');
    Route::resource('/staffs',"StaffController");
});

Route ::group(['middleware'=>'auth'],function(){

    Route::get('/dashboard',"AdminProfileController@admin_dashboard")->name('dashboard');
    Route::get('/adminprofile/create',"AdminProfileController@create")->name('create');
    Route::get('/adminprofile/{id}/edit',"AdminProfileController@edit")->name('edit');
    Route::get('/adminprofile/{id}',"AdminProfileController@show")->name('show');
    Route::post('/adminprofile/store',"AdminProfileController@store")->name('store');
    Route::post('/adminprofile/{id}/update',"AdminProfileController@update")->name('update');
    Route::get('/adminprofile/{id}/destroy',"AdminProfileController@destroy")->name('destroy');
    Route::get('/register_2',"NewUserController@create")->name('register_2');
    Route::post('/store',"NewUserController@user_store")->name('user_store');
});
Route::resource('/sales',"SalesController");
Route::resource('/receiving',"ReceivingController");
Route::resource('/products',"ProductsController");
Route::delete('/delete-products', "ProductsController@dmp")->name('products.dmp');
Route::resource('/customers',"CustomersController");
Route::resource('/suppliers',"SuppliersController");
Route::resource('/categories',"CategoryController");
Route::resource('/inventories',"InventoryController");
Route::resource('/accounts',"AccountController");
Route::resource('/transactions',"TransactionsController");
Route::resource('/expense',"ExpenseController");
Route::resource('/expense_cat',"ExpenseCategoryController");
Route::get('/pdf',"CustomersController@Customer_PDF")->name('customer_pdf');
Route::get('/sales-rep-pdf',"SaleReportController@Sale_PDF")->name('sale_pdf');
Route::resource('api/saletemp','SaleApiController');
Route::resource('api/receivingtemp','ReceivingApiController');
Route::resource('api/prodtemp','ProductsApiController');
Route::resource('/receivingsreport', 'ReceivingsReportController');
Route::resource('/salesreport', 'SaleReportController');

Route::get('login/facebook', 'Auth\LoginController@redirectToFacebook')->name('login.facebook');
Route::get('login/facebook/callback', 'Auth\LoginController@handleFacebookCallback');

Route::get('login/google', 'Auth\LoginController@redirectToGoogle')->name('login.google');
Route::get('login/google/callback', 'Auth\LoginController@handleGoogleCallback');

Route::get('/home', 'HomeController@index')->name('home');

Route::get('forget-password', 'ForgotPasswordController@showForgetPasswordForm')->name('forget.password.get');
Route::post('forget-password', 'ForgotPasswordController@submitForgetPasswordForm')->name('forget.password.post');
Route::get('reset-password/{token}', 'ForgotPasswordController@showResetPasswordForm')->name('reset.password.get');
Route::post('reset-password', 'ForgotPasswordController@submitResetPasswordForm')->name('reset.password.post');

Route::get('login-details','NewUserController@user_store');

Route::post('project/importProject', 'ProjectController@importProject')->name('importProject');
Route::resource('project', 'ProjectController');


<file_sep>/app/Http/Controllers/SaleApiController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use RealRashid\SweetAlert\Facades\Alert;
use Haruncpi\LaravelIdGenerator\IdGenerator;
use DB;
use App\Http\Requests\SaleRequest;
use Illuminate\Support\Facades\Input;
use App\Product;
use App\SaleTemp;
use Illuminate\Support\Facades\Response;
use \Auth, \Redirect, \Validator, \Session;

class SaleApiController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        return Response::json(SaleTemp::with('product')->get());
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $SaleTemps = new SaleTemp;
        $SaleTemps->product_id = $request->product_id;
        $SaleTemps->cost_price = $request->cost_price;
        $SaleTemps->selling_price = $request->selling_price;
        $SaleTemps->quantity = 1;
        $SaleTemps->total_cost = $request->cost_price;
        $SaleTemps->total_selling = $request->selling_price;
        //dd($request->all());
        $SaleTemps->save();
        return $SaleTemps;
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $SaleTemps = SaleTemp::find($id);
        $SaleTemps->quantity      = $request->quantity;
        // $SaleTemps->total_cost    = $request->cost_price;
        // $SaleTemps->total_selling = $request->selling_price;
        $SaleTemps->save();
        return $SaleTemps;
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        SaleTemp::destroy($id);
    }
}
<file_sep>/app/Http/Controllers/ReceivingApiController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Product;
use App\RecevingTemp;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Response;

class ReceivingApiController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return Response::json(RecevingTemp::with('product')->get());
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $type = $request->type;
        if ($type == 1) {
            $ReceivingTemps = new RecevingTemp;
            $ReceivingTemps->product_id = $request->product_id;
            $ReceivingTemps->cost_price = $request->cost_price;
            $ReceivingTemps->total_cost = $request->total_cost;
            $ReceivingTemps->quantity = 1;
            $ReceivingTemps->save();
            return $ReceivingTemps;
        } 
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $ReceivingTemps = RecevingTemp::find(3);
        $ReceivingTemps->quantity = 5;
        $ReceivingTemps->total_cost = 54;
        $ReceivingTemps->save();
        return $ReceivingTemps;
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        RecevingTemp::destroy($id);
    }
}
<file_sep>/app/Http/Controllers/NewUserController.php
<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use Illuminate\Support\Facades\Hash;
// use Illuminate\Support\Facades\Auth;
use App\Mail\UserMail;
use Mail;
use Illuminate\Support\Str;
use Crypt;

class NewUserController extends Controller
{


    public function user_store(Request $request)
    {
        //dd($request->all());
        $this->validate($request,[

            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            // 'usertype' => ['string', 'max:255']

        ]);

        $password = Str::random(6);

        $data = [
            'name'=> $request->get('name'),
            'email'=> $request->get('email'),
            'password'=> <PASSWORD>($<PASSWORD>),
            'usertype'=> $request->get('usertype')
        ];

            if(User::create($data)){

                $email = $data['email'];
                $details = [
                    'name' => $data['name'],
                    'email'=> $data['email'],
                    'password' => <PASSWORD>
                ];

                //dd($details['<PASSWORD>']);
                Mail::to($email)->send(new UserMail($details));

                return response()->json(['success_info'=>'<h6>You have succesfully registered a new user!</h6>']);

            }

    }
}
<file_sep>/app/Http/Controllers/HomeController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\AdminProfile;
use App\User;
class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        if(Auth()->user()->usertype == 'User'){

            return redirect('/staff_dashboard');
        }
        elseif(Auth()->user()->usertype == 'Admin')
        {
            return redirect('/dashboard');
        }
        
    }
    
}
<file_sep>/public/js/protractor.js

it('should remove the template directive and css class', function() {
    expect($('#template1').getAttribute('ng-cloak')).
      toBeNull();
    expect($('#template2').getAttribute('ng-cloak')).
      toBeNull();
      expect($('#template3').getAttribute('ng-cloak')).
      toBeNull();
    expect($('#template4').getAttribute('ng-cloak')).
      toBeNull();
      expect($('#template5').getAttribute('ng-cloak')).
      toBeNull();
    expect($('#template6').getAttribute('ng-cloak')).
      toBeNull();
      expect($('#template7').getAttribute('ng-cloak')).
      toBeNull();
    expect($('#template8').getAttribute('ng-cloak')).
      toBeNull();
      expect($('#template9').getAttribute('ng-cloak')).
      toBeNull();
  });<file_sep>/app/Staffs.php
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
// use Illuminate\Database\Eloquent\SoftDeletes;
use Haruncpi\LaravelIdGenerator\IdGenerator;
class Staffs extends Model
{
    // use SoftDeletes;


    protected $fillable = [
        'address','phone','city','photo','date_of_birth','date_employed','department','salary',
        'experience','status','slug'
    ];

    // protected $dates = ['deleted_at'];

    public function user(){
        return $this->belongs('App\User');
    }

    public function admin_profiles(){
        return $this->belongsTo('App\AdminProfile');
    }

    public function customers(){
        return $this->hasMany('App\Customers','id');
    }

    public function suppliers(){
        return $this->hasMany('App\Supplier','id');
    }

    public static function boot()
    {
        parent::boot();

        self::creating(function ($model) {
            $model->uuid= IdGenerator::generate(['table' => 'staffs', 'length' => 10, 'prefix' =>date('ym')]);
        });
    }

}
<file_sep>/app/Http/Controllers/StaffController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Haruncpi\LaravelIdGenerator\IdGenerator;
use RealRashid\SweetAlert\Facades\Alert;
use App\Staffs;
use App\User;
use App\AdminProfile;
use App\Customers;
use DB;


class StaffController extends Controller
{

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */

    public function Staff_dashboard()
    {
        if(Auth()->user()->usertype == 'User'){

            return view("staffs.dashboard");

        }else
        {
            notify()->warning("Access Denied!","Caution");

            return redirect()->back();
        }


    }

    public function index()
    {
        // $staffs = Staffs::orderBy('id','asc')->get();
        // return view('staffs.index')->with('staffs',$staffs);

        // $recs = array();
         //$users = DB::table("users")->select("id","name","email","usertype")->get();
        // array_push($recs,$users);
        // $staffs = DB::table("staffs")->select("user_id","photo","phone","department","experience")->get();
        // array_push($recs,$staffs);
        // dd($recs);
        // return view('staffs.index')->with('recs',$recs);

        // $users = DB::table("users")->select("id","name","email","usertype")->get();
        // $staffs = DB::table("staffs")->select("user_id","photo","phone","department","experience")->get();
        // $merged = $users->merge($staffs);
        // $recs = $merged->all();
        // dd($recs);
        // return view('staffs.index')->with('recs',$recs);

        $recs = array();
        $staff_rec_arr = array();
        $users = DB::table("users")->select("id","name","email","status","usertype")->get();
        foreach ($users as $user){
            if($user->usertype == "Admin") continue;
            $staff_rec = Staffs::where("user_id","=",$user->id)->get();

            if(!empty($staff_rec[0])){
                $staff_rec_arr["user_id"]    =  $user->id;
                $staff_rec_arr["id"]         =  $staff_rec[0]->id;
                $staff_rec_arr["photo"]      =  $staff_rec[0]->photo;
                $staff_rec_arr["phone"]      =  $staff_rec[0]->phone;
                $staff_rec_arr["name"]       =  $user->name;
                $staff_rec_arr["email"]      =  $user->email;
                $staff_rec_arr["status"]     =  $user->status;
                $staff_rec_arr["usertype"]   =  $user->usertype;
                $staff_rec_arr["department"] =  $staff_rec[0]->department;
                array_push($recs,$staff_rec_arr);

            }else{
                $staff_rec_arr["user_id"]    =  $user->id;
                $staff_rec_arr["photo"]      =  "";
                $staff_rec_arr["id"]         =  "";
                $staff_rec_arr["name"]       =  $user->name;
                $staff_rec_arr["email"]      =  $user->email;
                $staff_rec_arr["status"]      = $user->status;
                $staff_rec_arr["usertype"]   =  $user->usertype;
                $staff_rec_arr["phone"]      =  "";
                $staff_rec_arr["department"] =  "";
                array_push($recs,$staff_rec_arr);
            }


        }
                //dd($recs);
            //  $data = $this->paginate($recs);

            return view('staffs.index')->with('recs',$recs);



    }

    // public function paginate($items, $perPage = 3, $page = null, $options = [])
    // {
    //     $pageName = 'page';
    //     $page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
    //     //dd($page);
    //     $items = $items instanceof Collection ? $items : Collection::make($items);
    //     //dd($items);
    //     return new LengthAwarePaginator(
    //         $items->forPage($page, $perPage)->values(),
    //         $items->count(),
    //         $perPage,
    //         $page,
    //         [
    //             'path'     => Paginator::resolveCurrentPath(),
    //             'pageName' => $pageName,
    //         ]
    //     );

    // }

    public function changeStatus(Request $request, $id)
    {
        $rec = User::find($request->id);

        if ($rec->status == 0) {
            # code...
            $rec->status=1;
        }else{
            $rec->status=0;
        }
       if($rec->save()){

        notify()->info(" Status has been changed successfully!","Success!");

       }

        return redirect()->back();
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('staffs.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request,[

            'address' => 'required',
            'phone' => 'required',
            'city' => 'required',
            'photo' => 'image|nullable|max:1999',
            'date_of_birth' => 'required',
            'date_employed' => 'required',
            'department' => 'required',
            'experience' => 'required',
            'status' => 'required'
        ]);

        //Handle file uploads
        if($request->hasFile('photo')){
            //Get file name with the extension
            $fileNameWithExt = $request->file('photo')->getClientOriginalName();
            //Get just filename
            $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
            //Get just extension
            $extension = $request->file('photo')->getClientOriginalExtension();
            //Filename to store
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            //Upload image
            $path = $request->file('photo')->storeAs('public/photo',$fileNameToStore);
            } else {
            $fileNameToStore = 'noimage.jpg';
            }

            //dd($request->all());
            $staff = new Staffs;
            $staff->address = $request->address;
            $staff->user_id = auth()->user()->id;
            $staff->user_name = auth()->user()->name;
            $staff->user_email = auth()->user()->email;
            $staff->user_usertype = auth()->user()->usertype;
            $staff->phone = $request->phone;
            $staff->city = $request->city;
            $staff->photo = $fileNameToStore;
            $staff->slug = Str::slug($request->status);
            $staff->date_of_birth = $request->date_of_birth;
            $staff->date_employed = $request->date_employed;
            $staff ->department = $request->department;
            $staff->experience = $request->experience;
            $staff->status = $request->status;

            if($staff->save()){

                notify()->success("Profile Created!","Success");

            }else{
                notify()->error("There was a problem creating your profile!","Error");
            }

            return redirect('staff_dashboard');

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $staff = Staffs::find($id);
       //dd($staff);

         return view('staffs.show')->with('staff',$staff);

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $staff = Staffs::find($id);
        //$staff_info = User::find($staff);
        //dd($staff_info);
        return view('staffs.edit')->with('staff',$staff);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request,[

            'address' => 'required',
            'phone' => 'required',
            'city' => 'required',
            'date_of_birth' => 'required',
            'date_employed' => 'required',
            'department' => 'required',
            'experience' => 'required',
            'status' => 'required'
        ]);

        if($request->hasFile('photo')){
            //Get file name with the extension
            $fileNameWithExt = $request->file('photo')->getClientOriginalName();
            //Get just filename
            $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
            //Get just extension
            $extension = $request->file('photo')->getClientOriginalExtension();
            //Filename to store
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            //Upload image
            $path = $request->file('photo')->storeAs('public/photo',$fileNameToStore);
            }
            //dd($request->all());
            $staff = Staffs::find($id);
            $staff->address = $request->address;
            $staff->phone = $request->phone;
            $staff->city = $request->city;
            $staff->date_of_birth = $request->date_of_birth;
            $staff->date_employed = $request->date_employed;
            $staff ->department = $request->department;
            $staff->experience = $request->experience;
            $staff->status = $request->status;

            if($request->hasFile('photo')){
                $staff->photo = $fileNameToStore;
            }

            if($staff->save()){

                notify()->success("Profile Updated!","Success");

            }else{
                notify()->error("There was a problem updating your profile!","Error");
            }

            return redirect()->back();
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $user = User::findorfail($id);

        $user->delete();

        notify()->success("User Deleted!","Success");

        return redirect()->back();
    }

    // public function trashed()
    // {
    //     $staff = Staffs::onlyTrashed()->get();

    //     return view('staffs.trashed')->with('staff',$staff);
    // }

    // public function restore($id)
    // {
    //     $staff = Staffs::withTrashed()->where('id',$id)->first();

    //     $staff->restore();

    //     alert()->success('Success','Staff Restored!');

    //     return redirect()->back();
    // }

    public function kill($id)
    {
        // $staff = Staffs::withTrashed()->where('id',$id)->first();

        // if($staff->photo !== 'noimage.jpg'){
        //     //Delete image
        //     Storage::delete('public/photo/'.$staff->photo);
        // }

        // $delete_act = $staff->forceDelete();

        // $staff = Staffs::findorfail($id);

        // $delete_act = $staff->delete();

        // if($delete_act)
        // {
        //     $del =  DB::select("delete from users where id = '$staff->user_id'");
        // }


        $user = User::findorfail($id);

        $delete_act = $user->delete();

        if($delete_act)
        {
            $del =  DB::select("delete from staffs where user_id = '$user->id'");
        }
        notify()->success("Staff Deleted!","Success");

        return redirect()->back();
    }
}
<file_sep>/app/Http/Controllers/ReceivingController.php
<?php

namespace App\Http\Controllers;

use App\User;
use DB;
use App\Supplier;
use App\Product;
use App\Receving;
use App\Recevingitem;
use App\RecevingPayment;
use App\RecevingTemp;
use App\Inventory;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;

class ReceivingController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $receivings = Receving::orderBy('id', 'desc')->first();
        //dd($receivings);
        $suppliers = Supplier::all();
        return view('receiving.index')->with('suppliers', $suppliers); 
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //dd($request->all());
        $this->validate($request,[

            'supplier_id'=>'required',
            'payment_type'=>'required',
            'total'=>'required',
            'payment'=>'required'
    
            ]);
    
            $receivingItems = RecevingTemp::all();
           // dd($receivingItems);
            if(empty($receivingItems->toArray())) {
                notify()->error("Please Add some Items to create purchase!","Error");
                return back();
            }
    
            $receiving = new Receving;
            $receiving->supplier_id = $request->supplier_id;
            $receiving->user_id = Auth::user()->id;
            $receiving->payment_type = $request->payment_type;
            $payment = $receiving->payment = $request->payment;
            $total = $receiving->total = $request->total;
            $dues = $receiving->dues = $total - $payment;
            $receiving->comments = $request->comments;

            if ($dues > 0) {
                $receiving->status = 0;
            } else {
                $receiving->status = 1;
            }
            $receiving->save();
    
            $supplier = Supplier::findOrFail($receiving->supplier_id);
            $supplier->prev_balance = $supplier->prev_balance + $dues;
            $supplier->update();
            if ($request->payment > 0) {
                $payment = new RecevingPayment;
                $paid = $payment->payment = $request->payment;
                $payment->dues = $total - $paid;
                $payment->payment_type = $request->payment;
                $payment->comments = $request->comments;
                $payment->receiving_id = $receiving->id;
                $payment->user_id = Auth::user()->id;
                $payment->save();
            }
    
            $receivingItemsData=[];
            foreach ($receivingItems as $value) {
                $receivingItemsData = new RecevingItem;
                $receivingItemsData->receiving_id = $receiving->id;
                $receivingItemsData->product_id = $value->product_id;
                $receivingItemsData->cost_price = $value->cost_price;
                $receivingItemsData->quantity = $value->quantity;
                $receivingItemsData->total_cost = $value->total_cost;
                $receivingItemsData->save();
                //process inventory
                $products = Product::find($value->product_id);
                if ($products->type == 1) {
                    $inventories = new Inventory;
                    $inventories->product_id = $value->product_id;
                    $inventories->user_id = Auth::user()->id;
                    $inventories->in_out_qty = -($value->quantity);
                    $inventories->remarks = 'PURCHASE' . $receiving->id;
                    $inventories->save();
                    //process product quantity
                    $products->quantity = $products->quantity - $value->quantity;
                    $products->save();
                } 
            }
    
             //delete all data on SaleTemp model
             RecevingTemp::truncate();
             $itemsreceiving = RecevingItem::where('receiving_id', $receivingItemsData->receiving_id)->get();
             notify()->success("You have successfully added Purchases!","Success");
                 return view('receiving.complete')
                     ->with('receiving', $receiving)
                     ->with('receivingItemsData', $receivingItemsData)
                     ->with('receivingItems', $itemsreceiving);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
<file_sep>/app/Http/Controllers/CategoryController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use RealRashid\SweetAlert\Facades\Alert;
use App\Staffs;
use App\User;
use App\AdminProfile;
use DB;
use App\Customers;
use App\Suppliers;
use App\Product;
use App\Category;

class CategoryController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $categories = Category::withCount('products')->paginate(10);
        //dd($categories);
        return view('category.index')->with('categories',$categories);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('category.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
       $this->validate($request,[

                'cat_image'=>'image|nullable|max:1999',
                'cat_name'=>'required|max:185'
            ]);
    
                 //Handle file uploads
            if($request->hasFile('cat_image')){
                //Get file name with the extension
                $fileNameWithExt = $request->file('cat_image')->getClientOriginalName();
                //Get just filename
                $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
                //Get just extension
                $extension = $request->file('cat_image')->getClientOriginalExtension();
                //Filename to store
                $fileNameToStore = $filename.'_'.time().'.'.$extension;
                //Upload image
                $path = $request->file('cat_image')->storeAs('public/cat_image',$fileNameToStore);
                } else {
                $fileNameToStore = 'noimage.jpg';
                }

                //dd($request->all());
                $category = new Category;
                
                $category->cat_name = $request->cat_name;
                
                if($request->hasFile('cat_image')){
                    $category->cat_image = $fileNameToStore;
                }
    
                if($category->save()){
                    
                    notify()->success("Category Added!","Success");
    
                }
    
                return redirect()->route('categories.index');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $category = Category::findorfail($id);
        return view('category.edit')->with('category',$category);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request,[

                'cat_name'=>'required|max:185'
            ]);
    
                 //Handle file uploads
            if($request->hasFile('cat_image')){
                //Get file name with the extension
                $fileNameWithExt = $request->file('cat_image')->getClientOriginalName();
                //Get just filename
                $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
                //Get just extension
                $extension = $request->file('cat_image')->getClientOriginalExtension();
                //Filename to store
                $fileNameToStore = $filename.'_'.time().'.'.$extension;
                //Upload image
                $path = $request->file('cat_image')->storeAs('public/cat_image',$fileNameToStore);
                } else {
                $fileNameToStore = 'noimage.jpg';
                }
                //dd($request->all());
                $category = Category::find($id);
                
                $category->cat_name = $request->cat_name;
                
                if($request->hasFile('cat_image')){
                    $category->cat_image = $fileNameToStore;
                }
    
                if($category->save()){
                    
                    notify()->success("Category Updated!","Success");
    
                }
    
                return redirect()->route('categories.index');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $category = Category::findorfail($id);

        $category->delete();
        
        notify()->success("Category Deleted!","Success");

        return redirect()->back();
    }
}
<file_sep>/app/Http/Controllers/AccountController.php
<?php

namespace App\Http\Controllers;

use App\Account;
use Illuminate\Http\Request;

class AccountController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $accounts = Account::orderBy('id','asc')->get();
        return view('accounts.index')->with('accounts',$accounts);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('accounts.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request,[

            'account_no' => 'max:100',
            'name' => 'required|max:100',
            'company' => 'required|max:100',
            'branch' => 'max:100',
            'email' => 'max:100',
            'balance' => 'required|numeric|max:9999999999'
        ]);

            $account = new Account;

            $account->account_no = $request->account_no;
            $account->name = $request->name;
            $account->company = $request->company;
            $account->branch = $request->branch;
            $account->user_id = auth()->user()->id;
            $account->email = $request->email;
            $account->balance = $request->balance;

            $account->save();

            notify()->success("Account Created!","Success");
            return redirect()->back();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $account = Account::findorfail($id);

        return view('accounts.edit')->with('account',$account);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request,[

            'account_no' => 'max:100',
            'name' => 'required|max:100',
            'company' => 'required|max:100',
            'branch' => 'max:100',
            'email' => 'max:100',
            'balance' => 'required|numeric|max:9999999999'
        ]);

             $account = Account::find($id);
            
             $account->account_no = $request->account_no;
             $account->name = $request->name;
             $account->company = $request->company;
             $account->branch = $request->branch;
             $account->email = $request->email;
             $account->balance = $request->balance;

             $account->save();

             notify()->success("Account Updated!","Success");
             return redirect()->back();

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $account = Account::find($id);

        $account->delete();
        
        notify()->success("Account Deleted!","Success");
        return redirect()->back();
    }
}
<file_sep>/public/assets/js/page/index.js
"use strict";
var chartTextColor = '#96A2B4';

if ($("#message-list").length) {
	$("#message-list").css({
		height : 400
	}).niceScroll();
}

/* chart shadow */
var draw = Chart.controllers.line.prototype.draw;
Chart.controllers.lineShadow = Chart.controllers.line.extend({
	draw : function() {
		draw.apply(this, arguments);
		var ctx = this.chart.chart.ctx;
		var _stroke = ctx.stroke;
		ctx.stroke = function() {
			ctx.save();
			ctx.shadowColor = '#00000075';
			ctx.shadowBlur = 10;
			ctx.shadowOffsetX = 8;
			ctx.shadowOffsetY = 8;
			_stroke.apply(this, arguments)
			ctx.restore();
		}
	}
});


function monthlySalesChart() {
	// $data = document.getElementById('#monthlySalesChart').innerHTML;
	var options = {
		chart : {
			height : 300,
			type : 'bar',
			foreColor : chartTextColor,
			stacked: true,
			toolbar : {
				show : false,
			}
		},
		colors:['#fab107', '#9C27B0'],
		plotOptions : {
			bar : {
				horizontal : false,
				//endingShape : 'rounded',
				columnWidth : '55%',
			},
		},
		dataLabels : {
			enabled : false
		},
		stroke : {
			show : true,
			width : 2,
			colors : [ 'transparent' ]
		},
		series : [{
			name : 'Revenue',
			data : [ 44, 55, 57, 56, 61, 58, 63, 60, 66, 53, 57, 61 ]
		}, {
			name : 'Expense',
			data : [ 76, 85, 99, 98, 87, 95, 91, 98, 94, 83, 93, 98 ]
		} ],
		xaxis : {
			categories : [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
					'Aug', 'Sep', "Oct", "Nov", "Dec" ],

		},
		yaxis : {
			title : {
				text : '$ (thousands)'
			}
		},
		fill : {
			opacity : 1

		},
		tooltip : {
			y : {
				formatter : function(val) {
					return "$ " + val + " thousands"
				}
			}
		}
	}

	var chart = new ApexCharts(document.querySelector("#monthlySalesChart"), options);

	chart.render();

}

monthlySalesChart();

function yearlySalesChart() {
	var options = {
		chart : {
			height : 315,
			type : 'line',
			foreColor : chartTextColor,
			shadow : {
				enabled : false,
				color : '#bbb',
				top : 3,
				left : 2,
				blur : 3,
				opacity : 1
			},
			toolbar : {
				show : false,
			}
		},
		stroke : {
			width : 7,
			curve : 'smooth'
		},
		series : [ {
			name : 'revenue',
			data : [ 190, 243, 150, 301, 333, 230, 401, 346, 505, 618, 567 ]
		} ],
		xaxis : {
			type : 'year',
			categories : [ '2009', '2010', '2011', '2012', '2013', '2014',
					'2015', '2016', '2017', '2018', '2019', ],
		},

		fill : {
			type : 'gradient',
			gradient : {
				shade : 'dark',
				gradientToColors : [ '#f635fd' ],
				inverseColors: true,
				shadeIntensity : 1,
				type : 'horizontal',
				opacityFrom : 1,
				opacityTo : 1,
				stops: [50, 100],
			    colorStops: ["#b435fd","#fd5035"]
			},
		},
		markers : {
			size : 4,
			opacity : 0.9,
			colors : [ "#FFA41B" ],
			strokeColor : "#fff",
			strokeWidth : 2,

			hover : {
				size : 7,
			}
		},
		yaxis : {
			min : 0,
			max : 700,
			title : {
				text : '$ (thousands)',
			},
		}
	}

	var chart = new ApexCharts(document.querySelector("#yearlySalesChart"), options);

	chart.render();
}

yearlySalesChart();

function salesByCountriesChart() {
	var chart = document.getElementById('salesByCountriesChart');
	var barChart = echarts.init(chart);

	barChart.setOption({
		tooltip : {
			trigger : "item",
			formatter : "{a} <br/>{b} : {c} ({d}%)"
		},

		calculable : !0,
		series : [ {
			name : "Chart Data",
			type : "pie",
			radius : "55%",
			center : [ "50%", "48%" ],
			data : [ {
				value : 8500,
				name : "India"
			}, {
				value : 9500,
				name : "USA"
			}, {
				value : 1600,
				name : "Cambodia"
			}, {
				value : 6100,
				name : "Germany"
			} ]
		} ],
		color : [ '#575B7A', '#fc544b', '#ffc107', '#50A5D8' ]
	});
}

salesByCountriesChart();
<file_sep>/app/Http/Controllers/ChartsController.php
<?php

namespace App\Http\Controllers;

use App\User;
use App\Customers;
use App\Product;
use App\Sale;
use App\Supplier;
use App\Receiving;
use App\Expense;
use App\Staffs;
use Carbon;

use Illuminate\Http\Request;

class ChartsController extends Controller
{
    public function index()
    {
        $items = Product::where('type', 1)->count();
        $expenses = Expense::count();
        $customers = Customers::count();
        $suppliers = Supplier::count();
        $receivings = Receiving::count();
        $sales = Sale::count();
        $employees = Staffs::count();
        dd($employees);
        // $incomeexpensechart = $this->incomeExpenseChart();
        return view('adminprofile.dashboard')
            ->with('products', $products)
            ->with('expenses', $expenses)
            ->with('customers', $customers)
            ->with('suppliers', $suppliers)
            ->with('receivings', $receivings)
            ->with('sales', $sales)
            ->with('employees', $employees);
            
            // ->with('incomeexpensechart', $incomeexpensechart);
    }

    // private function getDatesOfWeek()
    // {
    //     $days = array();
    //     $days[] = date("Y-m-d", strtotime('-14 days'));
    //     $days[] = date("Y-m-d", strtotime('-13 days'));
    //     $days[] = date("Y-m-d", strtotime('-12 days'));
    //     $days[] = date("Y-m-d", strtotime('-11 days'));
    //     $days[] = date("Y-m-d", strtotime('-10 days'));
    //     $days[] = date("Y-m-d", strtotime('-9 days'));
    //     $days[] = date("Y-m-d", strtotime('-8 days'));
    //     $days[] = date("Y-m-d", strtotime('-7 days'));
    //     $days[] = date("Y-m-d", strtotime('-6 days'));
    //     $days[] = date("Y-m-d", strtotime('-5 days'));
    //     $days[] = date("Y-m-d", strtotime('-4 days'));
    //     $days[] = date("Y-m-d", strtotime('-3 days'));
    //     $days[] = date("Y-m-d", strtotime('-2 days'));
    //     $days[] = date("Y-m-d", strtotime('-1 days'));
    //     $days[] = date("Y-m-d", strtotime('0 days'));

    //     return $days;
    // }

    // public function getMonthListFromDate(Carbon $start)
    // {
    //     $start = $start->startOfMonth();
    //     $end = Carbon::today()->startOfMonth();
    //     do{
    //         $months[$start->format('m-Y')] = $start->format('F Y');
    //     }while ($start->addMonth() <= $end);
    //         dd($months);
    //         return $months;
    // }

    // public function incomeExpenseChart()
    // {
    //     $monthsOfYear = $this->getMonthListFromDate();
    //     $incomes = Sale::whereBetween('created_at', [ $monthsOfYear[0], $monthsOfYear[11]])->get();
    //     $expenses = Receiving::whereBetween('created_at', [ $monthsOfYear[0], $monthsOfYear[11]])->get();
    //     $chartArray = array();
    //     foreach ($monthsOfYear as $month) {
    //         $monthlyincome = "0";
    //         $monthlyexpense = "0";
    //         $monthlyincome = Sale::whereBetween('created_at', [ $month ])->count();
    //         $monthlyexpense = Receiving::whereBetween('created_at', [ $month ])->count();
    //         $chart = [
    //             'y' => $month,
    //             'a' => $monthlyexpense,
    //             'b'=>$monthlyincome,
    //         ];
    //         $chartArray[] =  $chart;
           
    //     }
    //     return $chartArray;
    // }
}
<file_sep>/app/Product.php
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Haruncpi\LaravelIdGenerator\IdGenerator;

class Product extends Model
{

     //Table Name
     protected $table = 'products';
     //Primary Key
      public $primaryKey = 'id';
     //Timestamps
     public $timestamps = true;

    public function sales(){

        return $this->hasMany('App\Sales','id');
    }

    public function inventory()
    {
        return $this->hasMany('App\Inventory')->orderBy('id', 'DESC');
    }

    public function categories(){

        return $this->belongsTo('App\Category','cat_id');
    }

    public function saletemp()
    {
        return $this->hasMany('App\SaleTemp')->orderBy('id', 'DESC');
    }

    public function saleitem()
    {
        return $this->hasMany('App\SaleItem');
    }


    public static function boot()
    {
        parent::boot();

        self::creating(function ($model) {
            $model->uuid = IdGenerator::generate(['table' => 'products', 'length' => 10, 'prefix' =>date('ym')]);
        });
    }
}
<file_sep>/database/seeds/CustomersTableSeeder.php
<?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Faker\Factory as Faker;

class CustomersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker = Faker::create();
    	foreach (range(1,20) as $index) {
	        DB::table('customers')->insert([
	            'name' => $faker->name,
                'email' => $faker->email,
                'phone_number' => $faker->e164PhoneNumber,
                'address' => $faker->address,
                'city' => $faker->city,
                'state' => $faker->state,
                'zip' => $faker->postcode,
                'company_name' => $faker->company,
                'account' =>$faker->creditCardType,
                'prev_balance' => '20000',
                'payment'=>$faker->randomNumber($nbDigits = 5, $strict = true),
                'created_at' => date("Y-m-d H:i:s"),
                'updated_at' => date("Y-m-d H:i:s")
	        ]);
	}
    }
}
<file_sep>/app/Http/Controllers/ExpenseCategoryController.php
<?php

namespace App\Http\Controllers;

use App\Expense;
use App\ExpenseCategory;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class ExpenseCategoryController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $expense_category = ExpenseCategory::all();
        return view('expense_cat.index')->with('expense_categories', $expense_category);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('expense_cat.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
       // dd($request->all());
        $this->validate($request,[
            'name'=> 'required|max:150',
            'description'=> 'required|max:150'
        ]);

        $expense_cat = new ExpenseCategory;
        $expense_cat->name = $request->name;
        $expense_cat->description = $request->description;
        $expense_cat->slug = Str::slug($request->description);

        $expense_cat->save();
        notify()->success('Expense Category added successfully!','Success');
        return redirect()->back();
        
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $expense_cat = ExpenseCategory::findOrFail($id);
        $expense_cats = ExpenseCategory::all();
        return view('expense_cat.show')->with('expense_cat', $expense_cat)
                                        ->with('expense_cats',$expense_cats);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
<file_sep>/app/Customers.php
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Customers extends Model
{
    protected $fillable = ['name', 'email', 'phone_number','avatar','address','city','state','zip','company','account','prev_balance','payment','prev_balance'];

    public function admin_profiles(){
        
        return $this->belongsTo('App\AdminProfile');

    }
    public function staffs(){
        
        return $this->belongsTo('App\Staffs');

    }

    public function user(){
        
        return $this->belongsTo('App\User');

    }
}
<file_sep>/app/Http/Controllers/SuppliersController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use RealRashid\SweetAlert\Facades\Alert;
use App\Staffs;
use App\User;
use App\AdminProfile;
use DB;
use App\Customers;
use App\Supplier;

class SuppliersController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $suppliers = Supplier::orderBy('id','asc')->get();
        return view('supplier.index')->with('suppliers',$suppliers);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('supplier.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request,[
         
            'sup_img'=>'image|nullable|max:1999',
            'name'=>'required|max:185',
            'email'=>'required|max:100',
            'address'=>'required|max:185',
            'company_name'=>'required|max:50',   
            'phone'=>'required|max:20',
            'city'=>'required',
            'state'=>'required',
            'country'=>'required',  
            'account'=>'max:20',
            'prev_balance'=>'max:9999999999|numeric',
            'payment'=>'max:9999999999|numeric|nullable' ,
            'postal_code'=>'required'
        ]);

             //Handle file uploads
        if($request->hasFile('sup_img')){
            //Get file name with the extension
            $fileNameWithExt = $request->file('sup_img')->getClientOriginalName();
            //Get just filename
            $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
            //Get just extension
            $extension = $request->file('sup_img')->getClientOriginalExtension();
            //Filename to store
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            //Upload image
            $path = $request->file('sup_img')->storeAs('public/sup_img',$fileNameToStore);
            } else {
            $fileNameToStore = 'noimage.jpg';
            }
            //dd($request->all());
            $supplier = new Supplier;
            
            $supplier->name = $request->name;
            $supplier->category = $request->category;
            $supplier->email = $request->email;
            $supplier->phone = $request->phone;
            $supplier->sup_img = $fileNameToStore;
            $supplier->address = $request->address;
            $supplier->company_name = $request->company_name;
            $supplier->city = $request->city;
            $supplier->state = $request->state;
            $supplier->country = $request->country;
            $supplier->postal_code = $request->postal_code;
            $supplier->comments = $request->comments;
            $supplier->payment = $request->payment;
            $supplier->prev_balance = $request->prev_balance;
            $supplier->account = $request->account;
            
            
            if($supplier->save()){

                notify()->success("Supplier Added!","Success");

            }

            return redirect()->back();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $supplier = Supplier::findorfail($id);
        return view('supplier.edit')->with('supplier',$supplier);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request,[

            'name'=>'required|max:185',
            'email'=>'required|max:100',
            'address'=>'required|max:185',
            'company_name'=>'required|max:50',   
            'phone'=>'required|max:20',
            'city'=>'required',
            'state'=>'required',
            'country'=>'required',   
            'postal_code'=>'required',
            'account'=>'max:20',
            'prev_balance'=>'max:9999999999|numeric',
            'payment'=>'max:9999999999|numeric|nullable'
        ]);

            //Handle file uploads
            if($request->hasFile('sup_img')){
                //Get file name with the extension
                $fileNameWithExt = $request->file('sup_img')->getClientOriginalName();
                //Get just filename
                $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
                //Get just extension
                $extension = $request->file('sup_img')->getClientOriginalExtension();
                //Filename to store
                $fileNameToStore = $filename.'_'.time().'.'.$extension;
                //Upload image
                $path = $request->file('sup_img')->storeAs('public/sup_img',$fileNameToStore);
                } else {
                $fileNameToStore = 'noimage.jpg';
                }

            //dd($request->all());
           // dd("am here");
            $supplier = Supplier::find($id);

            $supplier->name = $request->name;
            $supplier->email = $request->email;
            $supplier->phone = $request->phone;
            $supplier->address = $request->address;
            $supplier->company_name = $request->company_name;
            $supplier->city = $request->city;
            $supplier->state = $request->state;
            $supplier->country = $request->country;
            $supplier->postal_code = $request->postal_code;
            $supplier->comments = $request->comments;
            $supplier->payment = $request->payment;
            $supplier->prev_balance = $request->prev_balance;
            $supplier->account = $request->account;
            
            if($request->hasFile('sup_img')){
                $supplier->sup_image = $fileNameToStore;
            }

            if($supplier->save()){
                
                notify()->success("Supplier Updated!","Success");

            }

            return redirect()->back();
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $supplier = Supplier::findorfail($id);

        $supplier->delete();
        
        notify()->success("Supplier Deleted!","Success");

        return redirect()->back();
    }
}
<file_sep>/README.md
Stock-Management(POS):

A Sales POS web application built with laravel and angular js to cater for every business needs, built with the users in mind ensuring that they get
the maximum satisfation and a wonderful user experience.

Techstack:

-- Laravel 7
-- Angular
-- JS
-- Laravel Mix
-- Bootstrap
-- webpack
-- node Modules

Features:

Stock Adding and Managing
-- Customer Management, 
-- Supplier Management,
-- Sales Adding,
-- Purchases Adding,
-- POS(module)
-- Employee management system
-- Sales and purchases report
-- Accounts / Transactions
-- Income and Expenses
-- Invoicing 
-- Paystack Payment Integration


-- Run Composer install 

-- Run npm install

-- Create a copy of your .env file  e.g cp .env.example .env

-- Generate your app encryption key by running the following command
    php artisan key:generate
    
-- Create an empty database for your application

-- In the .env file, add database information to allow Laravel to connect to the database

-- Migrate the database using this command
    php artisan migrate
    
-- Optional: Seed the database using - php artisan db:seed

Then lastly, run your app either by configuring a virtual host or by simply serving it with 
- php artisan serve which generates a server for you @ localhost:8000

Enjoy : )
<file_sep>/app/Http/Controllers/AdminProfileController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use App\AdminProfile;
use App\Staffs;
use App\User;
use App\Customers;
use App\Product;
use App\Supplier;
use App\Sale;
use App\SaleItem;
use DB;
use Carbon\Carbon;
use Carbon\CarbonPeriod;
use RealRashid\SweetAlert\Facades\Alert;




class AdminProfileController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */

    public function admin_dashboard()
    {
        if(Auth()->user()->usertype == 'Admin'){

            $id = Auth::user()->id;
            $items = Product::where('type', 1)->count();
            $customers = Customers::count();
            $staff = Staffs::count();
            $sales = DB::table('sales')->where('user_id', $id)->sum('grand_total');
            $latest = Sale::orderBy('id','desc')->take(7)->get();
            // DB::table('sales')->sum('grand_total')
            // $incomeexpensechart = $this->incomeExpenseChart();
            return view("adminprofile.dashboard")
            ->with('items', $items)
            ->with('staff', $staff)
            ->with('customers', $customers)
            ->with('sales', $sales)
            ->with('latest', $latest);
            // ->with('incomeexpensechart', $incomeexpensechart);

        }

    }

    // public function getMonthListFromDate(Carbon $start)
    // {
    //     foreach (CarbonPeriod::create($start, '1 month', Carbon::today()) as $month){
    //         $months[$months[$month->format('m-Y')]] = $month->format('F Y');
    //     }
    //         return $months;
    // }

    // public function incomeExpenseChart()
    // {
    //     $monthsOfYear = $this->getMonthListFromDate();
    //     $incomes = Sale::whereBetween('created_at', [ $monthsOfYear[0], $monthsOfYear[11]])->get();
    //     $expenses = Receiving::whereBetween('created_at', [ $monthsOfYear[0], $monthsOfYear[11]])->get();
    //     $chartArray = array();
    //     foreach ($monthsOfYear as $month) {
    //         $monthlyincome = "0";
    //         $monthlyexpense = "0";
    //         $monthlyincome = Sale::whereBetween('created_at', [ $month ])->count();
    //         $monthlyexpense = Receiving::whereBetween('created_at', [ $month ])->count();
    //         $chart = [
    //             // 'y' => $month,
    //             'a' => $monthlyexpense,
    //             'b'=>$monthlyincome,
    //         ];
    //         $chartArray[] =  $chart;

    //     }
    //     return $chartArray;
    // }

    public function index()
    {
        $admins = AdminProfile::all();
        return view("adminprofile.index")->with('admins',$admins);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view("adminprofile.create");
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //dd($request->all());
        $this->validate($request,[

            'address' => 'required',
            'phone' => 'required',
            'no_of_staff' => 'required',
            'admin_image' => 'image|nullable|max:1999',
            'objective' => 'required',
            'company_name' => 'required'

        ]);

        //Handle file upload
        if($request->hasFile('admin_image')){
            //Get file name with the extension
            $fileNameWithExt = $request->file('admin_image')->getClientOriginalName();
            //Get just filename
            $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
            //Get just extension
            $extension = $request->file('admin_image')->getClientOriginalExtension();
            //Filename to store
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            //Upload image
            $path = $request->file('admin_image')->storeAs('public/admin_image',$fileNameToStore);
            }else {
                $fileNameToStore = 'noimage.jpg';
                }


            $admin = new AdminProfile;
            $admin->address = $request->address;
            $admin->user_id = auth()->user()->id;
            $admin->user_name = auth()->user()->name;
            $admin->user_email = auth()->user()->email;
            $admin->user_usertype = auth()->user()->usertype;
            $admin->phone = $request->phone;
            $admin->no_of_staff = $request->no_of_staff;
            $admin->admin_image = $fileNameToStore;
            $admin->objective = $request->objective;
            $admin->company_name = $request->company_name;

           if($admin->save()){

            notify()->success("Profile Created!","Success");
           }
           else{
            notify()->error("There was a problem creating your profile!","Error");
           }



            return redirect('/dashboard');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
      $admin = AdminProfile::find($id);
      //dd($admin);
      return view('adminprofile.show')->with('admin',$admin);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
      $admin = AdminProfile::find($id);
        //dd($admin->all());
      return view('adminprofile.edit')->with('admin',$admin);
    }
    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
       dd($request->all());
        $this->validate($request,[

            'address' => 'required',
            'phone' => 'required',
            'no_of_staff' => 'required',
            'objective' => 'required',
            'company_name' => 'required'
        ]);

        if($request->hasFile('admin_image')){
            //Get file name with the extension
            $fileNameWithExt = $request->file('admin_image')->getClientOriginalName();
            //Get just filename
            $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
            //Get just extension
            $extension = $request->file('admin_image')->getClientOriginalExtension();
            //Filename to store
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            //Upload image
            $path = $request->file('admin_image')->storeAs('public/admin_image',$fileNameToStore);
            }

            $admin = AdminProfile::find($id);
            $admin->address = $request->address;
            $admin->phone = $request->phone;
            $admin->no_of_staff = $request->no_of_staff;
            $admin->objective = $request->objective;
            $admin->company_name = $request->company_name;

            if($request->hasFile('admin_image')){
                $admin->admin_image = $fileNameToStore;
            }

            if($admin->save()){
             notify()->success("Profile Updated!","Success");

            }else{
                notify()->error("There was a problem creating your profile!","Error");
               }

            return redirect()->back();
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
{
        $admin_user = User::whereId($id);
       //dd($admin_user);
        /*if($admin_user->admin_image !== 'noimage.jpg'){
        //Delete image
            Storage::delete('public/admin_image/'.$admin_user->admin_image);
        }*/
        $admin_user->delete();
        return redirect('/');
    }

}
<file_sep>/app/Http/Controllers/TransactionsController.php
<?php

namespace App\Http\Controllers;

use App\Account;
use App\Transaction;
use Illuminate\Http\Request;

class TransactionsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {   $account = Account::orderBy('id','desc')->get();   
        $transactions = Transaction::orderBy('id','asc')->get();
        return view('transactions.index')->with('transactions',$transactions)
                                        ->with('account',$account);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $accounts = Account::orderBy('id','desc')->get();
        //dd($account);
        return view('transactions.create')->with('accounts',$accounts);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request,[

            'transaction_type'=>'required',
            'account_id'=>'required',
            'transaction_with'=>'required',
            'amount'=>'required'
        ]);

            $transaction = new Transaction;

            $transaction->transaction_type = $request->transaction_type;
            $transaction->user_id = auth()->user()->id;
            $transaction->account_id = $request->account_id;
            $transaction->transaction_with = $request->transaction_with;
            $transaction->amount = $request->amount;
            $transaction->updateAccountBalance('create');
            $transaction->save();

            notify()->success("Transaction Created!","Success");
            return redirect()->back();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $account = Account::orderBy('id','desc')->get();
        $transaction = Transaction::findOrFail($id);
        return view('transactions.edit')->with('account', $account)
                                        ->with('transaction',$transaction);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        notify()->error("Transaction Can not be edited!","Error");
        return redirect()->back();
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $transaction = Transaction::findorfail($id);
        $transaction->updateAccountBalance('delete');
        $transaction->delete();
        
        notify()->error("You have successfully deleted Transaction!","Error");
        return redirect()->back();
    }
}
<file_sep>/app/Http/Controllers/CustomersController.php
<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use RealRashid\SweetAlert\Facades\Alert;
use App\Staffs;
use App\User;
use App\AdminProfile;
use DB;
use App\Customers;

class CustomersController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $customers = Customers::orderBy('id','desc')->get();
        return view('customers.index')->with('customers',$customers);
        
    }

    public function Customer_PDF()
    {
        $customer_pdf = Customers::orderBy('id','desc')->get();
      
        $filename = 'Customers_list.pdf';
        $mpdf = new \Mpdf\Mpdf([
            'margin-left' => 10,
            'margin-left' => 10,
            'margin-left' => 15,
            'margin-left' => 20,
            'margin-left' => 10,
            'margin-left' => 10
        ]);

        $html = \View::make('customers.customerPDF')->with('customer_pdf',$customer_pdf);
        $html = $html->render();

        $mpdf->setHeader('xxxx|Customers|{PAGENO}');
        $mpdf->setFooter('Copyright StockBase Inc');
        $stylesheet = file_get_contents(url('css/customer_pdf.css'));
        $mpdf->WriteHTML($stylesheet,1);
        $mpdf->WriteHTML($html);
        $mpdf->Output($filename,'I');
        
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('customers.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request,[
         
            'avatar'=>'image|nullable|max:1999',
            'name'=>'max:185',
            'email'=>'max:100',
            'address'=>'max:185',
            'city'=>'max:185',
            'state'=>'max:185',
            'company_name'=>'max:150',
            'account'=>'max:150',
            'zip'=>'max:10',
            'phone_number'=>'max:20',
            'prev_balance'=>'max:999999|numeric',
            'payment'=>'max:999999|numeric|nullable'
        ]);

             //Handle file uploads
        if($request->hasFile('avatar')){
            //Get file name with the extension
            $fileNameWithExt = $request->file('avatar')->getClientOriginalName();
            //Get just filename
            $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
            //Get just extension
            $extension = $request->file('avatar')->getClientOriginalExtension();
            //Filename to store
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            //Upload image
            $path = $request->file('avatar')->storeAs('public/avatar',$fileNameToStore);
            } else {
            $fileNameToStore = 'noimage.jpg';
            }
            //dd($request->all());
            $customer = new Customers;
            
            $customer->name = $request->name;
            $customer->email = $request->email;
            $customer->phone_number = $request->phone_number;
            $customer->avatar = $fileNameToStore;
            $customer->address = $request->address;
            $customer->city = $request->city;
            $customer->state = $request->state;
            $customer->zip = $request->zip;
            $customer->company_name = $request->company_name;
            $customer->account = $request->account;
            $customer->prev_balance = $request->prev_balance;
            $customer->payment = $request->payment;
            
            if($customer->save()){

                notify()->success("Customer Added!","Success");

            }else{
                notify()->error("There was a problem creating customer!","Error");
            }

            return redirect()->back();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $customer = Customers::find($id);
        return view('customers.show')->with('customer',$customer);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $customer = Customers::findorfail($id);
        return view('customers.edit')->with('customer',$customer);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request,[

            'name'=>'max:185',
            'email'=>'max:100',
            'address'=>'max:185',
            'city'=>'max:185',
            'state'=>'max:185',
            'company_name'=>'max:50',
            'account'=>'max:50',
            'zip'=>'max:10',
            'phone_number'=>'max:20',
            'prev_balance'=>'max:999999|numeric',
            'payment'=>'max:999999|numeric|nullable'
        ]);

        if($request->hasFile('avatar')){
            //Get file name with the extension
            $fileNameWithExt = $request->file('avatar')->getClientOriginalName();
            //Get just filename
            $filename = pathinfo($fileNameWithExt,PATHINFO_FILENAME);
            //Get just extension
            $extension = $request->file('avatar')->getClientOriginalExtension();
            //Filename to store
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            //Upload image
            $path = $request->file('avatar')->storeAs('public/avatar',$fileNameToStore);
            } 

            //dd($request->all());
           // dd("am here");
            $customer = Customers::find($id);
            $customer->name = $request->name;
            $customer->email = $request->email;
            $customer->phone_number = $request->phone_number;
            $customer->address = $request->address;
            $customer->city = $request->city;
            $customer->state = $request->state;
            $customer->zip = $request->zip;
            $customer->company_name = $request->company_name;
            $customer->account = $request->account;
            $customer->prev_balance = $request->prev_balance;
            $customer->payment = $request->payment;
            
            if($request->hasFile('avatar')){
                $customer->avatar = $fileNameToStore;
            }

            if($customer->save()){
                
                notify()->success("Customer Updated!","Success");

            }else{
                notify()->error("There was a problem creating your profile!","Error");
               }

               return redirect()->route('customers.index');
            
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $customer = Customers::findorfail($id);

        $customer->delete();
        
        notify()->success("Customer Deleted!","Success");

        return redirect()->back();
    }
}
<file_sep>/app/Http/Controllers/SaleReportController.php
<?php

namespace App\Http\Controllers;

use App\Sale;
use Illuminate\Http\Request;

class SaleReportController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $salesReport = Sale::orderBy('id','desc')->paginate('10');
       //    dd($salesReport);

        return view('report.sale')->with('saleReport', $salesReport);
    }

    public function getSales(Request $request)
    {
        if ($request->ajax()) {
            $saleReport = Sale::whereBetween('created_at', [ $request->DateCreated.' 00:00:00', $request->EndDate.' 23:59:59'])->get();
            return view('report.listssale')->with('saleReport', $saleReport);
        }
    }

    public function Sale_PDF()
    {
        $sales_pdf = Sale::orderBy('id','desc')->get();
      
        $filename = 'sales_report.pdf';
        $mpdf = new \Mpdf\Mpdf([
            'margin-left' => 10,
            'margin-left' => 10,
            'margin-left' => 15,
            'margin-left' => 20,
            'margin-left' => 10,
            'margin-left' => 10
        ]);

        $html = \View::make('sales.salesreportPDF')->with('sales_pdf',$sales_pdf);
        $html = $html->render();

        $mpdf->setHeader('xxxx|Sales-Report|{PAGENO}');
        $mpdf->setFooter('Copyright StockBase Inc');
        $stylesheet = file_get_contents(url('css/customer_pdf.css'));
        $mpdf->WriteHTML($stylesheet,1);
        $mpdf->WriteHTML($html);
        $mpdf->Output($filename,'I');
        
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
