V1rus Private
User / IP
:
216.73.217.108
Host / Server
:
190.92.174.125 / aerosofthealthcare.com
System
:
Linux s3739.bom1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64
Cmd
|
Upload
|
Mass Deface
|
Create
|
Sym
:
/
home
/
aerosoft
/
public_html
/
InventorySystem
/
Viewing: add_sale.php
<?php $page_title = 'Add Sale'; require_once('includes/load.php'); page_require_level(3); $current_store_id = get_current_store_id(); $store_products = find_products_by_store($current_store_id); ?> <?php if(isset($_POST['add_sale'])){ $req_fields = array('sale_date', 'payment_type'); validate_fields($req_fields); if(empty($errors)){ $s_date = $db->escape($_POST['sale_date']); $store_id = $current_store_id; $payment_type = $db->escape($_POST['payment_type']); $is_transferred_out = isset($_POST['is_transferred_out']) ? 1 : 0; // Process multiple products if(isset($_POST['product_id']) && is_array($_POST['product_id'])){ $success_count = 0; $out_of_stock_products = array(); foreach($_POST['product_id'] as $key => $product_id){ if(!empty($product_id) && !empty($_POST['quantity'][$key]) && !empty($_POST['price'][$key])){ $p_id = $db->escape((int)$product_id); $s_qty = $db->escape((int)$_POST['quantity'][$key]); // Check stock availability $product = find_by_id('products', $p_id); if($product['quantity'] < $s_qty){ $out_of_stock_products[] = $product['name'] . " (Available: " . $product['quantity'] . ", Requested: " . $s_qty . ")"; continue; // Skip this product } $s_price = $db->escape((float)$_POST['price'][$key]); $s_total = $s_qty * $s_price; $buy_price = (float)$product['buy_price']; // For transferred out sales, profit is calculated differently if($is_transferred_out == 1) { $profit = 0; // No profit for transferred stock out } else { $profit = ($s_price - $buy_price) * $s_qty; } $sql = "INSERT INTO sales (product_id, qty, price, total, buy_price, profit, date, store_id, payment_type, is_transferred_out) VALUES ('{$p_id}','{$s_qty}','{$s_price}','{$s_total}','{$buy_price}','{$profit}','{$s_date}','{$store_id}','{$payment_type}','{$is_transferred_out}')"; if($db->query($sql)){ update_product_qty($s_qty, $p_id); $success_count++; } } } if(!empty($out_of_stock_products)){ $session->msg('w', "Some products are out of stock: " . implode(', ', $out_of_stock_products)); } if($success_count > 0){ $sale_type = $is_transferred_out ? 'Transferred Stock Out' : 'Regular Sale'; $session->msg('s', "{$success_count} {$sale_type}(s) added successfully. Payment: " . strtoupper($payment_type)); redirect('add_sale.php', false); } else { $session->msg('d', 'Failed to add sales. Check product availability.'); redirect('add_sale.php', false); } } else { $session->msg('d', 'No products selected.'); redirect('add_sale.php', false); } } else { $session->msg("d", $errors); redirect('add_sale.php', false); } } ?> <?php include_once('layouts/header.php'); ?> <div class="row"> <div class="col-md-12"> <?php echo display_msg($msg); ?> </div> </div> <div class="row"> <div class="col-md-8"> <div class="panel panel-default"> <div class="panel-heading clearfix"> <strong> <span class="glyphicon glyphicon-th"></span> <span>Add New Sale - <?php echo get_current_store_name(); ?></span> </strong> </div> <div class="panel-body"> <form method="post" action="add_sale.php" id="sale-form"> <!-- Sale Type Selection --> <div class="row"> <div class="col-md-12"> <div class="form-group"> <div class="checkbox" style="background-color: #e3f2fd; padding: 15px; border-radius: 5px; border: 2px solid #2196f3;"> <label style="font-size: 16px;"> <input type="checkbox" name="is_transferred_out" id="is_transferred_out" value="1" style="transform: scale(1.3); margin-right: 10px;"> <strong class="text-info" style="font-size: 18px;">TRANSFERRED STOCK VALUE (OUT)</strong> </label> <br> <small class="help-block text-muted"> ✅ Check this if you're transferring stock to another store (No profit will be calculated) </small> </div> </div> </div> </div> <div class="table-responsive"> <table class="table table-bordered" id="sale-table"> <thead> <tr> <th style="width: 35%;">Product</th> <th class="text-center" style="width: 12%;">Price (₹)</th> <th class="text-center" style="width: 12%;">Quantity</th> <th class="text-center" style="width: 12%;">Total (₹)</th> <th class="text-center" style="width: 12%;">Profit (₹)</th> <th class="text-center" style="width: 12%;">Stock</th> <th class="text-center" style="width: 5%;">Action</th> </tr> </thead> <tbody id="product-rows"> <!-- First row --> <tr class="product-row"> <td> <select name="product_id[]" class="form-control product-select" required> <option value="">Select Product</option> <?php foreach ($store_products as $product): $stock_class = ($product['quantity'] == 0) ? 'out-of-stock' : (($product['quantity'] < 10) ? 'low-stock' : ''); ?> <option value="<?php echo (int)$product['id']; ?>" data-price="<?php echo number_format($product['sale_price'], 2, '.', ''); ?>" data-buyprice="<?php echo number_format($product['buy_price'], 2, '.', ''); ?>" data-stock="<?php echo $product['quantity']; ?>" class="<?php echo $stock_class; ?>"> <?php echo $product['name']; ?> <?php if($product['quantity'] == 0): ?> (Out of Stock) <?php elseif($product['quantity'] < 10): ?> (Low Stock: <?php echo $product['quantity']; ?>) <?php else: ?> (Stock: <?php echo $product['quantity']; ?>) <?php endif; ?> </option> <?php endforeach; ?> </select> </td> <td> <input type="number" name="price[]" class="form-control price-input text-center" step="0.01" min="0" required readonly> </td> <td> <input type="number" name="quantity[]" class="form-control quantity-input text-center" min="1" value="1" required> <small class="stock-warning text-danger" style="display: none;"></small> </td> <td> <input type="text" name="total[]" class="form-control total-input text-center" readonly> </td> <td> <input type="text" name="profit[]" class="form-control profit-input text-center" readonly> </td> <td class="text-center"> <span class="stock-display">-</span> </td> <td class="text-center"> <button type="button" class="btn btn-danger btn-sm remove-row" disabled> <span class="glyphicon glyphicon-remove"></span> </button> </td> </tr> </tbody> <tfoot> <tr> <td colspan="7"> <button type="button" class="btn btn-success btn-sm" id="add-row"> <span class="glyphicon glyphicon-plus"></span> Add Another Product </button> </td> </tr> <tr> <td colspan="3" class="text-right"><strong>Grand Total:</strong></td> <td> <input type="text" class="form-control text-center" id="grand-total" value="₹0.00" readonly> </td> <td> <input type="text" class="form-control text-center" id="grand-profit" value="₹0.00" readonly> </td> <td colspan="2"></td> </tr> <tr id="transfer-info" style="display: none;"> <td colspan="7" class="text-center text-info"> <strong>ℹ️ Transferred Stock Mode: Profit calculation disabled</strong> </td> </tr> </tfoot> </table> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="sale_date">Sale Date:</label> <input type="datetime-local" class="form-control" name="sale_date" value="<?php echo date('Y-m-d\TH:i'); ?>" required> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="payment_type">Payment Type:</label> <select name="payment_type" class="form-control" required> <option value="">Select Payment</option> <option value="cash">Cash</option> <option value="online">Online</option> </select> </div> </div> </div> <button type="submit" name="add_sale" class="btn btn-primary btn-lg btn-block"> <span class="glyphicon glyphicon-ok"></span> Complete Sale </button> </form> </div> </div> </div> <div class="col-md-4"> <div class="panel panel-default"> <div class="panel-heading"> <strong> <span class="glyphicon glyphicon-info-sign"></span> <span>Quick Product Search</span> </strong> </div> <div class="panel-body"> <form method="post" action="ajax.php" autocomplete="off" id="sug-form"> <div class="form-group"> <div class="input-group"> <input type="text" id="sug_input" class="form-control" name="title" placeholder="Search product name"> <span class="input-group-btn"> <button type="submit" class="btn btn-primary">Find</button> </span> </div> <div id="result" class="list-group"></div> </div> </form> </div> </div> <!-- Sales Summary --> <div class="panel panel-default"> <div class="panel-heading"> <strong> <span class="glyphicon glyphicon-stats"></span> <span>Today's Summary</span> </strong> </div> <div class="panel-body"> <?php $today = date('Y-m-d'); $today_sales = get_daily_sales_summary($current_store_id, $today); ?> <div class="list-group"> <div class="list-group-item"> <span class="badge">₹<?php echo number_format($today_sales['total_sales'], 2); ?></span> Total Sales </div> <div class="list-group-item"> <span class="badge">₹<?php echo number_format($today_sales['cash_sales'], 2); ?></span> Cash Payments </div> <div class="list-group-item"> <span class="badge">₹<?php echo number_format($today_sales['online_sales'], 2); ?></span> Online Payments </div> <div class="list-group-item"> <span class="badge">₹<?php echo number_format($today_sales['total_profit'], 2); ?></span> Total Profit </div> </div> </div> </div> </div> </div> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> <script> $(document).ready(function(){ // Add new row $('#add-row').click(function(){ var newRow = $('.product-row:first').clone(); newRow.find('select').val(''); newRow.find('input').val(''); newRow.find('.price-input').val(''); newRow.find('.quantity-input').val('1'); newRow.find('.total-input').val(''); newRow.find('.profit-input').val(''); newRow.find('.stock-display').text('-'); newRow.find('.stock-warning').hide(); newRow.find('.remove-row').prop('disabled', false); $('#product-rows').append(newRow); updateGrandTotal(); }); // Remove row $(document).on('click', '.remove-row', function(){ if($('.product-row').length > 1){ $(this).closest('.product-row').remove(); updateGrandTotal(); } }); // Product selection change $(document).on('change', '.product-select', function(){ var price = $(this).find(':selected').data('price'); var buyPrice = $(this).find(':selected').data('buyprice'); var stock = $(this).find(':selected').data('stock'); var row = $(this).closest('.product-row'); row.find('.price-input').val(price); row.find('.stock-display').text(stock); row.data('buy-price', buyPrice); row.data('stock', stock); // Update quantity max value var quantityInput = row.find('.quantity-input'); quantityInput.attr('max', stock); // Check stock checkStock(row); calculateRowTotal(row); }); // Quantity change $(document).on('input', '.quantity-input', function(){ var row = $(this).closest('.product-row'); checkStock(row); calculateRowTotal(row); }); // Transferred out checkbox change $(document).on('change', '#is_transferred_out', function(){ var isChecked = $(this).is(':checked'); // Show/hide transfer info if(isChecked) { $('#transfer-info').show(); $('.profit-input').css('background-color', '#f8f9fa'); $('.profit-input').css('color', '#6c757d'); } else { $('#transfer-info').hide(); $('.profit-input').css('background-color', ''); $('.profit-input').css('color', ''); } // Recalculate all row profits when transfer status changes $('.product-row').each(function(){ calculateRowTotal($(this)); }); }); function checkStock(row){ var quantity = parseInt(row.find('.quantity-input').val()) || 0; var stock = parseInt(row.data('stock')) || 0; var warning = row.find('.stock-warning'); if(quantity > stock){ warning.text('Only ' + stock + ' available').show(); row.find('.quantity-input').addClass('is-invalid'); } else { warning.hide(); row.find('.quantity-input').removeClass('is-invalid'); } } function calculateRowTotal(row){ var price = parseFloat(row.find('.price-input').val()) || 0; var quantity = parseInt(row.find('.quantity-input').val()) || 0; var buyPrice = parseFloat(row.data('buy-price')) || 0; var isTransferredOut = $('#is_transferred_out').is(':checked'); var total = price * quantity; var profit = 0; if (!isTransferredOut) { profit = (price - buyPrice) * quantity; } row.find('.total-input').val('₹' + total.toFixed(2)); row.find('.profit-input').val('₹' + profit.toFixed(2)); updateGrandTotal(); } function updateGrandTotal(){ var grandTotal = 0; var grandProfit = 0; $('.total-input').each(function(){ var total = $(this).val().replace('₹', ''); grandTotal += parseFloat(total) || 0; }); $('.profit-input').each(function(){ var profit = $(this).val().replace('₹', ''); grandProfit += parseFloat(profit) || 0; }); $('#grand-total').val('₹' + grandTotal.toFixed(2)); $('#grand-profit').val('₹' + grandProfit.toFixed(2)); } // Initialize first row updateGrandTotal(); }); </script> <style> .out-of-stock { color: #dc3545 !important; font-weight: bold; } .low-stock { color: #ffc107 !important; font-weight: bold; } .is-invalid { border-color: #dc3545 !important; } .transferred-mode { background-color: #e3f2fd !important; border-left: 4px solid #2196f3 !important; } </style> <?php include_once('layouts/footer.php'); ?>
Coded With 💗 by
HanzOFC