Files
oxpoe eaf05f2811 OPEN-ISP v0.5 (pickle-lime) — rilis open-source perdana
Aplikasi billing & manajemen ISP (fiber optic) — PWA pelanggan, portal teknisi & kolektor,
admin panel lengkap, multi-vendor OLT, RADIUS, WhatsApp/Telegram, pembayaran QRIS.

Kredit & lisensi (ISC):
- Base kode & repo: alijayanet/billing-rtrw oleh Alijaya Net — terima kasih banyak
  atas base kode dan repo yang bermanfaat.
- Add-on: GoWA, LibreSpeed/OpenSpeedTest, Uptime Kuma, notification-forwarder.
- Dikembangkan menjadi OPEN-ISP oleh oxpoe — https://github.com/oxpoe/open-isp
2026-10-09 05:51:21 +07:00

47 lines
1.5 KiB
JavaScript

/**
* Service: Pelacakan Pemakaian Kuota (Usage Tracking)
*/
const db = require('../config/database');
const { logger } = require('../config/logger');
function getUsage(customerId, month, year) {
return db.prepare('SELECT * FROM customer_usage WHERE customer_id = ? AND period_month = ? AND period_year = ?')
.get(customerId, month, year);
}
function updateUsage(customerId, deltaIn, deltaOut, totalIn, totalOut) {
const now = new Date();
const month = now.getMonth() + 1;
const year = now.getFullYear();
const existing = getUsage(customerId, month, year);
if (existing) {
return db.prepare(`
UPDATE customer_usage
SET bytes_in = bytes_in + ?,
bytes_out = bytes_out + ?,
last_total_bytes_in = ?,
last_total_bytes_out = ?,
updated_at = (NOW_LOCAL())
WHERE id = ?
`).run(deltaIn, deltaOut, totalIn, totalOut, existing.id);
} else {
return db.prepare(`
INSERT INTO customer_usage (customer_id, period_month, period_year, bytes_in, bytes_out, last_total_bytes_in, last_total_bytes_out)
VALUES (?, ?, ?, ?, ?, ?, ?)
`).run(customerId, month, year, deltaIn, deltaOut, totalIn, totalOut);
}
}
function resetUsageCounter(customerId) {
const now = new Date();
return db.prepare(`
UPDATE customer_usage
SET last_total_bytes_in = 0, last_total_bytes_out = 0
WHERE customer_id = ? AND period_month = ? AND period_year = ?
`).run(customerId, now.getMonth() + 1, now.getFullYear());
}
module.exports = { getUsage, updateUsage, resetUsageCounter };