[Free Download] Grocery Store Management System in PHP SQLite
I developed this project using the following:
- PHP Language
- SQLite Database
- HTML
- JavaScrip
- XAMPP v3.3.0
- jQuery
- Ajax
- CSS
- Bootstrap
This Final year project has two modules;
- Administrator Usermodul
- Client module
The Administrator User Module is the system side where the Grocery’s store Add, delete, view, update, and the searching system can add, delete, view, update and search all their items, stocks, and Clients’ orders.
The Client Module is the side where Clients/visitors can browse, explore, add to cart, and place order their desired items.
When the Client checkouts, the system will be adding a delivery fee on the total amount of Clients to pay upon delivery of the items.
Grocery’s store Add, delete, view, update, and searching system also generates a simple and printable sales report.
Functional Requirements of Grocery Store Management System
Administrator User Side
- Admin can Secure Login/Logout
- Admin can Add, delete, view, update and search Category List
- Admin can Add, delete, view, update and search Delivery Charges/Fee per Location
- Admin can Add, delete, view, update and search Product List
- Admin can Add, delete, view, update and search Order List
- Admin can Add, delete, view, update and search Client List
- Admin can Generate Printable Sales Report
- Admin can Add, delete, view, update and search System Users List
- Admin can Add, delete, view, update and search Account Credentials
- Admin can Logout
Client-Side
- Client can Secure Login and Registration
- Client can Explore Items
- Client can Search Items
- Client can Filter Product by Categories
- Client can Add Product to Shopping Cart
- Client can Checkout
- Client can List all Orders
- Client can View Order Details
- Client can Add, delete, view, update and search Account Credentials
- Client can Logout
How to Run this FYP
- Download and Install XAMPP/WAMP.
- Download the provided source code zip file.
Default Administrator User Access
Username:Â Administrator User
Password:Â Administrator User123
view_product.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
<?php session_start(); require_once("DBConnection.php"); if(isset($_GET['id'])){ $qry = $conn->query("SELECT * FROM `product_list` where product_id = '{$_GET['id']}'"); foreach($qry->fetchArray() as $k => $v){ $$k = $v; } $in = $conn->query("SELECT SUM(quantity) as `in` from inventory_list where product_id = '{$product_id}' and `type` = 1")->fetchArray()['in']; $out = $conn->query("SELECT SUM(quantity) as `out` from inventory_list where product_id = '{$product_id}' and `type` = 2")->fetchArray()['out']; $available = $in - $out; } $thumbnail = 'uploads/thumbnails/'.$product_id.'.png'; $scan = scandir('uploads/images/'.$product_id.'/'); unset($scan[0]); unset($scan[1]); ?> <style> #uni_modal .modal-footer{ display:none; } </style> <div class="container-fluid" id="product-details"> <div class="col-12"> <div class="row"> <div class="col-lg-6"> <div class="row"> <div class="col-12"> <img src="<?php echo $thumbnail ?>" id="selected-image" alt="Img" class="display-image image-fluid border-dark border"> </div> </div> <div class="d-flex flex-nowrap w-100 overflow-auto my-2"> <div class="col-auto m-1"> <a href="javascript:void(0)" class="select-img border border-dark d-block"> <img src="<?php echo $thumbnail ?>" alt="Img" class="display-select-image img-fluid" /> </a> </div> <?php foreach($scan as $img): ?> <div class="col-auto m-1 img-item"> <a href="javascript:void(0)" class="select-img border border-dark d-block"> <img src="<?php echo 'uploads/images/'.$product_id.'/'.$img ?>" alt="Img" class="display-select-image img-fluid" /> </a> </div> <?php endforeach; ?> </div> </div> <div class="col-lg-6"> <div class="fs-4 pb-3"><?php echo $name ?></div> <hr> <div>Price: <?php echo number_format($price,2) ?> <i class="fa fa-tag text-success"></i></div> <div>Available: <?php echo number_format($available) ?></div> <p class="py-3"><?php echo str_replace("\n\r","<br/>",$description) ?></p> </div> </div> </div> <div class="col-12"> <div class="row justify-content-end"> <?php if(!isset($_GET['order_id'])): ?> <div class="col-auto mx-1"> <div class="btn btn btn-primary btn-sm rounded-0" id="add_to_cart" type="button">Add to Cart</div> </div> <?php endif; ?> <div class="col-1"> <div class="btn btn btn-dark btn-sm rounded-0" type="button" data-bs-dismiss="modal">Close</div> </div> </div> </div> </div> <script> $(function(){ $('.select-img').click(function(){ var imgPath = $(this).find('img').attr('src') $('#selected-image').attr('src',imgPath) }) if('<?php echo isset($_GET['order_id']) ?>' == 1){ $('#uni_modal').on('hidden.bs.modal',function(){ if($('#uni_modal #product-details').length > 0) uni_modal('Order Details',"view_order.php?id=<?php echo isset($_GET['order_id'])? $_GET['order_id'] : '' ?>",'large') }) } $('#add_to_cart').click(function(){ $('#uni_modal button').attr('disabled',true) if('<?php echo isset($_SESSION['customer_id']) && $_SESSION['customer_id'] > 0 ?>' == 1){ $.ajax({ url:"Actions.php?a=add_to_cart", method:"POST", data:{product_id:'<?php echo $product_id ?>',quantity:1}, dataType:'JSON', error:err=>{ alert("An error occurred") $('#uni_modal button').attr('disabled',false) }, success:function(resp){ if(resp.status == "success"){ $('#cart_count').text(resp.cart_count) alert("Product Added to cart"); }else{ alert("An error occurred") } $('#uni_modal button').attr('disabled',false) } }) }else{ uni_modal('Please Enter your Login Credentials',"login.php") } }) }) </script> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
<?php require_once('./DBConnection.php'); $sql = "SELECT o.*,c.fullname,f.location, f.amount FROM `order_list` o inner join `customer_list` c on o.customer_id = c.customer_id inner join fees_list f on o.fee_id = f.fee_id where `order_id` = '{$_GET['id']}'"; $qry = $conn->query($sql); foreach($qry->fetchArray() as $k => $v){ $$k = $v; } ?> <style> #uni_modal .modal-footer{ display:none; } </style> <div class="container-fluid"> <div class="col-12"> <div class="row"> <div class="col-md-6"> <div class="mb-2 d-flex"> <label for="" class="col-auto pe-1">Transaction Code: </label> <div class="col-auto flex-grow-1"><?php echo $transaction_code ?></div> </div> <div class="mb-2 d-flex"> <label for="" class="col-auto pe-1">Status: </label> <div class="col-auto flex-grow-1"> <span id="status"> <?php if($status == 1): ?> <span class="badge bg-primary"><small>Confirmed</small></span> <?php elseif($status == 2): ?> <span class="badge bg-success"><small>Delivered</small></span> <?php elseif($status == 3): ?> <span class="badge bg-danger"><small>Cancelled</small></span> <?php else: ?> <span class="badge bg-dark text-light"><small>Pending</small></span> <?php endif; ?> </span> </div> </div> </div> <div class="col-md-6"> <div class="mb-2 d-flex"> <label for="" class="col-auto pe-1">Date Created: </label> <div class="col-auto flex-grow-1"><?php echo date("Y-m-d h:i A",strtotime($date_created)) ?></div> </div> <div class="mb-2 d-flex"> <label for="" class="col-auto pe-1">Delivery Address: </label> <div class="col-auto flex-grow-1"><?php echo $delivery_address.', ',$location ?></div> </div> </div> </div> <div class="row"> <div class="col-md-12"> <table class="table table-bordered table-hover"> <colgroup> <col width="10%"> <col width="75%"> <col width="15%"> </colgroup> <thead> <tr> <th class="py-0 px-1 text-center">QTY</th> <th class="py-0 px-1 text-center">Item Details</th> <th class="py-0 px-1 text-center">Amount</th> </tr> </thead> <tbody> <?php $qry = $conn->query("SELECT o.*,p.name as pname, p.description,p.price,cc.name as cname FROM `order_items` o inner join `product_list` p on o.product_id = p.product_id inner join `category_list` cc on p.category_id = cc.category_id where o.`order_id` = '{$order_id}'"); $total = 0; while($row=$qry->fetchArray()): $total += $row['quantity'] * $row['price']; ?> <tr> <td class="px-1 py-0 text-center"><?php echo number_format($row['quantity']) ?></td> <td> <div class="w-100 d-flex"> <div class="col-auto me-2"> <img src="<?php echo './uploads/thumbnails/'.$row['product_id'].'.png' ?>" alt="" class="img-fluid border border-dark" height="75px" width="75px"> </div> <div class="col-auto flex-grow-1"> <div><a class="fs-5 text-decoration-none view_product" href="javascript:void(0)" data-id="<?php echo $row['product_id'] ?>"><b><?php echo $row['pname'] ?></b></a> </div> <small><i><?php echo $row['cname'] ?></i></small> <div class="w-100"> Price: <b><i> X <?php echo number_format($row['price'],2) ?></i></b> </div> </div> </div> </td> <td class="text-end align-middle"> <span class="fs-5"><b class="price_display"><?php echo number_format($row['quantity'] * $row['price'],2) ?></b></span> </td> <?php endwhile; ?> </tr> </tbody> <tfoot> <tr> <th colspan='2' class="text-end">Sub Total</th> <th class="text-end fs-5" id="gTotal"><?php echo number_format($total,2) ?></th> </tr> <tr> <th colspan='2' class="text-end">Delivery Fee</th> <th class="text-end fs-5" id="gTotal"><?php echo number_format($amount,2) ?></th> </tr> <tr> <th colspan='2' class="text-end">Total <input type="hidden" name="total" value="<?php echo $total + $row['amount'] ?>"></th> <th class="text-end fs-5" id="gTotal"><?php echo number_format($total + $amount,2) ?></th> </tr> </tfoot> </table> </div> </div> </div> <div class="col-12"> <div class="row justify-content-end"> <div class="col-1"> <div class="btn btn btn-dark btn-sm rounded-0" type="button" data-bs-dismiss="modal">Close</div> </div> </div> </div> </div> <script> $(function(){ $('.view_product').click(function(){ uni_modal('Product Detailes',"view_product.php?order_id=<?php echo $order_id ?>&id="+$(this).attr('data-id'),"mid-large") }) }) </script> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
<style> #uni_modal .modal-footer{ display:none; } </style> <?php session_start(); require_once("DBConnection.php"); ?> <div class="container-fluid"> <div class="row"> <div class="col-md-6"> <form action="" id="place-order"> <input type="hidden" name="total_amount" value="<?php echo $_GET['total'] ?>"> <div class="form-group"> <label for="fee_id" class="control-label">Delivery Location</label> <select name="fee_id" id="fee_id" class="form-select form-select-sm select2" required> <option value="" disabled <?php echo !isset($fee_id) ? "selected" : '' ?>></option> <?php $fees = $conn->query("SELECT * FROM `fees_list` where status = 1 ".(isset($fee_id) ? " OR fee_id = '{$fee_id}'" : '')." order by `location` asc "); while($row = $fees->fetchArray()): ?> <option value="<?php echo $row['fee_id'] ?>" data-amount = "<?php echo $row['amount'] ?>" <?php echo isset($fee_id) && $fee_id == $row['fee_id'] ? "selected" : "" ?>><?php echo $row['location'] ?></option> <?php endwhile; ?> </select> </div> <div class="form-group"> <label for="" class="control-label">Delivery Address Other Information</label> <textarea name="delivery_address" id="delivery_address" cols="30" rows="3" class="form-control rounded-0" placeholder="ie. Lot 23 Block 6, There Ville"></textarea> </div> </form> </div> <div class="col-md-6"> <table class="table table-striped"> <tbody> <tr> <th>Sub-Total</th> <th class="text-end" id="csub-total"><?php echo $_GET['total'] ?></th> </tr> <tr> <th>Delivery Fee</th> <th class="text-end" id="cfee">0</th> </tr> <tr> <th>Total</th> <th class="text-end" id="ctotal"><?php echo $_GET['total'] ?></th> </tr> </tbody> </table> </div> <div class="col-12 mt-3 text-center "> <button class="btn btn-sm btn-primary rounded-0 my-1" form="place-order">Place Order</button> <button class="btn btn-sm btn-dark rounded-0" type="button" data-bs-dismiss="modal">Cancel</button> </div> </div> </div> <script> $(function(){ $('#fee_id').change(function(){ var fee_id = $(this).val() var amount = $('#fee_id option[value="'+fee_id+'"]').attr('data-amount') var sub = $('#csub-total').text().replace(/\,/gi,'') var total = parseFloat(sub) + parseFloat(amount); $('#cfee').text(parseFloat(amount).toLocaleString('en-US')) $('#ctotal').text(parseFloat(total).toLocaleString('en-US')) }) $('#place-order').submit(function(e){ e.preventDefault(); if($('#fee_id').val() <= 0){ alert("Please select location address first."); $('#fee_id').focus() return false; } $('.pop_msg').remove() var _this = $(this) var _el = $('<div>') _el.addClass('pop_msg') _this.find('button').attr('disabled',true) $.ajax({ url:'Actions.php?a=place_order', method:'POST', data:$(this).serialize(), dataType:'JSON', error:err=>{ console.log(err) _el.addClass('alert alert-danger') _el.text("An error occurred.") _this.prepend(_el) _el.show('slow') _this.find('button').attr('disabled',false) _this.find('button[type="submit"]').text('Save') }, success:function(resp){ if(resp.status == 'success'){ location.replace("./") }else{ _el.addClass('alert alert-danger') } _el.text(resp.msg) _el.hide() _this.prepend(_el) _el.show('slow') _this.find('button').attr('disabled',false) _this.find('button[type="submit"]').text('Save') } }) }) }) </script> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
<h3>Cart</h3> <hr> <div class="col-lg-12"> <div class="w-100"> <div class="card"> <div class="card-body"> <table class="table table-bordered table-hover table-stripped"> <colgroup> <col width="5%"> <col width="75%"> <col width="20%"> </colgroup> <thead> <tr> <th></th> <th>Item Details</th> <th>Amount</th> </tr> </thead> <tbody> <?php $qry = $conn->query("SELECT c.*,p.name as pname, p.description,p.price,cc.name as cname FROM `cart_list` c inner join `product_list` p on c.product_id = p.product_id inner join `category_list` cc on p.category_id = cc.category_id where c.`customer_id` = '{$_SESSION['customer_id']}'"); $total = 0; while($row=$qry->fetchArray()): $total += $row['quantity'] * $row['price']; ?> <tr class="item" data-id="<?php echo $row['product_id'] ?>"> <td class="text-center align-middle"> <button class="btn btn-sm btn-danger rounded-0 del_item" button="button" data-id="<?php echo $row['product_id'] ?>"><span class="fa fa-trash"></span></button> </td> <td> <div class="w-100 d-flex"> <div class="col-auto me-2"> <img src="<?php echo './uploads/thumbnails/'.$row['product_id'].'.png' ?>" alt="" class="img-fluid border border-dark" height="75px" width="75px"> </div> <div class="col-auto flex-grow-1"> <div class="fs-5"><b><?php echo $row['pname'] ?></b></div> <small><i><?php echo $row['cname'] ?></i></small> <div class="d-flex w-100"> <div class="col-auto"> <input type="number" value="<?php echo number_format($row['quantity'],0,'.','') ?>" class="form-control form-control-sm rounded-0 py-0 qty text-center col-1" style="width:100px" required> <input type="hidden" value="<?php echo $row['price'] ?>" class="price"> <input type="hidden" value="<?php echo $row['product_id'] ?>" class="product_id"> </div> <div class="col-auto ms-1"> <b><i> X <?php echo number_format($row['price'],2) ?></i></b> </div> </div> </div> </div> </td> <td class="text-end align-middle"> <span class="fs-5"><b class="price_display"><?php echo number_format($row['quantity'] * $row['price'],2) ?></b></span> </td> </tr> <?php endwhile; ?> <?php if(!$qry->fetchArray()): ?> <tr> <th class="text-center" colspan='3'>Cart is empty. <a href="./">Explore Products</a></th> </tr> <?php endif; ?> </tbody> <tfoot> <tr> <th colspan='2' class="text-center">Total <input type="hidden" name="total" value="<?php echo $total ?>"></th> <th class="text-end fs-5" id="gTotal"><?php echo number_format($total,2) ?></th> </tr> </tfoot> </table> <center><button class="btn btn-dark btn-sm rounded-0" style="display:none" type="button" id="checkout">Checkout</button></center> </div> </div> </div> </div> <script> $(function(){ if($('.item').length < 0){ $('#checkout').hide(); }else{ $('#checkout').show(); } $('#checkout').click(function(){ uni_modal("Checkout","place_order.php?total="+$('[name="total"]').val(),'mid-large') }) $('.qty').change(function(){ var _qty = $(this).val() var _this = $(this) $(this).removeClass('boreder-danger') if($.isNumeric(_qty) === false){ $(this).addClass('boreder-danger') }else{ var _price = $(this).siblings('.price').val() var product_id = $(this).siblings('.product_id').val() console.log(product_id) var total = parseFloat(_price) * parseFloat(_qty) $(this).closest('tr').find('.price_display').text(parseFloat(total).toLocaleString('en-US',{ style:'decimal',minimumFractionDigits:2,maximumFractionDigits:2})) $.ajax({ url:"Actions.php?a=update_cart", method:"POST", data:{customer_id:"<?php echo $_SESSION['customer_id'] ?>",product_id:product_id,quantity:_qty}, dataType:'JSON', error:err=>{ console.log(err) alert("An error occured") }, success:function(resp){ if(resp.status == 'success'){ $('#cart_count').text(resp.cart_count) calc() }else if(!!resp.msg && !!resp.available){ alert(resp.msg) _this.val(resp.available).trigger('change') }else{ alert("An error occured") } } }) } }) $('.del_item').click(function(){ _conf("Are you sure to remove this Item from cart list?",'delete_data',[$(this).attr('data-id')]) }) }) function calc(){ var total = 0; $('.price_display').each(function(){ var _price = $(this).text().replace(/,/gi,'') total += parseFloat(_price) }) $('#gTotal').text(parseFloat(total).toLocaleString('en-US',{ style:'decimal',minimumFractionDigits:2,maximumFractionDigits:2})) } function delete_data($id){ $('#confirm_modal button').attr('disabled',true) $.ajax({ url:'Actions.php?a=delete_from_cart', method:'POST', data:{id:$id}, dataType:'JSON', error:err=>{ console.log(err) alert("An error occurred.") $('#confirm_modal button').attr('disabled',false) }, success:function(resp){ if(resp.status == 'success'){ $('#cart_count').text(resp.cart_count) calc() $('table tr.item[data-id="'+$id+'"]').remove() location.reload() }else{ alert("An error occurred.") $('#confirm_modal button').attr('disabled',false) } } }) } </script> |