feat: Receivable and payable aging summary financial statement.

This commit is contained in:
Ahmed Bouhuolia
2020-06-11 22:05:34 +02:00
parent 55a4319827
commit 4d1dd14f8d
36 changed files with 1435 additions and 195 deletions

View File

@@ -27,11 +27,13 @@ describe('routes: `/accounting`', () => {
reference: 'ASC',
entries: [
{
index: 1,
credit: 0,
debit: 0,
account_id: account.id,
},
{
index: 2,
credit: 0,
debit: 0,
account_id: account.id,
@@ -56,11 +58,13 @@ describe('routes: `/accounting`', () => {
journal_number: '123',
entries: [
{
index: 1,
credit: 1000,
debit: 0,
account_id: account.id,
},
{
index: 2,
credit: 0,
debit: 500,
account_id: account.id,
@@ -88,11 +92,13 @@ describe('routes: `/accounting`', () => {
journal_number: manualJournal.journalNumber,
entries: [
{
index: 1,
credit: 1000,
debit: 0,
account_id: account.id,
},
{
index: 2,
credit: 0,
debit: 1000,
account_id: account.id,
@@ -117,11 +123,13 @@ describe('routes: `/accounting`', () => {
journal_number: '123',
entries: [
{
index: 1,
credit: 1000,
debit: 0,
account_id: 12,
},
{
index: 2,
credit: 0,
debit: 1000,
account_id: 12,
@@ -149,11 +157,13 @@ describe('routes: `/accounting`', () => {
journal_number: '1000',
entries: [
{
index: 1,
credit: null,
debit: 0,
account_id: account1.id,
},
{
index: 2,
credit: null,
debit: 0,
account_id: account2.id,
@@ -164,10 +174,88 @@ describe('routes: `/accounting`', () => {
expect(res.status).equals(400);
expect(res.body.errors).include.something.that.deep.equal({
type: 'CREDIT.DEBIT.SUMATION.SHOULD.NOT.EQUAL.ZERO',
code: 400,
});
});
it('Should validate the customers and vendors contact if were not found on the storage.', async () => {
const account1 = await tenantFactory.create('account');
const account2 = await tenantFactory.create('account');
const res = await request()
.post('/api/accounting/make-journal-entries')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send({
date: new Date().toISOString(),
journal_number: '1000',
entries: [
{
index: 1,
credit: null,
debit: 1000,
account_id: account1.id,
contact_type: 'customer',
contact_id: 100,
},
{
index: 2,
credit: 1000,
debit: 0,
account_id: account1.id,
contact_type: 'vendor',
contact_id: 300,
},
],
});
expect(res.body.errors).include.something.deep.equals({
type: 'CUSTOMERS.CONTACTS.NOT.FOUND', code: 500, ids: [100],
});
expect(res.body.errors).include.something.deep.equals({
type: 'VENDORS.CONTACTS.NOT.FOUND', code: 600, ids: [300],
})
});
it('Should customer contact_type with receivable accounts type.', async () => {
const account1 = await tenantFactory.create('account');
const account2 = await tenantFactory.create('account');
const customer = await tenantFactory.create('customer');
const res = await request()
.post('/api/accounting/make-journal-entries')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send({
date: new Date().toISOString(),
journal_number: '1000',
entries: [
{
index: 1,
credit: null,
debit: 1000,
account_id: account1.id,
contact_type: 'customer',
contact_id: 100,
},
{
index: 2,
credit: 1000,
debit: 0,
account_id: account1.id,
},
],
});
expect(res.status).equals(400);
expect(res.body.errors).include.something.deep.equals({
type: 'CUSTOMERS.ACCOUNTS.NOT.RECEIVABLE.TYPE',
code: 700,
indexes: [1]
});
});
it('Should store manual journal transaction to the storage.', async () => {
const account1 = await tenantFactory.create('account');
const account2 = await tenantFactory.create('account');
@@ -183,10 +271,12 @@ describe('routes: `/accounting`', () => {
description: 'Description here.',
entries: [
{
index: 1,
credit: 1000,
account_id: account1.id,
},
{
index: 2,
debit: 1000,
account_id: account2.id,
},
@@ -194,7 +284,6 @@ describe('routes: `/accounting`', () => {
});
const foundManualJournal = await ManualJournal.tenant().query();
expect(foundManualJournal.length).equals(1);
expect(foundManualJournal[0].reference).equals('2000');
@@ -221,11 +310,13 @@ describe('routes: `/accounting`', () => {
memo: 'Description here.',
entries: [
{
index: 1,
credit: 1000,
account_id: account1.id,
note: 'First note',
},
{
index: 2,
debit: 1000,
account_id: account2.id,
note: 'Second note',

View File

@@ -10,7 +10,7 @@ import {
} from '~/dbInit';
describe('routes: /accounts/', () => {
describe.only('routes: /accounts/', () => {
describe('POST `/accounts`', () => {
it('Should `name` be required.', async () => {
const res = await request()
@@ -190,7 +190,7 @@ describe('routes: /accounts/', () => {
});
});
it('Should response success with correct data form.', async () => {
it.only('Should response success with correct data form.', async () => {
const account = await tenantFactory.create('account');
const res = await request()
.post('/api/accounts')
@@ -204,6 +204,8 @@ describe('routes: /accounts/', () => {
code: '123',
});
console.log(res.body);
expect(res.status).equals(200);
});
});

View File

@@ -0,0 +1,234 @@
import {
request,
expect,
} from '~/testInit';
import Item from '@/models/Item';
import {
tenantWebsite,
tenantFactory,
loginRes
} from '~/dbInit';
describe('routes: `/financial_statements/receivable_aging_summary`', () => {
it('Should retrieve customers list.', async () => {
const customer1 = await tenantFactory.create('customer', { display_name: 'Ahmed' });
const customer2 = await tenantFactory.create('customer', { display_name: 'Mohamed' });
const res = await request()
.get('/api/financial_statements/receivable_aging_summary')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.send();
expect(res.status).equals(200);
expect(res.body.aging.customers).is.an('array');
expect(res.body.aging.customers.length).equals(2);
expect(res.body.aging.customers[0].customer_name).equals('Ahmed');
expect(res.body.aging.customers[1].customer_name).equals('Mohamed');
});
it('Should respon se the customers ids not found.', async () => {
const res = await request()
.get('/api/financial_statements/receivable_aging_summary')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.query({
customer_ids: [3213, 3322],
})
.send();
expect(res.status).equals(400);
expect(res.body.errors).include.something.deep.equals({
type: 'CUSTOMERS.IDS.NOT.FOUND', code: 300, ids: [3213, 3322]
})
});
it('Should retrieve aging report columns.', async () => {
const customer1 = await tenantFactory.create('customer', { display_name: 'Ahmed' });
const customer2 = await tenantFactory.create('customer', { display_name: 'Mohamed' });
const res = await request()
.get('/api/financial_statements/receivable_aging_summary')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.query({
as_date: '2020-06-01',
aging_days_before: 30,
aging_periods: 6,
})
.send();
expect(res.body.columns).length(6);
expect(res.body.columns[0].before_days).equals(0);
expect(res.body.columns[0].to_days).equals(30);
expect(res.body.columns[1].before_days).equals(31);
expect(res.body.columns[1].to_days).equals(60);
expect(res.body.columns[2].before_days).equals(61);
expect(res.body.columns[2].to_days).equals(90);
expect(res.body.columns[3].before_days).equals(91);
expect(res.body.columns[3].to_days).equals(120);
expect(res.body.columns[4].before_days).equals(121);
expect(res.body.columns[4].to_days).equals(150);
expect(res.body.columns[5].before_days).equals(151);
expect(res.body.columns[5].to_days).equals(null);
});
it('Should retrieve receivable total of the customers.', async () => {
const customer1 = await tenantFactory.create('customer', { display_name: 'Ahmed' });
const customer2 = await tenantFactory.create('customer', { display_name: 'Mohamed' });
await tenantFactory.create('account_transaction', {
contact_id: customer1.id,
contact_type: 'customer',
debit: 10000,
credit: 0,
account_id: 10,
date: '2020-01-01',
});
await tenantFactory.create('account_transaction', {
contact_id: customer1.id,
contact_type: 'customer',
debit: 1000,
credit: 0,
account_id: 10,
date: '2020-03-15',
});
// Receive
await tenantFactory.create('account_transaction', {
contact_id: customer1.id,
contact_type: 'customer',
debit: 0,
credit: 8000,
account_id: 10,
date: '2020-06-01',
});
const res = await request()
.get('/api/financial_statements/receivable_aging_summary')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.query({
as_date: '2020-06-01',
aging_days_before: 30,
aging_periods: 6,
})
.send();
expect(res.body.aging.total[0].total).equals(0);
expect(res.body.aging.total[1].total).equals(0);
expect(res.body.aging.total[2].total).equals(1000);
expect(res.body.aging.total[3].total).equals(0);
expect(res.body.aging.total[4].total).equals(0);
expect(res.body.aging.total[5].total).equals(2000);
});
it('Should retrieve customer aging.', async () => {
const customer1 = await tenantFactory.create('customer', { display_name: 'Ahmed' });
const customer2 = await tenantFactory.create('customer', { display_name: 'Mohamed' });
await tenantFactory.create('account_transaction', {
contact_id: customer1.id,
contact_type: 'customer',
debit: 10000,
credit: 0,
account_id: 10,
date: '2020-01-14',
});
await tenantFactory.create('account_transaction', {
contact_id: customer1.id,
contact_type: 'customer',
debit: 1000,
credit: 0,
account_id: 10,
date: '2020-03-15',
});
// Receive
await tenantFactory.create('account_transaction', {
contact_id: customer1.id,
contact_type: 'customer',
debit: 0,
credit: 8000,
account_id: 10,
date: '2020-06-01',
});
const res = await request()
.get('/api/financial_statements/receivable_aging_summary')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.query({
as_date: '2020-06-01',
aging_days_before: 30,
aging_periods: 6,
})
.send();
expect(res.body.aging.customers[0].aging[0].total).equals(0);
expect(res.body.aging.customers[0].aging[1].total).equals(0);
expect(res.body.aging.customers[0].aging[2].total).equals(1000);
expect(res.body.aging.customers[0].aging[3].total).equals(0);
expect(res.body.aging.customers[0].aging[4].total).equals(2000);
expect(res.body.aging.customers[0].aging[5].total).equals(0);
});
it('Should retrieve the queried customers ids only.', async () => {
const customer1 = await tenantFactory.create('customer', { display_name: 'Ahmed' });
const customer2 = await tenantFactory.create('customer', { display_name: 'Mohamed' });
await tenantFactory.create('account_transaction', {
contact_id: customer1.id,
contact_type: 'customer',
debit: 10000,
credit: 0,
account_id: 10,
date: '2020-01-14',
});
await tenantFactory.create('account_transaction', {
contact_id: customer1.id,
contact_type: 'customer',
debit: 1000,
credit: 0,
account_id: 10,
date: '2020-03-15',
});
// Receive
await tenantFactory.create('account_transaction', {
contact_id: customer1.id,
contact_type: 'customer',
debit: 0,
credit: 8000,
account_id: 10,
date: '2020-06-01',
});
const res = await request()
.get('/api/financial_statements/receivable_aging_summary')
.set('x-access-token', loginRes.body.token)
.set('organization-id', tenantWebsite.organizationId)
.query({
as_date: '2020-06-01',
aging_days_before: 30,
aging_periods: 6,
customer_ids: [customer1.id],
})
.send();
expect(res.body.aging.customers.length).equals(1);
})
});

View File

@@ -10,7 +10,7 @@ import {
} from '~/dbInit';
import Vendor from '@/models/Vendor';
describe.only('route: `/vendors`', () => {
describe('route: `/vendors`', () => {
describe('POST: `/vendors`', () => {
it('Should response unauthorized in case the user was not logged in.', async () => {
const res = await request()