Init commit

This commit is contained in:
Marek Fraczyk
2021-02-16 16:24:22 +02:00
parent 056a817632
commit 79e9705b01
106 changed files with 18400 additions and 0 deletions

View File

@ -0,0 +1,48 @@
import storage from 'localforage';
class InvoiceService {
async getInvoices() {
const invoices = await storage.getItem('invoices');
return invoices || [];
}
async getInvoice(invoiceId) {
const invoices = await this.getInvoices();
return invoices.find(invoice => invoice.id === invoiceId);
}
async createInvoice(invoice) {
// TODO: add invoice no, issued_at, due_at, late_fee, prefill company info, bank_info, currency, vat_rate
const invoices = await this.getInvoices();
delete invoice.$id;
delete invoice.$isNew;
delete invoice.$isDirty;
invoices.push(invoice);
await storage.setItem('invoices', invoices);
}
async updateInvoice(invoice) {
// TODO: validation
const invoices = await this.getInvoices();
const index = invoices.findIndex(item => item.id === invoice.id);
invoices[index] = invoice;
return storage.setItem('invoices', invoices);
}
async deleteInvoice(invoiceId) {
const invoices = await this.getInvoices();
const index = invoices.findIndex(item => item.id === invoiceId);
invoices.splice(index, 1);
return storage.setItem('invoices', invoices);
}
bookInvoice(invoice) {
// TODO: validation
invoice.status = 'booked';
return this.updateInvoice(invoice);
}
}
export default new InvoiceService();