Файловый менеджер - Редактировать - /home/d46091/invoice.ecogenix.in/bill_book.php
Назад
<?php require_once('includes/connection.php'); if (!isset($_GET['id']) || empty($_GET['id'])) { echo "Invalid item ID."; exit; } $id = intval($_GET['id']); $stmt = $conn->prepare("SELECT * FROM road_challans WHERE id = ?"); $stmt->bind_param("i", $id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows === 0) { echo "Record not found."; exit; } $challan = $result->fetch_assoc(); $d_vehicle_date = $challan['d_vehicle_date']; // echo $d_vehicle_date; // die(); // Handle form submission if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Escape string values $bill_book_vendor = $conn->real_escape_string($_POST['bill_book_vendor'] ?? ''); $bill_book_invoice = $conn->real_escape_string($_POST['bill_book_invoice'] ?? ''); $bill_book_date = $conn->real_escape_string($_POST['bill_book_date'] ?? ''); $bill_book_vehicle_type = $conn->real_escape_string($_POST['bill_book_vehicle_type'] ?? ''); $d_vehicle_date = $conn->real_escape_string($_POST['d_vehicle_date'] ?? ''); $date_of_reach = $conn->real_escape_string($_POST['date_of_reach'] ?? ''); $days_diff = (int)($_POST['days_diff'] ?? 0); $updated_at = date('Y-m-d H:i:s'); // Escape and format date_of_unloading $date_raw = $_POST['date_of_unloading'] ?? ''; $formatted_date = $date_raw ? date('Y-m-d H:i:s', strtotime($date_raw)) : null; $date_of_unloading = $formatted_date ? "'" . $conn->real_escape_string($formatted_date) . "'" : "NULL"; // Numeric values function get_numeric_or_null($value) { return is_numeric($value) ? $value : 'NULL'; } $bill_book_value = get_numeric_or_null($_POST['bill_book_value'] ?? null); $bill_book_loading_expenses = get_numeric_or_null($_POST['bill_book_loading_expenses'] ?? null); $bill_book_office_expenses = get_numeric_or_null($_POST['bill_book_office_expenses'] ?? null); $bill_book_total_cost = get_numeric_or_null($_POST['bill_book_total_cost'] ?? null); $bill_book_lease_exp = get_numeric_or_null($_POST['bill_book_lease_exp'] ?? null); $bill_book_fuel_exp = get_numeric_or_null($_POST['bill_book_fuel_exp'] ?? null); $bill_book_toll_exp = get_numeric_or_null($_POST['bill_book_toll_exp'] ?? null); $bill_book_freight_exp = get_numeric_or_null($_POST['bill_book_freight_exp'] ?? null); $bill_book_road_exp = get_numeric_or_null($_POST['bill_book_road_exp'] ?? null); $bill_book_total_exp = get_numeric_or_null($_POST['bill_book_total_exp'] ?? null); // Build SQL $sql = "UPDATE `road_challans` SET `bill_book_vendor` = '$bill_book_vendor', `bill_book_invoice` = '$bill_book_invoice', `bill_book_date` = '$bill_book_date', `bill_book_value` = $bill_book_value, `bill_book_loading_expenses` = $bill_book_loading_expenses, `bill_book_office_expenses` = $bill_book_office_expenses, `bill_book_total_cost` = $bill_book_total_cost, `bill_book_vehicle_type` = '$bill_book_vehicle_type', `bill_book_lease_exp` = $bill_book_lease_exp, `bill_book_fuel_exp` = $bill_book_fuel_exp, `bill_book_toll_exp` = $bill_book_toll_exp, `bill_book_freight_exp` = $bill_book_freight_exp, `bill_book_road_exp` = $bill_book_road_exp, `bill_book_total_exp` = $bill_book_total_exp, `d_vehicle_date` = '$d_vehicle_date', `date_of_reach` = '$date_of_reach', `date_of_unloading` = $date_of_unloading, `days_diff` = $days_diff, `updated_at` = '$updated_at' WHERE `id` = $id"; // Debug option // echo $sql; exit; if ($conn->query($sql) === TRUE) { echo "<script> alert('Bill Updated successfully!'); window.location.href = 'challan.php'; </script>"; } else { echo "Error updating record: " . $conn->error; } exit; } require_once('includes/header.php'); ?> <div class="content"> <div class="container mt-4"> <h2>Bill Book Details</h2> <div class="card m-2 shadow-lg p-2"> <div class="card-body"> <form method="POST"> <div class="row"> <!-- Vendor Name --> <div class="col-md-3"> <div class="mb-3"> <label for="bill_book_vendor" class="form-label">Vendor Name</label> <select class="form-select" id="bill_book_vendor" name="bill_book_vendor"> <option value="" selected disabled>--Select Vendor Name--</option> <?php $vendor_query = "SELECT `id`, `company_name` FROM `vendor_master` WHERE `status` = 1"; $result = $conn->query($vendor_query); if ($result && $result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $companyName = htmlspecialchars($row['company_name']); echo "<option value='$companyName'>$companyName</option>"; } } ?> </select> </div> </div> <!-- Invoice No. --> <div class="col-md-3"> <div class="mb-3"> <label for="bill_book_invoice" class="form-label">Vendor Invoice No.</label> <input type="text" id="bill_book_invoice" name="bill_book_invoice" class="form-control"> </div> </div> <!-- Date --> <div class="col-md-3"> <div class="mb-3"> <label for="bill_book_date" class="form-label">Vendor Bill Date</label> <input type="date" id="bill_book_date" name="bill_book_date" class="form-control"> </div> </div> <!-- Value --> <div class="col-md-3"> <div class="mb-3"> <label for="value" class="form-label">Value</label> <input type="number" step="0.01" id="value" name="bill_book_value" class="form-control"> </div> </div> <!-- Loading Expenses --> <div class="col-md-3"> <div class="mb-3"> <label for="loading_expenses" class="form-label">Loading Expenses</label> <input type="number" step="0.01" id="loading_expenses" name="bill_book_loading_expenses" class="form-control"> </div> </div> <!-- Office Expenses --> <div class="col-md-3"> <div class="mb-3"> <label for="office_expenses" class="form-label">Office Expenses</label> <input type="number" step="0.01" id="office_expenses" name="bill_book_office_expenses" class="form-control"> </div> </div> <!-- Total Cost --> <div class="col-md-3"> <div class="mb-3"> <label for="total_cost" class="form-label">Total Cost</label> <input type="number" step="0.01" id="total_cost" name="bill_book_total_cost" class="form-control" readonly> </div> </div> <div class="col-md-2"> <fieldset class="mb-3"> <legend class="form-label">Is Vehicle</legend> <div class="form-check form-check-inline"> <input type="radio" id="vehicle_leased" name="bill_book_vehicle_type" class="form-check-input vehicle-type" value="Leased" <?= (!empty($challan['bill_book_vehicle_type']) && $challan['bill_book_vehicle_type'] === 'Leased') ? 'checked' : '' ?>> <label class="form-check-label" for="vehicle_leased">Leased</label> </div> <div class="form-check form-check-inline"> <input type="radio" id="vehicle_hired" name="bill_book_vehicle_type" class="form-check-input vehicle-type" value="Hired" <?= (!empty($challan['bill_book_vehicle_type']) && $challan['bill_book_vehicle_type'] === 'Hired') ? 'checked' : '' ?>> <label class="form-check-label" for="vehicle_hired">Hired</label> </div> <div class="form-check form-check-inline"> <input type="radio" id="vehicle_suppliered" name="bill_book_vehicle_type" class="form-check-input vehicle-type" value="Supplier" <?= (!empty($challan['bill_book_vehicle_type']) && $challan['bill_book_vehicle_type'] === 'Supplier') ? 'checked' : '' ?>> <label class="form-check-label" for="vehicle_suppliered">Supplier</label> </div> </fieldset> </div> <div class="col-md-3"> <div class="form-group"> <label>Vehicle Dispatch Date:</label> <input type="date" id="d_vehicle_date" name="d_vehicle_date" class="form-control" required value="<?= $d_vehicle_date ?>"> </div> </div> <!-- Date Of Reaching --> <div class="col-md-3"> <label for="date_of_reach">Date Of Reaching</label> <input type="date" id="date_of_reach" name="date_of_reach" class="form-control"> </div> <!-- Date Of Unloading --> <div class="col-md-3"> <label for="date_of_unloading">Date Of Unloading</label> <input type="datetime-local" id="date_of_unloading" name="date_of_unloading" class="form-control"> </div> <!-- Days Difference Display --> <div class="col-md-3"> <label>Transit Days</label> <input type="text" id="days_diff" name="days_diff" class="form-control" readonly> </div> <!-- Lease, Fuel, Toll Expenses (Leased only) --> <div class="col-md-3 lease-expenses" style="display:none;"> <div class="mb-3"> <label for="bill_book_lease_exp" class="form-label">Lease Expense</label> <input type="number" step="0.01" id="lease_exp" name="bill_book_lease_exp" class="form-control expense-input"> </div> </div> <div class="col-md-3 lease-expenses" style="display:none;"> <div class="mb-3"> <label for="bill_book_fuel_exp" class="form-label">Fuel Expense</label> <input type="number" step="0.01" id="fuel_exp" name="bill_book_fuel_exp" class="form-control expense-input"> </div> </div> <div class="col-md-3 lease-expenses" style="display:none;"> <div class="mb-3"> <label for="bill_book_toll_exp" class="form-label">Toll Expense</label> <input type="number" step="0.01" id="toll_exp" name="bill_book_toll_exp" class="form-control expense-input"> </div> </div> <!-- Freight Expense (Hired only) --> <div class="col-md-3 hired-expenses" style="display:none;"> <div class="mb-3"> <label for="bill_book_freight_exp" class="form-label">Freight Expense</label> <input type="number" step="0.01" id="freight_exp" name="bill_book_freight_exp" class="form-control expense-input"> </div> </div> <!-- Road Expense (Always visible) --> <div class="col-md-3"> <div class="mb-3"> <label for="bill_book_road_exp" class="form-label">Road Expenses</label> <input type="number" step="0.01" id="road_exp" name="bill_book_road_exp" class="form-control expense-input"> </div> </div> <!-- Total Expense (Always visible, readonly) --> <div class="col-md-3"> <div class="mb-3"> <label for="bill_book_total_exp" class="form-label">Total Expense</label> <input type="number" step="0.01" id="total_exp" name="bill_book_total_exp" class="form-control" readonly> </div> </div> <script> function updateVisibility() { const leased = document.getElementById('vehicle_leased').checked; const hired = document.getElementById('vehicle_hired').checked; document.querySelectorAll('.lease-expenses').forEach(el => { el.style.display = leased ? 'block' : 'none'; if (!leased) { el.querySelector('input').value = ''; // clear input when hidden } }); document.querySelectorAll('.hired-expenses').forEach(el => { el.style.display = hired ? 'block' : 'none'; if (!hired) { el.querySelector('input').value = ''; } }); calculateTotal(); } function calculateTotal() { let total = 0; document.querySelectorAll('.expense-input').forEach(input => { const val = parseFloat(input.value); if (!isNaN(val)) { total += val; } }); document.getElementById('total_exp').value = total.toFixed(2); } // Event listeners document.querySelectorAll('.vehicle-type').forEach(radio => { radio.addEventListener('change', updateVisibility); }); document.querySelectorAll('.expense-input').forEach(input => { input.addEventListener('input', calculateTotal); }); // Initialize on page load window.addEventListener('DOMContentLoaded', () => { updateVisibility(); // If you want to prefill inputs from PHP $challan, you can do it here or directly in HTML value attributes }); </script> </div> <!-- Buttons --> <button type="submit" class="btn btn-primary">Submit</button> <a href="challan.php" class="btn btn-secondary">Cancel</a> </form> </div> </div> </div> </div> <?php require_once('includes/footer.php'); ?> <!-- JavaScript --> <script> const valueInput = document.getElementById('value'); const loadInput = document.getElementById('loading_expenses'); const officeInput = document.getElementById('office_expenses'); const totalInput = document.getElementById('total_cost'); function updateTotal() { const v = parseFloat(valueInput.value) || 0; const l = parseFloat(loadInput.value) || 0; const o = parseFloat(officeInput.value) || 0; const sum = v + l + o; totalInput.value = sum.toFixed(2); } // Listen for input events [valueInput, loadInput, officeInput].forEach(el => { el.addEventListener('input', updateTotal); }); // Run once on page load document.addEventListener('DOMContentLoaded', updateTotal); // Optional: restrict inputs to numeric characters only (if type="text" is used) document.querySelectorAll('.only-number').forEach(input => { input.addEventListener('input', () => { input.value = input.value.replace(/[^0-9.]/g, ''); }); }); </script> <script> document.getElementById('date_of_unloading').addEventListener('change', calculateDaysDiff); document.getElementById('d_vehicle_date').addEventListener('change', calculateDaysDiff); function calculateDaysDiff() { const dispatchDate = document.getElementById('d_vehicle_date').value; const unloadingDate = document.getElementById('date_of_unloading').value; const daysDiffInput = document.getElementById('days_diff'); if (dispatchDate && unloadingDate) { const dispatch = new Date(dispatchDate); const unload = new Date(unloadingDate); // Calculate the difference in milliseconds const diffTime = unload - dispatch; const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); // Show difference only if unload date is after dispatch date if (diffDays >= 0) { daysDiffInput.value = diffDays; } else { daysDiffInput.value = 'Invalid dates'; } } else { daysDiffInput.value = ''; } } </script>
| ver. 1.4 |
Github
|
.
| PHP 8.1.32 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка