2
0
mirror of https://github.com/frappe/books.git synced 2024-11-13 00:46:28 +00:00

[start] reports

This commit is contained in:
Rushabh Mehta 2018-03-26 17:44:27 +05:30
parent edb0924375
commit b5e3188608
18 changed files with 685 additions and 240 deletions

View File

@ -1,2 +1,2 @@
server: nodemon server.js server: nodemon start.js
watch: node_modules/.bin/rollup -c --watch watch: node_modules/.bin/rollup -c --watch

37
client/index.js Normal file
View File

@ -0,0 +1,37 @@
const GeneralLedgerView = require('../reports/GeneralLedgerView');
const frappe = require('frappejs');
module.exports = {
start() {
// require modules
frappe.registerModels(require('../models'), 'client');
frappe.registerView('List', 'ToDo', require('frappejs/models/doctype/ToDo/ToDoList.js'));
frappe.registerView('Form', 'FilterSelector', require('frappejs/models/doctype/FilterSelector/FilterSelectorForm.js'));
frappe.registerView('List', 'Account', require('../models/doctype/Account/AccountList.js'));
frappe.registerView('Form', 'Account', require('../models/doctype/Account/AccountForm.js'));
frappe.registerView('List', 'Invoice', require('../models/doctype/Invoice/InvoiceList.js'));
frappe.registerView('List', 'Customer', require('../models/doctype/Party/CustomerList.js'));
frappe.router.add('report/general-ledger', async (params) => {
if (!frappe.views.generalLedger) {
frappe.views.generalLedger = new GeneralLedgerView();
}
await frappe.views.generalLedger.show(params);
})
frappe.desk.menu.addItem('ToDo', '#list/ToDo');
frappe.desk.menu.addItem('Accounts', '#list/Account');
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('Settings', () => frappe.desk.showFormModal('SystemSettings'));
frappe.router.default = '#list/ToDo';
frappe.router.show(window.location.hash);
}
}

View File

@ -32,5 +32,11 @@ module.exports = {
"Expense" "Expense"
] ]
} }
] ],
events: {
validate: (doc) => {
}
}
} }

View File

@ -8,7 +8,7 @@ module.exports = {
keywordFields: [ keywordFields: [
'account', 'account',
'party', 'party',
'reference_name' 'referenceName'
], ],
fields: [ fields: [
{ {

View File

@ -99,17 +99,21 @@ module.exports = {
{ fields: [ "terms" ] }, { fields: [ "terms" ] },
], ],
formEvents: { links: [
refresh: (form) => { {
if (!form.ledgerLink) { label: 'Ledger Entries',
form.ledgerLink = form.container.addLink('Ledger Entries', () => { condition: (form) => form.doc.submitted,
frappe.flags.filters = { action:(form) => {
reference_type: 'Invoice', return {
reference_name: form.doc.name route: ['table', 'AccountingLedgerEntry'],
params: {
filters: {
referenceType: 'Invoice',
referenceName: form.doc.name
}
} }
frappe.router.setRoute('table', 'AccountingLedgerEntry'); };
});
} }
} }
} ]
} }

View File

@ -23,5 +23,23 @@ module.exports = {
"label": "Supplier", "label": "Supplier",
"fieldtype": "Check" "fieldtype": "Check"
} }
],
links: [
{
label: 'Invoices',
condition: (form) => form.doc.customer,
action: (form) => {
return {
route: ['table', 'Invoice'],
params: {
filters: {
customer: form.doc.name,
}
}
};
}
}
] ]
} }

View File

@ -1,11 +1,11 @@
{ {
"name": "frappe-accounting", "name": "frappe-accounting",
"version": "1.0.0", "version": "1.0.0",
"main": "server.js", "main": "start.js",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "mocha tests", "test": "mocha tests",
"start": "nodemon server.js" "start": "nodemon start.js"
}, },
"dependencies": { "dependencies": {
"frappejs": "link:../frappejs" "frappejs": "link:../frappejs"

19
reports/GeneralLedger.js Normal file
View File

@ -0,0 +1,19 @@
const frappe = require('frappejs');
module.exports = class GeneralLedger {
async run(params) {
const filters = {};
if (params.account) filters.account = params.account;
if (params.party) filters.party = params.party;
if (params.from_date) filters.date = ('>=', params.from_date);
if (params.to_date) filters.date = ('<=', params.to_date);
let data = await frappe.db.getAll({
doctype: 'AccountingLedgerEntry',
fields: ['date', 'account', 'party', 'referenceType', 'referenceName', 'debit', 'credit'],
filters: filters
});
return data;
}
}

View File

@ -0,0 +1,28 @@
const ReportPage = require('frappejs/client/desk/reportpage');
const frappe = require('frappejs');
module.exports = class GeneralLedgerView extends ReportPage {
constructor() {
super({title: frappe._('General Ledger')});
this.addFilter({fieldtype: 'Link', target: 'Account', label: 'Account'});
this.addFilter({fieldtype: 'Link', target: 'Party', label: 'Party'});
this.addFilter({fieldtype: 'Date', label: 'From Date'});
this.addFilter({fieldtype: 'Date', label: 'To Date'});
this.url = '/api/report/general-ledger';
}
getColumns() {
return [
{label: 'Date', fieldtype: 'Date'},
{label: 'Account', fieldtype: 'Link'},
{label: 'Party', fieldtype: 'Link'},
{label: 'Description', fieldtype: 'Data'},
{label: 'Debit', fieldtype: 'Currency'},
{label: 'Credit', fieldtype: 'Currency'},
{label: 'Balance', fieldtype: 'Currency'}
]
}
}

View File

@ -1,15 +0,0 @@
const server = require('frappejs/server');
const frappe = require('frappejs');
server.start({
backend: 'sqlite',
connectionParams: {dbPath: 'test.db'},
static: './',
models: require('./models')
}).then(() => {
// set server-side modules
frappe.models.Invoice.documentClass = require('./models/doctype/Invoice/InvoiceServer.js');
frappe.metaCache = {};
frappe.syncDoc(require('./fixtures/invoicePrint'));
});

26
server/index.js Normal file
View File

@ -0,0 +1,26 @@
const server = require('frappejs/server');
const frappe = require('frappejs');
const GeneralLedger = require('../reports/GeneralLedger')
module.exports = {
async start() {
await server.start({
backend: 'sqlite',
connectionParams: {dbPath: 'test.db'},
staticPath: './www',
models: require('../models')
})
// set server-side modules
frappe.models.Invoice.documentClass = require('../models/doctype/Invoice/InvoiceServer.js');
frappe.metaCache = {};
frappe.syncDoc(require('../fixtures/invoicePrint'));
frappe.app.get('/api/report/general-ledger', frappe.asyncHandler(async function(request, response) {
const generalLedger = new GeneralLedger();
const data = await generalLedger.run(request.query);
response.json(data);
}));
}
}

View File

@ -1,33 +0,0 @@
const client = require('frappejs/client');
// start server
client.start({
columns: 3,
server: 'localhost:8000'
}).then(() => {
// require modules
frappe.registerModels(require('../models'), 'client');
frappe.registerView('List', 'ToDo', require('frappejs/models/doctype/ToDo/ToDoList.js'));
frappe.registerView('Form', 'FilterSelector', require('frappejs/models/doctype/FilterSelector/FilterSelectorForm.js'));
frappe.registerView('List', 'Account', require('../models/doctype/Account/AccountList.js'));
frappe.registerView('Form', 'Account', require('../models/doctype/Account/AccountForm.js'));
frappe.registerView('List', 'Invoice', require('../models/doctype/Invoice/InvoiceList.js'));
frappe.registerView('List', 'Customer', require('../models/doctype/Party/CustomerList.js'));
frappe.desk.menu.addItem('ToDo', '#list/ToDo');
frappe.desk.menu.addItem('Accounts', '#list/Account');
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('Settings', () => frappe.desk.showFormModal('SystemSettings'));
frappe.router.default = '#list/ToDo';
frappe.router.show(window.location.hash);
});
module.exports = false;

2
start.js Normal file
View File

@ -0,0 +1,2 @@
const server = require('./server');
server.start();

View File

@ -7380,8 +7380,6 @@ html {
padding-bottom: 0; } padding-bottom: 0; }
.page .page-links { .page .page-links {
padding: 1rem 2rem; } padding: 1rem 2rem; }
.page .page-links .page-link {
display: inline-block; }
.page .page-error { .page .page-error {
text-align: center; text-align: center;
padding: 200px 0px; } padding: 200px 0px; }
@ -7397,6 +7395,8 @@ html {
background-color: lightyellow; } background-color: lightyellow; }
.form-body .alert { .form-body .alert {
margin-top: 1rem; } margin-top: 1rem; }
.form-inline .form-group {
margin-right: 0.5rem; }
.list-search { .list-search {
padding: 1rem 2rem; } padding: 1rem 2rem; }
.list-body .list-row { .list-body .list-row {
@ -7436,6 +7436,8 @@ html {
.table-page-wrapper { .table-page-wrapper {
width: 100%; width: 100%;
padding: 1rem 2rem; } padding: 1rem 2rem; }
.filter-toolbar {
padding: 1rem 2rem; }
.table-wrapper { .table-wrapper {
margin-top: 2rem; margin-top: 2rem;
margin-bottom: 2rem; } margin-bottom: 2rem; }

File diff suppressed because it is too large Load Diff

12
www/index.js Normal file
View File

@ -0,0 +1,12 @@
const client = require('frappejs/client');
const appClient = require('../client');
// start server
client.start({
columns: 3,
server: 'localhost:8000'
}).then(() => {
appClient.start();
});
module.exports = false;