In part 2, we only edit the file index.php (pos/application/main/index.php), header.php (pos/application/layout/header.php) and pos.php (pos/application/model/pos.php)
Table of Contents
Tutorial PHP Point Of Sale System Part 2
I have discussed “how to create a dynamic menu on adminLTE” on some of my previous articles:
- Tutorial Create Dynamic Sidebar Menu on MySQL, Node.js, Express, AdminLTE For Beginner.
- Create Dynamic Sidebar Multilevel Menu in AdminLTE with MySQL, PHP, and PDO.
- How To Create User Permissions View To Dynamic Sidebar Menu AdminLTE.
- Creating dynamic sidebar menu with Mysql and AdminLTE Bootstrap Template.
I will not discuss in detail how to create this menu, but you can read some of my articles above to understand more. The primary purpose of this article is to create a PHP point of sale system that is safe and has a dynamic menu (to manage the menu navigation flexibly and efficiently).
To start making this menu, make sure you have created the m_user table in tutorial part 1. Then create 2 more tables with the name r_menu and r_sub_menu as follows.
In addition to the 2 tables above, please create a r_ref_system table to accommodate the main data of the application. r_ref_system table structure like the following picture:
Until this step, we have succeeded to create 4 tables in the pos database.
Add some of the following MySQL queries to fill the table r_menu and r_submenu :
1 2 3 4 5 6 7 | insert into 'r_menu'('id_menu','name_menu','menu_order','icon') values (1,'Master',1,''); insert into 'r_menu'('id_menu','name_menu','menu_order','icon') values (2,'Penjualan',2,''); insert into 'r_menu'('id_menu','name_menu','menu_order','icon') values (3,'Utility',7,''); insert into 'r_menu_sub'('id_sub_menu','name_sub_menu','id_menu','sub_menu_order','hak_akses','url','content_before','content_after','icon','title','target') values (1,'Master Item',1,2,'2','application/master/v_item.php',NULL,NULL,'<i class=\"fa fa-arrow-right\"></i>','MASTER ITEMS','_self'); insert into 'r_menu_sub'('id_sub_menu','name_sub_menu','id_menu','sub_menu_order','hak_akses','url','content_before','content_after','icon','title','target') values (2,'Point Of Sale',2,2,'2','application/sales/v_pos.php',NULL,NULL,'<i class=\"fa fa-arrow-right\"></i>','POINT OF SALES','_self'); insert into 'r_menu_sub'('id_sub_menu','name_sub_menu','id_menu','sub_menu_order','hak_akses','url','content_before','content_after','icon','title','target') values (3,'Master User',3,1,'4','application/utility/v_mstuser.php',NULL,NULL,'<i class=\"fa fa-arrow-right\"></i>','MASTER USERS','_self'); |
Execute the MySQL query below to fill the table r_ref_system
1 | insert into 'r_ref_system'('id','name_shop','address_shop','phone_shop') values (1,'SEEGATESITE SHOP','1193 Hartway Street Rapid City, SD 57702','08777-8370-888'); |
Edit the header.php file (pos/application/layout/header.php) and fill in the following 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 | </head> <body class="hold-transition skin-black layout-top-nav"> <!-- Site wrapper --> <div class="wrapper"> <header class="main-header"> <nav class="navbar navbar-static-top"> <div class="container-fluid"> <div class="navbar-header"> <a href="<?php echo $sitename.'application/main/index.php';?>" class="navbar-brand"> <span class="logo-mini"> <b>Seegate</b>site </span> </a> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse"> <i class="fa fa-bars"></i> </button> </div> <!-- main navigation bar disini --> <div class="collapse navbar-collapse pull-left" id="navbar-collapse"> <ul class="nav navbar-nav"> <?php $sv = new pos(); $data = $sv->getMenu(); $key = $data[1]; ?> <?php foreach($key as $menu) { $idmenux=$menu['id_menu']; $id_menu=$menu['id_menu']; $query_sub_menu = $sv->getSubMenu($id_menu); $jumlah_submenu = count($query_sub_menu[1]); if($jumlah_submenu > 0){ $cekmenuz=0; /*--------------------*/ foreach($query_sub_menu[1] as $sub_menu) { $mymenu=$_SESSION['pos_h_menu']; $arramymenu=explode(",", $mymenu); if(in_array($sub_menu['id_sub_menu'], $arramymenu)) { $cekmenuz++; } } /*--------------------*/ } if($cekmenuz >0) { ?> <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo $menu['name_menu']; ?> <span class="caret"></span></a> <?php } if($jumlah_submenu > 0){ ?> <ul class="dropdown-menu" role="menu"> <?php foreach($query_sub_menu[1] as $sub_menu) { $mymenu=$_SESSION['pos_h_menu']; $arramymenu=explode(",", $mymenu); if(in_array($sub_menu['id_sub_menu'], $arramymenu)) { echo $sub_menu['content_before'] ; ?> <li> <a class="titles" href="<?php echo $sitename.$sub_menu['url']; ?>" target="<?php echo $sub_menu['target']; ?>" title="<?php echo $sub_menu['title']; ?>" > <?php echo $sub_menu['icon'].$sub_menu['name_sub_menu']; ?> </a> </li> <?php echo $sub_menu['content_after'] ; } } ?> </ul> <?php } ?> </li> <?php } ?> </ul> </div> <!-- /.navbar-collapse --> <!-- ./ main navigation bar --> <div class="navbar-custom-menu"> <ul class="nav navbar-nav"> <li class="dropdown user user-menu"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <img src="../../dist/img/avatar5.png" class="user-image" alt="User Image"> <span class="hidden-xs"><?php echo $_SESSION['pos_username']; ?></span> </a> <ul class="dropdown-menu"> <!-- User image --> <li class="user-header"> <img src="../../dist/img/avatar5.png" class="img-circle" alt="User Image"> <p> <?php echo $_SESSION['pos_username']; ?> </p> </li> <!-- Menu Footer--> <li class="user-footer"> <div class="pull-left"> <a href="<?php echo $sitename.'application/utility/v_ubah_password.php'; ?>" title="Change Password " class="btn btn-default btn-flat">Change Password</a> </div> <div class="pull-right"> <a href="<?php echo $sitename.'application/main/logout.php'; ?>" title="Close Application" class="btn btn-default btn-flat">Logout</a> </div> </li> </ul> </li> <li> <a class="titles" href="<?php echo $sitename.'application/main/logout.php'; ?>" ><i class="titles fa fa-sign-out" title="Close Application" ></i></a> </li> </ul> </div><!-- /.<div class="navbar-custom-menu">--> </div><!-- ./container --> </nav> </header> <!-- main content --> <div class="content-wrapper"> <div class="container-fluid"> |
Brief Description :
The PHP navigation menu code is placed here. We store user menu permissions in the h_menu field in a string format delimited by commas. For example, “1,2,3.”
Then in the header.php file, we break up the h_menu into an array. The next step is to check the submenu code in the array. If the submenu code is in an array formed from h_menu, then the submenu will be displayed
Create Dashboard in PHP
Edit the index.php file (pos/application/main/index.php) and fill in the following 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 | <?php include "../../library/config.php"; ?> <?php $titlepage="Dashboard"; ?> <?php require_ once("../model/dbconn.php"); require_ once("../model/pos.php"); include "../layout /top-header.php"; include "../../library /check_login.php"; include "../layout/header.php"; ?> <section style="margin-bottom:10px;" class="content-header"> <h1> Dashboard <small>Page</small> </h1> </section> <section class="content-main"> <div class="row"> <div class="col-xs-12"> <div class="box box-solid box-danger"> <?php $pos = new pos(); $toko = $pos->getrefsytem(); $nameshop = $toko[1]['name_shop']; $address_shop = $toko[1]['address_shop']; $phoneshop = $toko[1]['phone_shop']; ?> <div class="box-header"> <h1 class="box-title"><?php echo $nameshop;?></h1> </div> <!-- end of box-header --> <div class="box-body"> <h4><?php echo $address_shop;?></h4> <h5>Telp : <?php echo $phoneshop;?></h5> </div> <!-- end of box-body --> </div><!-- end of box box-solid bg-light-blue-gradiaent --> </div> </div><!-- row --> <div class="row"> <div class="col-md-9"> <div class="box box-info"> <div class="box box-info"> <div class="box-header"> <h3 class="box-title">Search Item</h3> </div> <!-- end of box-header --> <div class="row"> <div class=" col-xs-12" style="padding-left:25px;padding-right:25px"> <input type="text" class="form-control " id="txtsearchitem" placeholder="Search item or item id here..."> </div> </div> <div class="box-body"> <div class="box-body table-responsive no-padding" style="max-width:900px;"> <table id="table_search" class="table table-bordered table-hover table-striped"> <thead> <tr class="tableheader"> <th style="width:40px">#</th> <th style="width:60px">Id</th> <th style="width:300px">Items</th> <th style="width:100px">Price</th> <th style="width:120px">Stock</th> </tr> </thead> <tbody></tbody> </table> </div> </div> <!-- end of box-body --> </div> </div><!-- end of div box info --> </div><!-- end of col-md-8 --> <div class="col-md-3"> <div class="small-box bg-green"> <div class="inner"> <h3>30</h3> <p>Today Sales</p> </div> <div class="icon"> <i class="ion ion-stats-bars"></i> </div> <a href="#" id="lapjuals" class="small-box-footer"> More Detail <i class="fa fa-arrow-circle-right"></i></a> </div><!-- end of small-box-green --> <div class="small-box bg-aqua"> <div class="inner"> <h3>10</h3> <p>Out of stock items</p> </div> <div class="icon"> <i class="ion ion-bag"></i> </div> <a href="<?php echo $sitename;?>application/mutasi/l_barang_abis.php" target="_blank" class="small-box-footer">Info detail <i class="fa fa-arrow-circle-right"></i></a> </div><!-- end of col md 4 --> </div><!-- end of row --> </section> <?php include "../layout/footer.php"; //footer template ?> <?php include "../layout/bottom-footer.php"; //footer template ?> <script src="../../dist/js/redirect.js"></script> <script> $(document).on("keyup keydown","#txtsearchitem",function(){ var searchitem = $("#txtsearchitem").val(); value={ term : searchitem, } $.ajax( { url : "../master/c_search_item.php", type: "POST", data : value, success: function(data, textStatus, jqXHR) { var data = jQuery.parseJSON(data); $("#table_search tbody").html(data.data) }, error: function(jqXHR, textStatus, errorThrown) { } }); }); </script> </body> </html> |
Edit the pos.php file (pos/application/model/pos.php) and add the following 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 | /****************************************************************************** START OF pos MENU CODE *******************************************************************************/ public function getMenu() { $db = $this->dblocal; try { $stmt = $db->prepare("select * from r_menu order by menu_order"); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getSubMenu($id) { $db = $this->dblocal; try { $stmt = $db->prepare("select * from r_menu_sub where id_menu = :id order by sub_menu_order asc"); $stmt->bindParam("id",$id); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetchAll(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); return $stat; } } public function getrefsytem() { $db = $this->dblocal; try { $stmt = $db->prepare("select a.* from r_ref_system a where id = 1 "); $stmt->execute(); $stat[0] = true; $stat[1] = $stmt->fetch(PDO::FETCH_ASSOC); return $stat; } catch(PDOException $ex) { $stat[0] = false; $stat[1] = $ex->getMessage(); $stat[2] = 0; return $stat; } } |
Brief Description :
On the dashboard page, we create a table for item search. But the item search module does not work in this chapter, we will discuss it in the next tutorial.
To tests the dynamic menu please add the value in a h_menu field in the m_user table. Change the menu to 1,2 or 1,3 and see the result.
you can download the entire php point of sale project in the tutorial part 5 here.
Conclusion
Creating a dynamic navigation menu and Adminlte dashboard does not require a long time. Adminlte is a free dashboard framework that is easily customized according to the goals to be achieved.
List of PHP point of sale tutorials:
- Create login page – Tutorial Build PHP Point Of Sale Part 1.
- Create Dynamic Menu and Dashboard Page -PHP Point Of Sale Tutorial Part 2.
- Create Master User Form – PHP Point Of Sale Tutorial Part 3
- Create Master Item / Product Form – PHP Point Of Sale Tutorial Part 4
- Create Sales Form / Point of sale – PHP Point Of Sale Tutorial Part 5
I think the 2nd part tutorial is pretty easy, so I don’t need to explain in detail. Up here Tutorial Build PHP Point Of Sale With, PDO, MySQL And Jquery Part 2 has been completed, In the next article will discuss how to create master user page in PHP point of sale tutorial.
Kenapa muncul Fatal error : break not in the loop or switch context in ….. di file authorization.php
kode break; cuman bisa di gunakan di loop atau switch. mungkin php versinya yak yang mempengaruhi 🙂
I am getting this error whenever I try to run the pos.php code,
“Parse error: syntax error, unexpected ‘public’ (T_PUBLIC), expecting end of file in C:\xampp\htdocs\pos\application\model\pos.php on line 5”.
create new class pos… please read first article before
https://seegatesite.com/tutorial-build-point-of-sale-with-php-pdo-mysql-and-jquery-part-1/