D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
kk.encodersunlimited.com
/
Filename :
calculate.php
back
Copy
<?php require('config.php'); // Database connection // Fetch categories with status function fetchCategories($conn) { $sql = "SELECT id, category_name, status FROM category"; // Include status $result = $conn->query($sql); $categories = []; while ($row = $result->fetch_assoc()) { $categories[] = $row; } return $categories; } // Fetch products function fetchProducts($conn) { $sql = "SELECT id, name, category FROM products"; // Adjust SQL query as needed $result = $conn->query($sql); $products = []; while ($row = $result->fetch_assoc()) { $products[] = $row; } return $products; } $categories = fetchCategories($conn); $products = fetchProducts($conn); if ($_SERVER["REQUEST_METHOD"] == "POST") { // Check if required form values are set $productId = isset($_POST['product_select']) ? $_POST['product_select'] : null; $categoryId = isset($_POST['category_select']) ? $_POST['category_select'] : null; $goldWeight = isset($_POST['gold_quantity']) ? floatval($_POST['gold_quantity']) : null; $goldPrice = isset($_POST['gold_price']) ? floatval($_POST['gold_price']) : null; $diamondWeight = isset($_POST['diamond_quantity']) ? floatval($_POST['diamond_quantity']) : 0; $diamondPrice = isset($_POST['diamond_price']) ? floatval($_POST['diamond_price']) : 0; $makingCharge = isset($_POST['additional_charge']) ? floatval($_POST['additional_charge']) : null; $profitPercentage = isset($_POST['profit_percentage']) ? floatval($_POST['profit_percentage']) : null; $gstPercentage = isset($_POST['gst_percentage']) ? floatval($_POST['gst_percentage']) : null; // New customer details fields $customerName = isset($_POST['customer_name']) ? $_POST['customer_name'] : null; $customerNumber = isset($_POST['customer_number']) ? $_POST['customer_number'] : null; $customerEmail = isset($_POST['customer_email']) ? $_POST['customer_email'] : null; $customerAddress = isset($_POST['customer_address']) ? $_POST['customer_address'] : null; // Validate form inputs if ($productId && $categoryId && $goldWeight !== null && $goldPrice !== null && $makingCharge !== null && $profitPercentage !== null && $gstPercentage !== null) { // Calculate total price $goldTotal = $goldWeight * $goldPrice; $diamondTotal = $diamondWeight * $diamondPrice; $totalBeforeCharges = $goldTotal + $diamondTotal; $makingChargeAmount = ($totalBeforeCharges * $makingCharge) / 100; $profitAmount = ($totalBeforeCharges * $profitPercentage) / 100; $subtotal = $totalBeforeCharges + $makingChargeAmount + $profitAmount; $gstAmount = ($subtotal * $gstPercentage) / 100; $totalPrice = $subtotal + $gstAmount; // Insert into database $stmt = $conn->prepare("INSERT INTO `order_details` (product_id, category_id, gold_weight, gold_price, diamond_weight, diamond_price, making_charge, profit_percentage, total_cost, customer_name, customer_number, customer_email, customer_address) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param("iiddiddidssss", $productId, $categoryId, $goldWeight, $goldPrice, $diamondWeight, $diamondPrice, $makingCharge, $profitPercentage, $totalPrice, $customerName, $customerNumber, $customerEmail, $customerAddress); if ($stmt->execute()) { echo "Data successfully inserted."; } else { echo "Error: " . $stmt->error; } $stmt->close(); } else { echo "Please fill in all required fields."; } $conn->close(); } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>kk-admin</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta content="Premium Multipurpose Admin & Dashboard Template" name="description" /> <meta content="Themesbrand" name="author" /> <!-- App favicon --> <link rel="shortcut icon" href="assets/images/favicon.ico"> <!-- plugin css --> <link href="assets/libs/admin-resources/jquery.vectormap/jquery-jvectormap-1.2.2.css" rel="stylesheet" type="text/css" /> <!-- preloader css --> <link rel="stylesheet" href="assets/css/preloader.min.css" type="text/css" /> <!-- Bootstrap Css --> <link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" /> <!-- Icons Css --> <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" /> <!-- App Css--> <link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" /> </head> <body> <!-- <body data-layout="horizontal"> --> <!-- Begin page --> <div id="layout-wrapper"> <?php include('header.php') ?> <!-- ========== Left Sidebar Start ========== --> <?php include('sidebar.php') ?> <!-- Left Sidebar End --> <!-- ============================================================== --> <!-- Start main Content here --> <!-- ============================================================== --> <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-sm-flex align-items-center justify-content-between"> <h4 class="mb-sm-0 font-size-18">Add Category</h4> <div class="page-title-right"> <ol class="breadcrumb m-0"> <li class="breadcrumb-item"><a href="javascript: void(0);">Category</a></li> <li class="breadcrumb-item active">Add Category</li> </ol> </div> </div> </div> </div> <!-- end page title --> <div class="row"> <div class="col-12"> <div class="card"> <div class="card-header"> <h4 class="card-title">Add Product</h4> <p class="card-title-desc">Fill in the details below to add a new product.</p> </div> <div class="card-body p-4"> <div class="row"> <form id="priceForm" method="POST" action=""> <div class="form-row"> <!-- Column 1 --> <div class="col-md-6 mb-3"> <div class="form-group"> <label for="product_select">Select Product:</label> <select class="form-control" id="product_select" name="product_select" required> <option value="" disabled selected>Select a product</option> <?php foreach ($products as $product) { echo "<option value=\"{$product['id']}\">{$product['name']}</option>"; } ?> </select> </div> <div class="form-group"> <label for="category_select">Select Category:</label> <select class="form-control" id="category_select" name="category_select" required> <option value="" disabled selected>Select a category</option> <?php foreach ($categories as $category) { echo "<option value=\"{$category['id']}\" data-status=\"{$category['status']}\">{$category['category_name']}</option>"; } ?> </select> </div> <!-- New customer fields --> <div class="form-group"> <label for="customer_name">Customer Name:</label> <input type="text" class="form-control" id="customer_name" name="customer_name" required> </div> <div class="form-group"> <label for="customer_number">Customer Number:</label> <input type="text" class="form-control" id="customer_number" name="customer_number" required> </div> <div class="form-group"> <label for="customer_email">Customer Email:</label> <input type="email" class="form-control" id="customer_email" name="customer_email" required> </div> <div class="form-group"> <label for="customer_address">Customer Address:</label> <textarea class="form-control" id="customer_address" name="customer_address" required></textarea> </div> <!-- Gold and diamond fields --> <div class="form-group"> <label for="gold_quantity">Gold Quantity (grams):</label> <input type="number" step="0.01" class="form-control" id="gold_quantity" name="gold_quantity" required> </div> <div class="form-group"> <label for="gold_price">Gold Price per gram:</label> <input type="number" step="0.01" class="form-control" id="gold_price" name="gold_price" required> </div> <div class="form-group hidden" id="diamond_quantity_group"> <label for="diamond_quantity">Diamond Quantity (carats):</label> <input type="number" step="0.01" class="form-control" id="diamond_quantity" name="diamond_quantity"> </div> <div class="form-group hidden" id="diamond_price_group"> <label for="diamond_price">Diamond Price per carat:</label> <input type="number" step="0.01" class="form-control" id="diamond_price" name="diamond_price"> </div> </div> <!-- Column 2 --> <div class="col-md-6 mb-3"> <div class="form-group"> <label for="additional_charge">Additional Charge (%):</label> <input type="number" step="0.01" class="form-control" id="additional_charge" name="additional_charge" required> </div> <div class="form-group"> <label for="profit_percentage">Profit Percentage (%):</label> <input type="number" step="0.01" class="form-control" id="profit_percentage" name="profit_percentage" required> </div> <div class="form-group"> <label for="gst_percentage">GST Percentage (%):</label> <input type="number" step="0.01" class="form-control" id="gst_percentage" name="gst_percentage" required> </div> <div class="form-group"> <label for="total_cost">Total Cost:</label> <input type="number" step="0.01" class="form-control disabled" id="total_cost" name="total_cost" readonly> </div> <div class="btn-div d-flex p-2"> <button type="submit" class="btn btn-primary mt-4">Save Report</button> </div> </div> </div> </form> <div id="calculationResult" class="calculation-result"> <!-- Display the result of the calculation here --> </div> </div> </div> </div> </div> </div> </div> <!-- container-fluid --> </div> <!-- End Page-content --> <footer class="footer"> <div class="container-fluid"> <div class="row"> <div class="col-sm-6"> <script> document.write(new Date().getFullYear()) </script> © KK Jewellers. </div> <div class="col-sm-6"> <div class="text-sm-end d-none d-sm-block"> Design & Develop by <a href="#!" class="text-decoration-underline">Encoders Unlimited</a> </div> </div> </div> </div> </footer> </div> <!-- end main content--> </div> <!-- END layout-wrapper --> <!-- Right Sidebar --> <div class="right-bar"> <div data-simplebar class="h-100"> <div class="rightbar-title d-flex align-items-center bg-dark p-3"> <h5 class="m-0 me-2 text-white">Theme Customizer</h5> <a href="javascript:void(0);" class="right-bar-toggle ms-auto"> <i class="mdi mdi-close noti-icon"></i> </a> </div> <!-- Settings --> <hr class="m-0" /> <div class="p-4"> <h6 class="mb-3">Layout</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout" id="layout-vertical" value="vertical"> <label class="form-check-label" for="layout-vertical">Vertical</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout" id="layout-horizontal" value="horizontal"> <label class="form-check-label" for="layout-horizontal">Horizontal</label> </div> <h6 class="mt-4 mb-3 pt-2">Layout Mode</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-mode" id="layout-mode-light" value="light"> <label class="form-check-label" for="layout-mode-light">Light</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-mode" id="layout-mode-dark" value="dark"> <label class="form-check-label" for="layout-mode-dark">Dark</label> </div> <h6 class="mt-4 mb-3 pt-2">Layout Width</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-width" id="layout-width-fuild" value="fuild" onchange="document.body.setAttribute('data-layout-size', 'fluid')"> <label class="form-check-label" for="layout-width-fuild">Fluid</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-width" id="layout-width-boxed" value="boxed" onchange="document.body.setAttribute('data-layout-size', 'boxed')"> <label class="form-check-label" for="layout-width-boxed">Boxed</label> </div> <h6 class="mt-4 mb-3 pt-2">Layout Position</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-position" id="layout-position-fixed" value="fixed" onchange="document.body.setAttribute('data-layout-scrollable', 'false')"> <label class="form-check-label" for="layout-position-fixed">Fixed</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-position" id="layout-position-scrollable" value="scrollable" onchange="document.body.setAttribute('data-layout-scrollable', 'true')"> <label class="form-check-label" for="layout-position-scrollable">Scrollable</label> </div> <h6 class="mt-4 mb-3 pt-2">Topbar Color</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="topbar-color" id="topbar-color-light" value="light" onchange="document.body.setAttribute('data-topbar', 'light')"> <label class="form-check-label" for="topbar-color-light">Light</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="topbar-color" id="topbar-color-dark" value="dark" onchange="document.body.setAttribute('data-topbar', 'dark')"> <label class="form-check-label" for="topbar-color-dark">Dark</label> </div> <h6 class="mt-4 mb-3 pt-2 sidebar-setting">Sidebar Size</h6> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-size" id="sidebar-size-default" value="default" onchange="document.body.setAttribute('data-sidebar-size', 'lg')"> <label class="form-check-label" for="sidebar-size-default">Default</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-size" id="sidebar-size-compact" value="compact" onchange="document.body.setAttribute('data-sidebar-size', 'md')"> <label class="form-check-label" for="sidebar-size-compact">Compact</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-size" id="sidebar-size-small" value="small" onchange="document.body.setAttribute('data-sidebar-size', 'sm')"> <label class="form-check-label" for="sidebar-size-small">Small (Icon View)</label> </div> <h6 class="mt-4 mb-3 pt-2 sidebar-setting">Sidebar Color</h6> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-color" id="sidebar-color-light" value="light" onchange="document.body.setAttribute('data-sidebar', 'light')"> <label class="form-check-label" for="sidebar-color-light">Light</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-color" id="sidebar-color-dark" value="dark" onchange="document.body.setAttribute('data-sidebar', 'dark')"> <label class="form-check-label" for="sidebar-color-dark">Dark</label> </div> <div class="form-check sidebar-setting"> <input class="form-check-input" type="radio" name="sidebar-color" id="sidebar-color-brand" value="brand" onchange="document.body.setAttribute('data-sidebar', 'brand')"> <label class="form-check-label" for="sidebar-color-brand">Brand</label> </div> <h6 class="mt-4 mb-3 pt-2">Direction</h6> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-direction" id="layout-direction-ltr" value="ltr"> <label class="form-check-label" for="layout-direction-ltr">LTR</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="layout-direction" id="layout-direction-rtl" value="rtl"> <label class="form-check-label" for="layout-direction-rtl">RTL</label> </div> </div> </div> <!-- end slimscroll-menu--> </div> <!-- /Right-bar --> <!-- Right bar overlay--> <div class="rightbar-overlay"></div> <script> document.addEventListener('DOMContentLoaded', function () { // Get form elements const goldQuantityInput = document.getElementById('gold_quantity'); const goldPriceInput = document.getElementById('gold_price'); const diamondQuantityInput = document.getElementById('diamond_quantity'); const diamondPriceInput = document.getElementById('diamond_price'); const additionalChargeInput = document.getElementById('additional_charge'); const profitPercentageInput = document.getElementById('profit_percentage'); const gstPercentageInput = document.getElementById('gst_percentage'); const totalCostInput = document.getElementById('total_cost'); const diamondFields = document.getElementById('diamond_quantity_group'); const diamondPriceFields = document.getElementById('diamond_price_group'); // Category selection element const categorySelect = document.getElementById('category_select'); // Show or hide diamond fields based on category status categorySelect.addEventListener('change', function () { const selectedOption = this.options[this.selectedIndex]; const status = selectedOption.getAttribute('data-status'); if (status === 'diamond') { diamondFields.classList.remove('hidden'); diamondPriceFields.classList.remove('hidden'); } else { diamondFields.classList.add('hidden'); diamondPriceFields.classList.add('hidden'); } }); // Function to calculate total cost function calculateTotal() { const goldQuantity = parseFloat(goldQuantityInput.value) || 0; const goldPrice = parseFloat(goldPriceInput.value) || 0; const diamondQuantity = parseFloat(diamondQuantityInput.value) || 0; const diamondPrice = parseFloat(diamondPriceInput.value) || 0; const additionalCharge = parseFloat(additionalChargeInput.value) || 0; const profitPercentage = parseFloat(profitPercentageInput.value) || 0; const gstPercentage = parseFloat(gstPercentageInput.value) || 0; // Calculate gold and diamond totals const goldTotal = goldQuantity * goldPrice; const diamondTotal = diamondQuantity * diamondPrice; const totalBeforeCharges = goldTotal + diamondTotal; // Calculate additional charges and profit const makingChargeAmount = (totalBeforeCharges * additionalCharge) / 100; const profitAmount = (totalBeforeCharges * profitPercentage) / 100; const subtotal = totalBeforeCharges + makingChargeAmount + profitAmount; // Calculate GST and total cost const gstAmount = (subtotal * gstPercentage) / 100; const totalPrice = subtotal + gstAmount; // Display the total cost totalCostInput.value = totalPrice.toFixed(2); } // Attach event listeners for calculating the total dynamically goldQuantityInput.addEventListener('input', calculateTotal); goldPriceInput.addEventListener('input', calculateTotal); diamondQuantityInput.addEventListener('input', calculateTotal); diamondPriceInput.addEventListener('input', calculateTotal); additionalChargeInput.addEventListener('input', calculateTotal); profitPercentageInput.addEventListener('input', calculateTotal); gstPercentageInput.addEventListener('input', calculateTotal); }); </script> <!-- JAVASCRIPT --> <script src="assets/libs/jquery/jquery.min.js"></script> <script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script> <script src="assets/libs/metismenu/metisMenu.min.js"></script> <script src="assets/libs/simplebar/simplebar.min.js"></script> <script src="assets/libs/node-waves/waves.min.js"></script> <script src="assets/libs/feather-icons/feather.min.js"></script> <!-- pace js --> <script src="assets/libs/pace-js/pace.min.js"></script> <!-- apexcharts --> <script src="assets/libs/apexcharts/apexcharts.min.js"></script> <!-- Plugins js--> <script src="assets/libs/admin-resources/jquery.vectormap/jquery-jvectormap-1.2.2.min.js"></script> <script src="assets/libs/admin-resources/jquery.vectormap/maps/jquery-jvectormap-world-mill-en.js"></script> <!-- dashboard init --> <script src="assets/js/pages/dashboard.init.js"></script> <script src="assets/js/app.js"></script> <script> function getChartColorsArray(colors) { try { return JSON.parse(colors); } catch (e) { console.error("Invalid JSON for chart colors: ", colors); return []; // Return an empty array or a default value } } </script> </body> </html>