itemsmaster

This commit is contained in:
sriramv 2022-04-05 09:48:02 +05:30
parent a515f42e5a
commit e1c7e6284f
5 changed files with 53 additions and 41 deletions

View File

@ -123,7 +123,7 @@ exports.MenuList = async (req, res) => {
.then(Entityfinyearsdata => {
// create skeletion with itemmaster data (itemmaster(id) == financial(itemid))
Itemsmaster.findAll({ where :{is_active : 1},attributes: ['id'] , order: [['id', 'ASC']] })
Itemsmaster.findAll({ where :{pvtltd:1,is_active : 1},attributes: ['id'] , order: [['statement', 'ASC'],['section', 'ASC'],['pvtltd_itemorder', 'ASC']] })
.then(ItemsmasterData => {
//construct lineitem array for bulk insert using itemmaster primarykey (id)
var SkeletonInsert = new Promise((resolve, reject) => {
@ -279,6 +279,7 @@ Entities.findOne({where : { id } , attributes: [ 'id','losid','process_instance_
.then(EntitiesData => {
const instancesid = EntitiesData.dataValues.process_instance_id;
const probe42_data_status = EntitiesData.dataValues.probe42_data_status;
if(probe42_data_status == 0){order_by_key = "pvtltd_itemorder"}else if(probe42_data_status == 2){order_by_key = "itemorder"}else{order_by_key = "NULL"}
sequelize.query("select a.losid,a.entityid,a.FY,a.st_type as st_type_id, b.statement_name as st_type_name,a.additional_year_type, a.probe42_data_status FROM entity_fin_year a LEFT JOIN (SELECT id,statement_name FROM statement_type) b ON a.st_type = b.id WHERE entityid ="+id+" order by a.fy desc")
.then(EntityfinyearData => {
if(EntityfinyearData[0].length != 0)
@ -287,7 +288,7 @@ sequelize.query("select a.losid,a.entityid,a.FY,a.st_type as st_type_id, b.state
const year_1 = EntityfinyearData[0][0].FY;
const additional_year_type = EntityfinyearData[0][0].additional_year_type;
if(EntitiesData.dataValues.entity_type == "COMPANY"){entity_type_key = "pvtltd"} else if(EntitiesData.dataValues.entity_type == "INDIVIDUAL"){entity_type_key = "llp"} else {entity_type_key = "others"}
const years = {losid:EntitiesData.dataValues.losid,entityid:EntitiesData.dataValues.id,entity_type_key:entity_type_key,probe42_data_status:probe42_data_status,additional_year_type:additional_year_type};
const years = {losid:EntitiesData.dataValues.losid,entityid:EntitiesData.dataValues.id,order_by_key:order_by_key,probe42_data_status:probe42_data_status,additional_year_type:additional_year_type};
formula_obj = {};
// below function call is for calculation of additional new year flag generation
add_new_FY_flag = financialControllerHelper.addNewFyFlag(year_1);
@ -309,12 +310,12 @@ sequelize.query("select a.losid,a.entityid,a.FY,a.st_type as st_type_id, b.state
{
key_addition = key + 1;
alisename = words[key_addition];
select_items += ","+alisename+".st_type as Y"+key_addition+"_st_type,"+alisename+".fy as Y"+key_addition+","+alisename+".id Y"+key_addition+"_id ,"+alisename+".is_editable as Y"+key_addition+"_is_editable ,"+alisename+".value Y"+key_addition+"_value";
sub_query += "LEFT JOIN ( SELECT id,entity_id, itemid, value,fy,is_active,st_type,is_editable FROM financials WHERE fy = '"+value.FY+"' and entity_id = "+id+" and is_active = 1) "+alisename+" ON a.entity_id = "+alisename+".entity_id and a.itemid = "+alisename+".itemid ";
select_items += ","+alisename+".st_type as Y"+key_addition+"_st_type,"+alisename+".fy as Y"+key_addition+","+alisename+".id Y"+key_addition+"_id ,"+alisename+".is_editable as Y"+key_addition+"_is_editable ,"+alisename+".value Y"+key_addition+"_value,"+alisename+".sub_value Y"+key_addition+"_sub_value";
sub_query += "LEFT JOIN ( SELECT id,entity_id, itemid, value,sub_value,fy,is_active,st_type,is_editable FROM financials WHERE fy = '"+value.FY+"' and entity_id = "+id+" and is_active = 1) "+alisename+" ON a.entity_id = "+alisename+".entity_id and a.itemid = "+alisename+".itemid ";
}
}); // end of foreach
var query = "Select a.entity_id,x.id as statement_id,x.statement as statement,y.id as section_id,y.section as section,w.subsection as subsection_id,z.subsection as subsection , z.itemtext as subsection_itemtext ,a.itemid,w.itemtext as items,w.formula,w.is_calculated,w.is_summary,w.pvtltd,w.llp,w.others,a.st_type as Y1_st_type,a.fy as Y1,a.id as Y1_id ,a.is_editable as Y1_is_editable,a.value as Y1_value "+ select_items +",v.remarks , v.id as remarks_id FROM financials a LEFT JOIN ( SELECT id,entity_id,itemid,remarks FROM fin_remarks WHERE is_active = 1) v ON a.entity_id = v.entity_id and a.itemid = v.itemid JOIN ( SELECT id,itemtext,statement,section,subsection,formula,is_calculated,is_summary,pvtltd,llp,others FROM new_itemsmaster ) w ON a.itemid = w.id JOIN ( SELECT id, statement FROM statementsmaster ) x ON w.statement = x.id JOIN ( SELECT id, section FROM sectionsmaster ) y ON w.section = y.id LEFT JOIN ( SELECT id, subsection , itemtext FROM subsectionsmaster ) z ON w.subsection = z.id "+ sub_query +"WHERE a.fy = '"+year_1+"' and a.entity_id = "+id+" and a.is_active = 1 order by w.statement asc , w.section asc , w.subsection , w.id asc";
var query = "Select a.entity_id,x.id as statement_id,x.statement as statement,y.id as section_id,y.section as section,w.subsection as subsection_id,w.itemkey,w.itemorder,w.pvtltd_itemorder,z.subsection as subsection , z.itemtext as subsection_itemtext ,a.itemid,w.itemtext as items,w.formula,w.is_calculated,w.is_summary,w.pvtltd,w.llp,w.others,a.st_type as Y1_st_type,a.fy as Y1,a.id as Y1_id ,a.is_editable as Y1_is_editable,a.value as Y1_value,a.sub_value as Y1_sub_value "+ select_items +",v.remarks , v.id as remarks_id FROM financials a LEFT JOIN ( SELECT id,entity_id,itemid,remarks FROM fin_remarks WHERE is_active = 1) v ON a.entity_id = v.entity_id and a.itemid = v.itemid JOIN ( SELECT id,itemtext,statement,section,subsection,itemkey,itemorder,pvtltd_itemorder,formula,is_calculated,is_summary,pvtltd,llp,others FROM itemsmaster ) w ON a.itemid = w.id JOIN ( SELECT id, statement FROM statementsmaster ) x ON w.statement = x.id JOIN ( SELECT id, section FROM sectionsmaster ) y ON w.section = y.id LEFT JOIN ( SELECT id, subsection , itemtext FROM subsectionsmaster ) z ON w.subsection = z.id "+ sub_query +"WHERE a.fy = '"+year_1+"' and a.entity_id = "+id+" and a.is_active = 1 order by w.statement asc , w.section asc , w.subsection ";
setTimeout(function(){
sequelize.query(query).then(summary => { console.log(query)
// is_summary filter from fin_summary data
@ -392,7 +393,7 @@ exports.ConsolidatedSummary = async (req, res) => {
}
}); // end of foreach
var query = "Select x.id as statement_id,x.statement as statement,y.id as section_id,y.section as section,e.subsection as subsection_id,g.subsection as subsection , g.itemtext as subsection_itemtext, a.itemid,e.itemtext as items,e.is_summary,a.fy as Y1 , SUM(a.value) as Y1_value"+ select_items +" from entities z JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+year_1+"'and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) a ON z.id = a.entity_id" + sub_query + " JOIN ( SELECT id,itemtext,statement,section,subsection,formula,is_calculated,is_summary FROM itemsmaster ) e ON a.itemid = e.id JOIN ( SELECT id, statement FROM statementsmaster ) x ON e.statement = x.id JOIN ( SELECT id, section FROM sectionsmaster ) y ON e.section = y.id LEFT JOIN ( SELECT id, subsection , itemtext FROM subsectionsmaster ) g ON e.subsection = g.id where losid = '"+losid+"' GROUP BY a.itemid,x.id,x.statement,y.id,y.section,e.subsection,g.subsection,g.itemtext,e.itemtext,e.statement,e.section,e.id,a.fy,e.is_summary " + group + " ORDER BY e.statement asc , e.section asc , e.id asc"
var query = "Select x.id as statement_id,x.statement as statement,y.id as section_id,y.section as section,e.subsection as subsection_id,g.subsection as subsection , g.itemtext as subsection_itemtext, a.itemid,e.itemtext as items,e.is_summary,e.itemorder,e.pvtltd_itemorder,a.fy as Y1 , SUM(a.value) as Y1_value"+ select_items +" from entities z JOIN(SELECT entity_id,itemid,fy,value FROM financials WHERE fy = '"+year_1+"'and is_active = 1 GROUP BY itemid,fy,is_active,value,entity_id) a ON z.id = a.entity_id" + sub_query + " JOIN ( SELECT id,itemtext,statement,section,subsection,formula,is_calculated,is_summary,itemorder,pvtltd_itemorder FROM itemsmaster ) e ON a.itemid = e.id JOIN ( SELECT id, statement FROM statementsmaster ) x ON e.statement = x.id JOIN ( SELECT id, section FROM sectionsmaster ) y ON e.section = y.id LEFT JOIN ( SELECT id, subsection , itemtext FROM subsectionsmaster ) g ON e.subsection = g.id where losid = '"+losid+"' GROUP BY a.itemid,x.id,x.statement,y.id,y.section,e.subsection,g.subsection,g.itemtext,e.itemtext,e.statement,e.section,e.id,a.fy,e.is_summary " + group + " ORDER BY e.statement asc , e.section asc asc"
setTimeout(function(){
sequelize.query(query)
@ -793,10 +794,39 @@ exports.checkProbeStatus = (req, res) => {
exports.test = async (req, res) => {
try
{
// const str = 'a v:ery (long) string';
// console.log(str)
// var remove_spl_char = str.replace(/[^a-zA-Z ]/g, "")
// console.log(remove_spl_char)
// var strUnderscores = remove_spl_char.replace(/\s+/g, '_');
// console.log(strUnderscores)
// TempItemMaster.findAll({raw : true ,where :{statement:3 , section:17} , attributes: [ 'id' , 'itemtext' ] })
// .then(async(ItemsmasterData) => {
// for( value of ItemsmasterData)
// {
// var txt = value.itemtext;
// var txt1 = txt.slice(0, 15)
// var txt2 = txt1.replace(/[^a-zA-Z ]/g, "");
// var txt3 = txt2.replace(/\s+/g, '_');
// var txt4 = "cf_cff_"+txt3;
// var txt5 = txt4.toLowerCase();
// console.log(txt5);
// await TempItemMaster.update({ itemkey : txt5 } , { where: { id: value.id }});
// }
// });
}catch(err) {
res.send({'status':404,message: err.message || "Some error occurred while inserting statements." ,'data': "No data"});
}
};
@ -804,32 +834,11 @@ exports.checkProbeStatus = (req, res) => {
try
{
// start_date = "'2019-08-12'";
// let starting_date = new Date(start_date);
// end_date = "'2021-05-12'";
// let date = new Date(end_date);
// years_skeleton = [];
// for(let i=0;i<12;i++)
// {
// //store on fly month number
// month_count = date.getMonth() + 1;
// //create on fly month data
// new_date = date.toLocaleString('default', { month: 'short' })+"-"+date.getFullYear();
// //create on fly period data
// new_period = date.getFullYear()+"-"+month_count+"-01";
// obj = {month:new_date,period:new_period};
// // push skeleton object
// years_skeleton.push(obj);
// //Reset date here
// date.setMonth(date.getMonth() - 1);
// //check if loop meets starting date or not
// if(starting_date.getFullYear() == date.getFullYear() && starting_date.getMonth() + 1 == month_count) { break; }
// }
// console.log(years_skeleton);
key = "manual";
Itemsmaster.findAll({ where :{ key : 1,is_active : 1},attributes: ['id'] , order: [['statement', 'ASC'],['section', 'ASC']] })
.then(ItemsmasterData => {
res.send(ItemsmasterData);
});

View File

@ -23,7 +23,8 @@ module.exports = (sequelize, DataTypes) => {
itemid: { type: DataTypes.INTEGER },
is_editable: { type: DataTypes.INTEGER },
is_active: { type: DataTypes.INTEGER },
value: { type: DataTypes.INTEGER },
value: { type: DataTypes.INTEGER },
sub_value: { type: DataTypes.STRING },
createdby: { type: DataTypes.INTEGER },
updatedby: { type: DataTypes.INTEGER },

View File

@ -24,28 +24,30 @@ module.exports = (sequelize, DataTypes) => {
}
Itemsmaster.init(
{
{
statement: { type: DataTypes.INTEGER },
section: { type: DataTypes.INTEGER },
subsection: { type: DataTypes.INTEGER },
itemtext: { type: DataTypes.STRING },
itemorder: { type: DataTypes.INTEGER },
itemkey: { type: DataTypes.STRING },
pvtltditemkey: { type: DataTypes.STRING },
// pvtltd_is_calculated: { type: DataTypes.INTEGER },
// pvtltd_formula: { type: DataTypes.INTEGER },
is_active: { type: DataTypes.INTEGER },
pvtltd_itemorder: { type: DataTypes.INTEGER },
manual: { type: DataTypes.INTEGER },
pvtltd: { type: DataTypes.INTEGER },
llp: { type: DataTypes.INTEGER },
others: { type: DataTypes.INTEGER },
formula: { type: DataTypes.INTEGER },
formula: { type: DataTypes.STRING },
is_calculated: { type: DataTypes.INTEGER },
is_summary: { type: DataTypes.INTEGER },
is_active: { type: DataTypes.INTEGER },
createdby: { type: DataTypes.INTEGER },
updatedby: { type: DataTypes.INTEGER },
},
{
sequelize,
tableName: 'new_itemsmaster',
tableName: 'itemsmaster',
modelName: 'Itemsmaster',
createdAt: 'createdon',
updatedAt: 'updatedon',

View File

@ -7,7 +7,7 @@ module.exports = app => {
const { logMsg } = require('../services/logger.js');
var router = require("express").Router();
// router.get("/demo", financials.demo);
router.get("/test", financials.demo);
/**
* @swagger
* /api/checkProbeStatus:

View File

@ -34,7 +34,7 @@ function createSkeleton(losid,entityid)
{
// create skeletion with itemmaster data (itemmaster(id) == financial(itemid))
Itemsmaster.findAll({ where :{is_active : 1},attributes: ['id'] , order: [['id', 'ASC']] })
Itemsmaster.findAll({ where :{manual:1,is_active : 1},attributes: ['id'] , order: [['statement', 'ASC'],['section', 'ASC'],['itemorder', 'ASC']] })
.then(ItemsmasterData => {
var year = new Date().getFullYear();