Файловый менеджер - Редактировать - /home/d46091/invoice.ecogenix.in/generate_challan_no.php
Назад
<?php require_once('includes/connection.php'); header('Content-Type: application/json'); if (isset($_POST['companyName'])) { $companyName = $_POST['companyName']; // 1. Fetch company code $stmt = $conn->prepare("SELECT c_inv FROM company_master WHERE c_name = ?"); $stmt->bind_param("s", $companyName); $stmt->execute(); $stmt->bind_result($c_inv); $stmt->fetch(); $stmt->close(); if (!$c_inv) { echo json_encode(['success' => false, 'message' => 'Company code not found']); exit; } // 2. Determine financial year (e.g., 24-25) $currentMonth = date('n'); $yearStart = ($currentMonth >= 4) ? (int)date('y') : (int)date('y', strtotime('-1 year')); $yearEnd = sprintf("%02d", ($yearStart + 1) % 100); $financialYear = "{$yearStart}-{$yearEnd}"; // 3. Create prefix and search pattern $prefix = "{$c_inv}/{$financialYear}/"; $like = $prefix . "%"; // 4. Fetch latest challan number $stmt = $conn->prepare("SELECT challan_no FROM challan_master WHERE challan_no LIKE ? ORDER BY id DESC LIMIT 1"); $stmt->bind_param("s", $like); $stmt->execute(); $stmt->bind_result($lastChallan); $stmt->fetch(); $stmt->close(); $lastSerial = 0; if ($lastChallan) { // Normalize slashes in case of malformed challans like SSCT/25-26//25-26/1 $lastChallan = preg_replace('/\/+/', '/', $lastChallan); $segments = explode('/', $lastChallan); if (count($segments) === 3 && is_numeric($segments[2])) { $lastSerial = (int)$segments[2]; } } $newSerial = $lastSerial + 1; $challanNo = $prefix . $newSerial; // ✅ Return challan number only (do not insert) echo json_encode([ 'success' => true, 'challanNo' => $challanNo ]); exit; } // Invalid request fallback echo json_encode(['success' => false, 'message' => 'Invalid request']);
| ver. 1.4 |
Github
|
.
| PHP 8.1.32 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка