From 7bf0cf12d9405cdd886a247a03ed439579bc8a89 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Wed, 28 Mar 2018 17:42:13 +0530 Subject: [PATCH] Journal Entry DocType added --- client/index.js | 1 + models/doctype/Address/Address.js | 1 - models/doctype/JournalEntry/JournalEntry.js | 83 +++++++++++++++++++ .../JournalEntry/JournalEntryServer.js | 29 +++++++ .../JournalEntryAccount.js | 27 ++++++ .../JournalEntrySetting.js | 18 ++++ models/index.js | 8 +- server/index.js | 2 + 8 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 models/doctype/JournalEntry/JournalEntry.js create mode 100644 models/doctype/JournalEntry/JournalEntryServer.js create mode 100644 models/doctype/JournalEntryAccount/JournalEntryAccount.js create mode 100644 models/doctype/JournalEntrySetting/JournalEntrySetting.js diff --git a/client/index.js b/client/index.js index 5379465e..41391414 100644 --- a/client/index.js +++ b/client/index.js @@ -23,6 +23,7 @@ module.exports = { frappe.desk.menu.addItem('Items', '#list/Item'); frappe.desk.menu.addItem('Customers', '#list/Customer'); frappe.desk.menu.addItem('Invoice', '#list/Invoice'); + frappe.desk.menu.addItem('Journal Entry', '#list/JournalEntry'); frappe.desk.menu.addItem('Address', "#list/Address"); frappe.desk.menu.addItem('Contact', "#list/Contact"); frappe.desk.menu.addItem('Settings', () => frappe.desk.showFormModal('SystemSettings')); diff --git a/models/doctype/Address/Address.js b/models/doctype/Address/Address.js index 071e4aef..b6191f8c 100644 --- a/models/doctype/Address/Address.js +++ b/models/doctype/Address/Address.js @@ -104,7 +104,6 @@ module.exports = { return ['addressTitle', 'addressType']; }, getRowHTML(list, data) { - console.log(list, data); return `
${list.getNameHTML(data)} (${data.addressType})
`; } }, diff --git a/models/doctype/JournalEntry/JournalEntry.js b/models/doctype/JournalEntry/JournalEntry.js new file mode 100644 index 00000000..a6ff5931 --- /dev/null +++ b/models/doctype/JournalEntry/JournalEntry.js @@ -0,0 +1,83 @@ +const frappe = require('frappejs'); +const utils = require('../../../accounting/utils'); + +module.exports = { + name: "JournalEntry", + doctype: "DocType", + isSingle: 0, + isChild: 0, + isSubmittable: 1, + keywordFields: ["name"], + showTitle: true, + settings: "JournalEntrySetting", + fields: [ + { + fieldname: "date", + label: "Date", + fieldtype: "Date" + }, + { + fieldname: "entryType", + label: "Entry Type", + fieldtype: "Select", + options: [ + "Journal Entry", + "Bank Entry", + "Cash Entry", + "Credit Card Entry", + "Debit Note", + "Credit Note", + "Contra Entry", + "Excise Entry", + "Write Off Entry", + "Opening Entry", + "Depreciation Entry" + ], + required: 1 + }, + { + fieldname: "accounts", + label: "Account Entries", + fieldtype: "Table", + childtype: "JournalEntryAccount", + required: true + }, + { + fieldname: "referenceNumber", + label: "Reference Number", + fieldtype: "Data", + }, + { + fieldname: "referenceDate", + label: "Reference Date", + fieldtype: "Date", + }, + { + fieldname: "userRemark", + label: "User Remark", + fieldtype: "Text", + } + ], + layout: [ + // section 1 + { + columns: [ + { fields: [ "date" ] }, + { fields: [ "entryType" ] }, + ] + + }, + // section 2 + { fields: ["accounts"]}, + // section 3 + { + columns: [ + { fields: [ "referenceNumber"] }, + { fields: [ "referenceDate"] } + + ] + }, + // section 4 + { fields: [ "userRemark" ] }, + ] +} \ No newline at end of file diff --git a/models/doctype/JournalEntry/JournalEntryServer.js b/models/doctype/JournalEntry/JournalEntryServer.js new file mode 100644 index 00000000..8680dfdd --- /dev/null +++ b/models/doctype/JournalEntry/JournalEntryServer.js @@ -0,0 +1,29 @@ +const BaseDocument = require('frappejs/model/document'); +const frappe = require('frappejs'); +const LedgerPosting = require.main.require('./accounting/ledgerPosting'); + +module.exports = class PaymentServer extends BaseDocument { + /** + + getPosting() { + let entries = new LedgerPosting({reference: this, party: this.party}); + entries.debit(this.paymentAccount, this.amount); + + for (let row of this.for) { + entries.credit(this.account, row.amount, row.referenceType, row.referenceName); + } + + return entries; + + } + + async afterSubmit() { + await this.getPosting().post(); + } + + async afterRevert() { + await this.getPosting().postReverse(); + } + + **/ +} \ No newline at end of file diff --git a/models/doctype/JournalEntryAccount/JournalEntryAccount.js b/models/doctype/JournalEntryAccount/JournalEntryAccount.js new file mode 100644 index 00000000..4419ebe6 --- /dev/null +++ b/models/doctype/JournalEntryAccount/JournalEntryAccount.js @@ -0,0 +1,27 @@ +module.exports = { + name: "JournalEntryAccount", + doctype: "DocType", + isSingle: 0, + isChild: 1, + keywordFields: [], + layout: 'ratio', + fields: [ + { + "fieldname": "account", + "label": "Account", + "fieldtype": "Link", + "target": "Account", + "required": 1, + }, + { + "fieldname": "debit", + "label": "Debit", + "fieldtype": "Currency" + }, + { + "fieldname": "credit", + "label": "Credit", + "fieldtype": "Currency" + } + ] +} \ No newline at end of file diff --git a/models/doctype/JournalEntrySetting/JournalEntrySetting.js b/models/doctype/JournalEntrySetting/JournalEntrySetting.js new file mode 100644 index 00000000..14d77872 --- /dev/null +++ b/models/doctype/JournalEntrySetting/JournalEntrySetting.js @@ -0,0 +1,18 @@ +module.exports = { + "name": "JournalEntrySetting", + "label": "Journal Entry Setting", + "doctype": "DocType", + "isSingle": 1, + "isChild": 0, + "keywordFields": [], + "fields": [ + { + "fieldname": "numberSeries", + "label": "Number Series", + "fieldtype": "Link", + "target": "NumberSeries", + "required": 1, + "default": "JV" + } + ] +} \ No newline at end of file diff --git a/models/index.js b/models/index.js index 148d2f5e..056261fb 100644 --- a/models/index.js +++ b/models/index.js @@ -17,7 +17,13 @@ module.exports = { Tax: require('./doctype/Tax/Tax.js'), TaxDetail: require('./doctype/TaxDetail/TaxDetail.js'), TaxSummary: require('./doctype/TaxSummary/TaxSummary.js'), + Address: require('./doctype/Address/Address.js'), - Contact: require('./doctype/Contact/Contact.js') + Contact: require('./doctype/Contact/Contact.js'), + + JournalEntry: require('./doctype/JournalEntry/JournalEntry.js'), + JournalEntryAccount: require('./doctype/JournalEntryAccount/JournalEntryAccount.js'), + JournalEntrySetting: require('./doctype/JournalEntrySetting/JournalEntrySetting.js'), + } } diff --git a/server/index.js b/server/index.js index 2c139b2b..7138b10f 100644 --- a/server/index.js +++ b/server/index.js @@ -15,6 +15,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.metaCache = {}; @@ -23,6 +24,7 @@ module.exports = { // init naming series if missing await naming.createNumberSeries('INV-', 'InvoiceSetting'); await naming.createNumberSeries('PAY-', 'PaymentSetting'); + await naming.createNumberSeries('JV-', 'JournalEntrySetting'); frappe.registerMethod({ method: 'general-ledger',