diff --git a/models/doctype/JournalEntry/JournalEntry.js b/models/doctype/JournalEntry/JournalEntry.js index a6ff5931..25d9eb9e 100644 --- a/models/doctype/JournalEntry/JournalEntry.js +++ b/models/doctype/JournalEntry/JournalEntry.js @@ -70,7 +70,7 @@ module.exports = { // section 2 { fields: ["accounts"]}, // section 3 - { + { columns: [ { fields: [ "referenceNumber"] }, { fields: [ "referenceDate"] } diff --git a/models/doctype/JournalEntry/JournalEntryServer.js b/models/doctype/JournalEntry/JournalEntryServer.js index 8680dfdd..d9d6c468 100644 --- a/models/doctype/JournalEntry/JournalEntryServer.js +++ b/models/doctype/JournalEntry/JournalEntryServer.js @@ -1,10 +1,10 @@ -const BaseDocument = require('frappejs/model/document'); +const JournalEntry = require('./JournalEntry'); const frappe = require('frappejs'); -const LedgerPosting = require.main.require('./accounting/ledgerPosting'); +const LedgerPosting = rootRequire('accounting/ledgerPosting'); -module.exports = class PaymentServer extends BaseDocument { +module.exports = class JournalEntryServer extends BaseDocument { /** - + getPosting() { let entries = new LedgerPosting({reference: this, party: this.party}); entries.debit(this.paymentAccount, this.amount); @@ -24,6 +24,6 @@ module.exports = class PaymentServer extends BaseDocument { async afterRevert() { await this.getPosting().postReverse(); } - + **/ } \ No newline at end of file diff --git a/models/doctype/Quotation/Quotation.js b/models/doctype/Quotation/Quotation.js index 5ddb0a85..572fc295 100644 --- a/models/doctype/Quotation/Quotation.js +++ b/models/doctype/Quotation/Quotation.js @@ -1,8 +1,10 @@ +const deepmerge = require('deepmerge'); const Invoice = require('../Invoice/Invoice'); -const Quotation = Invoice; -Quotation.name = "Quotation"; -Quotation.label = "Quotation"; -Quotation.settings = "QuotationSettings"; +const Quotation = deepmerge(Invoice, { + name: "Quotation", + label: "Quotation", + settings: "QuotationSettings" +}); module.exports = Quotation; diff --git a/models/doctype/QuotationSettings/QuotationSettings.js b/models/doctype/QuotationSettings/QuotationSettings.js index fd423aa3..dbc26797 100644 --- a/models/doctype/QuotationSettings/QuotationSettings.js +++ b/models/doctype/QuotationSettings/QuotationSettings.js @@ -1,8 +1,11 @@ +const deepmerge = require('deepmerge'); const InvoiceSettings = require('../InvoiceSettings/InvoiceSettings'); -const QuotationSettings = InvoiceSettings; -QuotationSettings.name = "QuotationSettings"; -QuotationSettings.label = "Quotation Settings"; -QuotationSettings.fields.find((field)=>{ - if (field.fieldname == "numberSeries") field.default = "QTN"; -}); +const QuotationSettings = deepmerge(InvoiceSettings, { + "name": "QuotationSettings", + "label": "Quotation Settings", + "fields": { + "default": "INV" + } +}) + module.exports = QuotationSettings; \ No newline at end of file diff --git a/reports/ProfitAndLoss/ProfitAndLoss.js b/reports/ProfitAndLoss/ProfitAndLoss.js new file mode 100644 index 00000000..58505c76 --- /dev/null +++ b/reports/ProfitAndLoss/ProfitAndLoss.js @@ -0,0 +1,30 @@ +const frappe = require('frappejs'); +const { getData } = require('../financialStatements'); + +class ProfitAndLoss { + async run(params) { + const filters = {}; + if (params.account) filters.account = params.account; + if (params.party) filters.party = params.party; + if (params.referenceType) filters.referenceType = params.referenceType; + if (params.referenceName) filters.referenceName = params.referenceName; + if (params.fromDate) filters.date = ['>=', params.fromDate]; + if (params.toDate) filters.date = ['<=', params.toDate]; + + let income = await getData({ + rootType: 'Income', + balanceMustBe: 'Credit' + }); + + let expense = await getData({ + rootType: 'Expense', + balanceMustBe: 'Credit' + }); + + return data; + } +} + +module.exports = function execute(params) { + return new ProfitAndLoss().run(params); +} diff --git a/reports/financialStatements.js b/reports/financialStatements.js index 54aafff7..439ccdb1 100644 --- a/reports/financialStatements.js +++ b/reports/financialStatements.js @@ -1,8 +1,8 @@ const frappe = require('frappejs'); -async function getData(rootType) { +async function getData({ rootType, balanceMustBe }) { const accounts = await getAccounts(rootType); - if (!accounts || accounts.length === 0) return; + if (!accounts || accounts.length === 0) return []; const ledgerEntries = await frappe.db.getAll({ doctype: 'AccountingLedgerEntry', @@ -38,4 +38,4 @@ async function getAccounts(rootType) { module.exports = { getData -} \ No newline at end of file +} diff --git a/reports/generalLedger/GeneralLedger.js b/reports/generalLedger/GeneralLedger.js index e5f49760..81ef77cd 100644 --- a/reports/generalLedger/GeneralLedger.js +++ b/reports/generalLedger/GeneralLedger.js @@ -1,9 +1,5 @@ const frappe = require('frappejs'); -module.exports = function execute(params) { - return new GeneralLedger().run(params); -} - class GeneralLedger { async run(params) { const filters = {}; @@ -22,4 +18,8 @@ class GeneralLedger { return data; } -} \ No newline at end of file +} + +module.exports = function execute(params) { + return new GeneralLedger().run(params); +} diff --git a/server/index.js b/server/index.js index 578165cb..3a615120 100644 --- a/server/index.js +++ b/server/index.js @@ -23,7 +23,7 @@ module.exports = { // set server-side modules frappe.models.Invoice.documentClass = require('../models/doctype/Invoice/InvoiceServer.js'); frappe.models.Payment.documentClass = require('../models/doctype/Payment/PaymentServer.js'); - frappe.models.JournalEntry.documentClass = require('../models/doctype/JournalEntry/JournalEntryServer.js'); + // frappe.models.JournalEntry.documentClass = require('../models/doctype/JournalEntry/JournalEntryServer.js'); frappe.metaCache = {};