mirror of
https://github.com/frappe/books.git
synced 2025-01-11 02:36:14 +00:00
eslint fixes
This commit is contained in:
parent
bb5dc896c8
commit
1a5d01ffeb
@ -1,83 +1,86 @@
|
|||||||
const frappe = require('frappejs');
|
const frappe = require('frappejs');
|
||||||
|
|
||||||
module.exports = class LedgerPosting {
|
module.exports = class LedgerPosting {
|
||||||
constructor({reference, party, date, description}) {
|
constructor({ reference, party, date, description }) {
|
||||||
Object.assign(this, arguments[0]);
|
Object.assign(this, arguments[0]);
|
||||||
this.entries = [];
|
this.entries = [];
|
||||||
this.entryMap = {};
|
this.entryMap = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
debit(account, amount, referenceType, referenceName) {
|
||||||
|
const entry = this.getEntry(account, referenceType, referenceName);
|
||||||
|
entry.debit += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
credit(account, amount, referenceType, referenceName) {
|
||||||
|
const entry = this.getEntry(account, referenceType, referenceName);
|
||||||
|
entry.credit += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
getEntry(account, referenceType, referenceName) {
|
||||||
|
if (!this.entryMap[account]) {
|
||||||
|
const entry = {
|
||||||
|
account: account,
|
||||||
|
party: this.party || '',
|
||||||
|
date: this.date || this.reference.date,
|
||||||
|
referenceType: referenceType || this.reference.doctype,
|
||||||
|
referenceName: referenceName || this.reference.name,
|
||||||
|
description: this.description,
|
||||||
|
debit: 0,
|
||||||
|
credit: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
this.entries.push(entry);
|
||||||
|
this.entryMap[account] = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
debit(account, amount, referenceType, referenceName) {
|
return this.entryMap[account];
|
||||||
const entry = this.getEntry(account, referenceType, referenceName);
|
}
|
||||||
entry.debit += amount;
|
|
||||||
|
async post() {
|
||||||
|
this.validateEntries();
|
||||||
|
await this.insertEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
async postReverse() {
|
||||||
|
this.validateEntries();
|
||||||
|
let temp;
|
||||||
|
for (let entry of this.entries) {
|
||||||
|
temp = entry.debit;
|
||||||
|
entry.debit = entry.credit;
|
||||||
|
entry.credit = temp;
|
||||||
|
}
|
||||||
|
await this.insertEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
validateEntries() {
|
||||||
|
let debit = 0;
|
||||||
|
let credit = 0;
|
||||||
|
let debitAccounts = [];
|
||||||
|
let creditAccounts = [];
|
||||||
|
|
||||||
|
for (let entry of this.entries) {
|
||||||
|
debit += entry.debit;
|
||||||
|
credit += entry.credit;
|
||||||
|
if (debit) {
|
||||||
|
debitAccounts.push(entry.account);
|
||||||
|
} else {
|
||||||
|
creditAccounts.push(entry.account);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
credit(account, amount, referenceType, referenceName) {
|
if (debit !== credit) {
|
||||||
const entry = this.getEntry(account, referenceType, referenceName);
|
throw frappe.errors.ValidationError(frappe._('Debit {0} must be equal to Credit {1}', [debit, credit]));
|
||||||
entry.credit += amount;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getEntry(account, referenceType, referenceName) {
|
async insertEntries() {
|
||||||
if (!this.entryMap[account]) {
|
for (let entry of this.entries) {
|
||||||
const entry = {
|
let entryDoc = frappe.newDoc({
|
||||||
account: account,
|
doctype: 'AccountingLedgerEntry'
|
||||||
party: this.party || '',
|
});
|
||||||
date: this.date || this.reference.date,
|
Object.assign(entryDoc, entry);
|
||||||
referenceType: referenceType || this.reference.doctype,
|
await entryDoc.insert();
|
||||||
referenceName: referenceName || this.reference.name,
|
|
||||||
description: this.description,
|
|
||||||
debit: 0,
|
|
||||||
credit: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
this.entries.push(entry);
|
|
||||||
this.entryMap[account] = entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.entryMap[account];
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
async post() {
|
};
|
||||||
this.validateEntries();
|
|
||||||
await this.insertEntries();
|
|
||||||
}
|
|
||||||
|
|
||||||
async postReverse() {
|
|
||||||
this.validateEntries();
|
|
||||||
let temp;
|
|
||||||
for (let entry of this.entries) {
|
|
||||||
temp = entry.debit;
|
|
||||||
entry.debit = entry.credit;
|
|
||||||
entry.credit = temp;
|
|
||||||
}
|
|
||||||
await this.insertEntries();
|
|
||||||
}
|
|
||||||
|
|
||||||
validateEntries() {
|
|
||||||
let debit = 0, credit = 0;
|
|
||||||
let debitAccounts = [], creditAccounts = [];
|
|
||||||
for (let entry of this.entries) {
|
|
||||||
debit += entry.debit;
|
|
||||||
credit += entry.credit;
|
|
||||||
if (debit) {
|
|
||||||
debitAccounts.push(entry.account);
|
|
||||||
} else {
|
|
||||||
creditAccounts.push(entry.account);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (debit !== credit) {
|
|
||||||
throw frappe.errors.ValidationError(frappe._("Debit {0} must be equal to Credit {1}", [debit, credit]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async insertEntries() {
|
|
||||||
for (let entry of this.entries) {
|
|
||||||
let entryDoc = frappe.newDoc({
|
|
||||||
doctype: 'AccountingLedgerEntry'
|
|
||||||
});
|
|
||||||
Object.assign(entryDoc, entry);
|
|
||||||
await entryDoc.insert();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,30 +1,28 @@
|
|||||||
const Invoice = require('./InvoiceDocument');
|
const Invoice = require('./InvoiceDocument');
|
||||||
const frappe = require('frappejs');
|
|
||||||
const LedgerPosting = require('../../../accounting/ledgerPosting');
|
const LedgerPosting = require('../../../accounting/ledgerPosting');
|
||||||
|
|
||||||
module.exports = class InvoiceServer extends Invoice {
|
module.exports = class InvoiceServer extends Invoice {
|
||||||
getPosting() {
|
getPosting() {
|
||||||
let entries = new LedgerPosting({reference: this, party: this.customer});
|
let entries = new LedgerPosting({ reference: this, party: this.customer });
|
||||||
entries.debit(this.account, this.grandTotal);
|
entries.debit(this.account, this.grandTotal);
|
||||||
|
|
||||||
for (let item of this.items) {
|
|
||||||
entries.credit(item.account, item.amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.taxes) {
|
|
||||||
for (let tax of this.taxes) {
|
|
||||||
entries.credit(tax.account, tax.amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return entries;
|
|
||||||
|
|
||||||
|
for (let item of this.items) {
|
||||||
|
entries.credit(item.account, item.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
async afterSubmit() {
|
if (this.taxes) {
|
||||||
await this.getPosting().post();
|
for (let tax of this.taxes) {
|
||||||
|
entries.credit(tax.account, tax.amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
async afterRevert() {
|
async afterSubmit() {
|
||||||
await this.getPosting().postReverse();
|
await this.getPosting().post();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
async afterRevert() {
|
||||||
|
await this.getPosting().postReverse();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user