Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(actual) Resolvers for Finance: show available room for income an… #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,30 @@ export class WalloraAPI extends RESTDataSource {
headers: this.getHeaders(v1AccessToken, v2AccessToken),
});
}
/**
* Get planned amount for Income and Expense Categories
* @param v1AccessToken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove tokens from API doc comment

* @param v2AccessToken
* @param dates { startMonth: String, endMonth: String }
* @returns workItems for Income and Expense Categories
*/
async getPlannedWorkItems(v1AccessToken,v2AccessToken, month) {
console.log('Access Token1:', v1AccessToken);
console.log('Access Token2:', v2AccessToken);
return this.get(`stats/total-planned-amount-workitemwise?startmonth=202112&endmonth=202112`, null, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It takes hard coded dates. Please use startDate and endDate params instead

headers: this.getHeaders(v1AccessToken, v2AccessToken)
});
}
/**
* Get actual amount for Income and Expense Categories
* @param v1AccessToken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove token from docs

* @param v2AccessToken
* @param dates { startMonth: String, endMonth: String }
* @returns workItems for Income and Expense Categories
*/
async getActualsWorkItems(v1AccessToken,v2AccessToken) {
return this.get(`stats/total-actual-amount-workitemwise?startdate=20211201&enddate=20211231`, null, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It takes hard coded dates. Please use startDate and endDate params instead

headers: this.getHeaders(v1AccessToken, v2AccessToken)
});
}
}
37 changes: 25 additions & 12 deletions schema/finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ const typeDef = gql`
}

type incomeExpenseCategoriesWorkItems {
id: Int
id: String
order: Int
name: String
incomeOrExpense: String
currency: String
plannedTotal: Int
actualTotal: Int
balanceTotal: Float
}

type actualsWorkItems {
Expand Down Expand Up @@ -103,23 +104,35 @@ const financeResolvers = {
return dates;
},
incomeExpenseCategoriesWorkItems: async (root, { }, { v1AccessToken, v2AccessToken, dataSources }) => {
const workItems = await dataSources.walloraAPI.getWorkItems(
v1AccessToken,
v2AccessToken
)
const plannedWorkItmes = await dataSources.walloraAPI.getPlannedWorkItems(v1AccessToken, v2AccessToken);
const actualWorkItems = await dataSources.walloraAPI.getActualsWorkItems(v1AccessToken, v2AccessToken);
const massagedActualWorkItems = _.map(actualWorkItems, (actualWorkItem) => {
return {
id: actualWorkItem.workitemId,
totalActualAmount: actualWorkItem.totalActualAmount
}
});
// merge planned and actual work items
var indexed = _.indexBy(massagedActualWorkItems, 'id');
const workItems = _.map(plannedWorkItmes, function(obj) {
var master = indexed[obj.workitem.id];
return _.extend({}, master, obj);
});
const masaged = [];

workItems.map((item, index) => {
masaged.push({
id: index,
order: item.order,
name: item.name,
incomeOrExpense: item.incomeOrExpense,
id: item.workitem.id,
order: item.workitem.order,
name: item.workitem.name,
incomeOrExpense: item.workitem.incomeOrExpense,
currency: 'INR',
plannedTotal: 1000,
actualTotal: 1000
plannedTotal: item.totalPlannedAmount,
actualTotal: item.totalActualAmount,
balanceTotal: (item.totalPlannedAmount && item.totalActualAmount) ? ((item.totalActualAmount / item.totalPlannedAmount) * 100).toFixed(2) : 0
});
});
return masaged;
return _.sortBy(masaged, function(o) { return o.order; })
},
}
};
Expand Down