// auto_bill_generator.php ফাইল তৈরি করুন function generate_auto_bills() { global $pdo; try { // এক্সপায়ারির ৭ দিন আগের লাইসেন্সগুলো খুঁজে বের করুন $seven_days_later = date('Y-m-d', strtotime('+7 days')); $stmt = $pdo->prepare(" SELECT l.*, u.id as user_id FROM licenses l LEFT JOIN users u ON l.admin_id = u.id WHERE l.expires_at = ? AND l.status = 'active' AND l.id NOT IN ( SELECT license_id FROM invoices WHERE due_date = ? AND status IN ('pending', 'paid') ) "); $stmt->execute([$seven_days_later, $seven_days_later]); $expiring_licenses = $stmt->fetchAll(); foreach ($expiring_licenses as $license) { // প্যাকেজ প্রাইস বের করুন (আপনার লজিক অনুযায়ী) $package_price = get_package_price($license['product_name']); // ইউনিক ইনভয়েস নাম্বার জেনারেট করুন $invoice_number = 'INV-' . date('Ymd') . '-' . $license['id'] . '-' . rand(1000, 9999); // নতুন বিল ক্রিয়েট করুন $invoice_stmt = $pdo->prepare(" INSERT INTO invoices (user_id, license_id, invoice_number, amount, due_date, status) VALUES (?, ?, ?, ?, ?, 'pending') "); $invoice_stmt->execute([ $license['user_id'], $license['id'], $invoice_number, $package_price, $seven_days_later ]); } return count($expiring_licenses); } catch (PDOException $e) { error_log("Auto bill generation error: " . $e->getMessage()); return false; } }