-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook_keeping.js
40 lines (35 loc) · 1.16 KB
/
book_keeping.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { InvoiceStatus } from './Constants.js';
class AccountingSoftware {
constructor() {
this.invoices = [];
this.dbKey = 'invoicesDB';
this.loadInvoicesFromDB();
}
// Load invoices from browser storage
loadInvoicesFromDB() {
const storedInvoices = localStorage.getItem(this.dbKey);
this.invoices = storedInvoices ? JSON.parse(storedInvoices) : [];
console.log(`${this.invoices.length} invoices loaded from the browser database.`);
}
// Save invoices to browser storage
saveInvoicesToDB() {
localStorage.setItem(this.dbKey, JSON.stringify(this.invoices));
console.log('Invoices saved to the browser database.');
}
addInvoice(invoice) {
this.invoices.push(invoice);
this.saveInvoicesToDB();
console.log('Invoice added: ', invoice);
}
// Mark an invoice as paid
markInvoicePaid(invoiceNumber) {
const invoice = this.invoices.find(i => i.invoiceNumber === invoiceNumber);
if (!invoice) {
console.error(`Invoice #${invoiceNumber} not found`);
return;
}
invoice.status = InvoiceStatus.PAID;
this.saveInvoicesToDB();
console.log(`Invoice #${invoiceNumber} marked as paid`);
}
}