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

Added pie chart and column graph #81

Open
wants to merge 2 commits into
base: dev
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
216 changes: 210 additions & 6 deletions controller/dashboardController.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/* eslint-disable import/no-dynamic-require */
const { ipcMain } = require('electron');
const isDev = require('electron-is-dev');
const path = require('path');
const moment = require('moment');
const sequelize = require('sequelize');
const { Op } = require('sequelize');

const response = isDev
? require('../config/responseConfig')
: require(`${path.join(__dirname, '', '../config/responseConfig')}`);
const { inventoryOut, items, vendor } = isDev
const { inventoryOut, items, inventoryIn, supplier } = isDev
? require('../models')
: require(`${path.join(__dirname, '', '../models')}`);

ipcMain.on('report-items-fetch-message', async (event, arg) => {
ipcMain.on('report-items-fetch-message', async (event) => {
try {
const utility = {
options: {
Expand All @@ -24,7 +23,7 @@ ipcMain.on('report-items-fetch-message', async (event, arg) => {
},
],
raw: true,
order: [['updatedAt', 'DESC']],
order: [['updatedAt', 'ASC']],
nest: true,
},
lastWeek: {
Expand All @@ -51,7 +50,7 @@ ipcMain.on('report-items-fetch-message', async (event, arg) => {
// [Op.lte]: moment().subtract(0, 'days').toDate(),
// },
// },
order: [[sequelize.literal('month_year'), 'DESC']],
// order: [[sequelize.literal('month_year'), 'DESC']],
},
};
const mostOutItems = await inventoryOut.findAll({
Expand All @@ -73,3 +72,208 @@ ipcMain.on('report-items-fetch-message', async (event, arg) => {
event.reply('report-items-fetch-reply', response.error(error.message));
}
});
ipcMain.on('report-inventory-in-out-fetch-message', async (event) => {
try {
const outUtility = {
options: {
raw: true,
// order: [['updatedAt', 'DESC']],
nest: true,
},
lastWeek: {
attributes: [
'id',
[sequelize.literal("'Inventory Out'"), 'name'],
[
sequelize.literal('strftime("%d-%m-%Y", inventoryOut.createdAt)'),
'month_year',
],
[sequelize.literal('SUM(quantity*rate)'), 'totalCount'],
],
group: [
sequelize.fn(
'strftime',
'%d-%m-%Y',
sequelize.col('inventoryOut.createdAt'),
// 'createdAt',
),
],
},
};
const inUtility = {
options: {
raw: true,
// order: [['updatedAt', 'DESC']],
nest: true,
},
lastWeek: {
attributes: [
'id',
[sequelize.literal("'Inventory In'"), 'name'],
[
sequelize.literal('strftime("%d-%m-%Y", inventoryIn.createdAt)'),
'month_year',
],
[sequelize.literal('SUM(quantity*rate)'), 'totalCount'],
],
group: [
sequelize.fn(
'strftime',
'%d-%m-%Y',
sequelize.col('inventoryIn.createdAt'),
// 'createdAt',
),
],
},
};
const outItems = await inventoryOut.findAll({
...outUtility.options,
...outUtility.lastWeek,
});
const inItems = await inventoryIn.findAll({
...inUtility.options,
...inUtility.lastWeek,
});
const data = outItems.concat(inItems);
event.reply(
'report-inventory-in-out-fetch-reply',
response.success('Items Found successfully', {
data,
}),
);
} catch (error) {
event.reply(
'report-inventory-in-out-fetch-reply',
response.error(error.message),
);
}
});
ipcMain.on('report-all-suppliers', async (event) => {
try {
const utility = {
options: {
raw: true,
order: [['updatedAt', 'DESC']],
nest: true,
include: [inventoryIn],
},
lastWeek: {
attributes: [
'id',
'name',
[
sequelize.literal('SUM(inventoryIns.quantity*inventoryIns.rate)'),
'totalCount',
],
],
group: ['supplier.id'],
},
};
const suppliers = await supplier.findAll({
...utility.options,
...utility.lastWeek,
});
event.reply(
'report-all-suppliers-reply',
response.success('Items Found successfully', {
data: suppliers,
}),
);
} catch (error) {
event.reply('report-all-suppliers-reply', response.error(error.message));
}
});
ipcMain.on('report-item-comparison', async (event, arg) => {
try {
const utility = {
options: {
raw: true,
order: [['updatedAt', 'DESC']],
nest: true,
include: [inventoryIn, inventoryOut],
},
lastWeek: {
attributes: [
'id',
['productName', 'name'],
[
sequelize.literal('SUM(inventoryOuts.quantity*inventoryOuts.rate)'),
'earn',
],
[
sequelize.literal('SUM(inventoryIns.quantity*inventoryIns.rate)'),
'invest',
],
[sequelize.literal('COUNT(inventoryIns.quantity)'), 'iteration'],
[sequelize.literal('SUM(inventoryOuts.quantity)'), 'sales'],
],
group: ['items.id'],
},
};
const data = await items.findAll({
where: {
id: arg.id,
},
...utility.options,
...utility.lastWeek,
});
const comparisonChart = {
options: {
// limit: 4,
include: [
{
model: items,
attributes: ['productName'],
where: {
id: arg.id,
},
},
],
raw: true,
order: [['updatedAt', 'ASC']],
nest: true,
},
lastWeek: {
attributes: [
'id',
[
sequelize.literal('strftime("%d-%m-%Y", inventoryOut.createdAt)'),
'month_year',
],
[sequelize.literal('SUM(quantity*rate)'), 'totalOutEarns'],
],
group: [
sequelize.fn(
'strftime',
'%d-%m-%Y',
sequelize.col('inventoryOut.createdAt'),
// 'createdAt',
),
'item.id',
],
// where: {
// createdAt: {
// [Op.gte]: moment().subtract(7, 'days').toDate(),
// [Op.lte]: moment().subtract(0, 'days').toDate(),
// },
// },
// order: [[sequelize.literal('month_year'), 'DESC']],
},
};
const graphItem = await inventoryOut.findAll({
...comparisonChart.options,
...comparisonChart.lastWeek,
});
event.reply(
'report-item-comparison-reply',
response.success('Items Found successfully', {
data: {
totalPlate: data,
data: graphItem,
},
}),
);
} catch (error) {
event.reply('report-item-comparison-reply', response.error(error.message));
}
});
100 changes: 24 additions & 76 deletions src/common/components/dashboard/ColumnGraph.jsx
Original file line number Diff line number Diff line change
@@ -1,85 +1,27 @@
/* eslint-disable react/jsx-props-no-spreading */
import React from 'react';
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Column } from '@ant-design/charts';
import { Spin } from 'antd';
import Paragraph from 'antd/lib/typography/Paragraph';
import { getColumnGraph } from '../../../components/Dashboard/reducer';

const ColumnGraph = () => {
const data = [
{
name: 'Inventory In',
date: 'Jan',
value: 100,
},
{
name: 'Inventory Out',
date: 'Jan',
value: 50,
},
{
name: 'Inventory In',
date: 'Feb',
value: 100,
},
{
name: 'Inventory Out',
date: 'Feb',
value: 10,
},
{
name: 'Inventory In',
date: 'Mar',
value: 10,
},
{
name: 'Inventory Out',
date: 'Mar',
value: 50,
},
{
name: 'Inventory In',
date: 'Apr',
value: 100,
},
{
name: 'Inventory Out',
date: 'Apr',
value: 50,
},
{
name: 'Inventory In',
date: 'May',
value: 40,
},
{
name: 'Inventory Out',
date: 'May',
value: 100,
},
{
name: 'Inventory In',
date: 'Jun',
value: 100,
},
{
name: 'Inventory Out',
date: 'Jun',
value: 50,
},
{
name: 'Inventory In',
date: 'July',
value: 17,
},
{
name: 'Inventory Out',
date: 'July',
value: 50,
},
];
const {
isLoading,
isError,
data: items,
} = useSelector((state) => state.DashboardReducer.columnGraph);
const dispatch = useDispatch();

useEffect(() => {
dispatch(getColumnGraph());
}, []);
const config = {
data,
data: items,
isGroup: true,
xField: 'date',
yField: 'value',
xField: 'month_year',
yField: 'totalCount',
seriesField: 'name',
label: {
position: 'middle',
Expand All @@ -90,6 +32,12 @@ const ColumnGraph = () => {
],
},
};
if (isLoading) {
return <Spin />;
}
if (isError) {
return <Paragraph>Some error occured while loading the graph</Paragraph>;
}
return <Column {...config} />;
};

Expand Down
Loading