dvrReportController.js 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706
  1. const db = require("../services/dbconnection");
  2. const validation = require("../controllers/validation")
  3. const moment = require("moment");
  4. const logger = require('../utils/logger');
  5. module.exports.createContactEntry = async (req, res) => {
  6. const validationResp = await validation.createContactentrycheck(req);
  7. const createdate = new Date();
  8. if (validationResp.status) {
  9. try {
  10. var stage_id;
  11. if (req.body.email_id == null || req.body.mobile_no == null) {
  12. //|| req.body.department == null || req.body.designation == null) {
  13. stage_id = 2;
  14. console.log(stage_id);
  15. } else {
  16. stage_id = 1;
  17. }
  18. const querycount = "select COUNT(*) as count from contact_master where first_name='" + req.body.first_name + "' and last_name='" + req.body.last_name + "' and mobile_number ='" + req.body.mobile_no + "'";
  19. console.log("querycount", querycount);
  20. const querycountresult = await db.executequery(querycount);
  21. console.log("querycountresult", querycountresult);
  22. console.log("querycountresult1", querycountresult[0].count);
  23. if (querycountresult[0].count > 0) {
  24. console.log("duplicate entry present");
  25. res.send({
  26. status: true,
  27. data: [{
  28. message: "",
  29. createStatus: "1",
  30. exception: {
  31. errorid: "400",
  32. errormessage: "Duplicate Entry: This contact alrady exists in the database."
  33. }
  34. }],
  35. error: ""
  36. })
  37. } else {
  38. console.log("new contact details")
  39. const query = "INSERT INTO contact_master(first_name,last_name,mobile_number,email_id,designation,department,function_area,created_by,created_on,customer_id,stage_id,mob_no)" +
  40. "VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
  41. const values = [req.body.first_name, req.body.last_name, req.body.mobile_no, req.body.email_id, req.body.designation, req.body.department, req.body.function, req.body.created_by, createdate, req.body.contact_for, stage_id, req.body.mob_no]
  42. const res1 = await db.executevaluesquery(query, values);
  43. logger.info('log to file', res);
  44. if (res1) {
  45. const query = "select contact_id,customer_id,first_name,last_name from contact_master order by contact_id desc limit 1";
  46. const queryresult = await db.executequery(query);
  47. console.log("queryresult", queryresult);
  48. res.send({
  49. status: true,
  50. data: [{
  51. message: "Contact Entry created Successfully ",
  52. createStatus: "0",
  53. lastinsertedData: queryresult[0].first_name + " " + queryresult[0].last_name,
  54. exception: {
  55. errorid: "",
  56. errormessage: "No Errors"
  57. }
  58. }],
  59. error: " "
  60. })
  61. } else {
  62. res.send({
  63. status: true,
  64. data: [{
  65. message: "",
  66. createStatus: "1",
  67. exception: {
  68. errorid: "404",
  69. errormessage: "Bad request"
  70. }
  71. }],
  72. error: ""
  73. })
  74. }
  75. }
  76. }
  77. catch (err) {
  78. console.log(err)
  79. res.send({
  80. status: true,
  81. data: [{
  82. message: "",
  83. createStatus: "1",
  84. exception: {
  85. errorid: "404",
  86. errormessage: "Bad request"
  87. }
  88. }],
  89. error: err
  90. })
  91. }
  92. } else {
  93. res.send(validationResp)
  94. }
  95. }
  96. module.exports.getdvrDetails = async (req, res) => {
  97. console.log("in dvr details for one id");
  98. const validationResp = await validation.getdvrDetailscheck(req);
  99. if (validationResp.status) {
  100. try {
  101. const query = "SELECT d.dvr_id,d.date_of_visit,d.customer_name,d.contact_name,d.physical_meeting,d.message,s.stage_desc,d.stage_id,d.created_on,d.nextstep,d.second_contact,d.objective,d.est_Date,d.estvalue,d.func,d.person FROM dvr_report d JOIN stage_master s ON d.stage_id=s.stage_id WHERE d.dvr_id = '" + req.query.dvrid + "' and d.delete_id = 0";
  102. console.log("query", query)
  103. const queryresult = await db.executequery(query);
  104. if (queryresult.length > 0) {
  105. res.send({
  106. status: true,
  107. data: [
  108. {
  109. getdvrDataStatus: '0',
  110. mesasge: "Data Found",
  111. visit_date: queryresult[0].date_of_visit,
  112. customer_name: queryresult[0].customer_name,
  113. contact_name: queryresult[0].contact_name,
  114. mesasge: queryresult[0].message,
  115. physical_metting: queryresult[0].physical_meeting,
  116. stage_desc: queryresult[0].stage_desc,
  117. stage_id: queryresult[0].stage_id,
  118. created_on: queryresult[0].created_on,
  119. nextstep: queryresult[0].nextstep,
  120. second_contact:queryresult[0].second_contact,
  121. objective:queryresult[0].objective,
  122. est_Date:queryresult[0].est_Date,
  123. deal:queryresult[0].estvalue,
  124. func:queryresult[0].func,
  125. person:queryresult[0].person
  126. }
  127. ],
  128. errors: ""
  129. })
  130. } else {
  131. res.send({
  132. status: false,
  133. data: [
  134. {
  135. getdvrDataStatus: '1',
  136. mesasge: "Data not Found"
  137. }
  138. ],
  139. errors: ""
  140. })
  141. }
  142. }
  143. catch (err) {
  144. console.log(err)
  145. res.send({
  146. status: true, data: []
  147. })
  148. }
  149. } else {
  150. res.send(validationResp)
  151. }
  152. }
  153. module.exports.getselectionData = async (req, res) => {
  154. try {
  155. var customerData = [];
  156. var contactData = [];
  157. var stageData = [];
  158. var personData = [];
  159. var funcDetails = [];
  160. const query = "SELECT customer_id,customer_name FROM customer_master";
  161. const queryresult = await db.executequery(query);
  162. if (queryresult.length > 0) {
  163. for (var i = 0; i < queryresult.length; i++) {
  164. customerData.push(queryresult[i])
  165. }
  166. }
  167. const query1 = "SELECT contact_id,first_name,last_name FROM contact_master order by first_name";
  168. const queryresult1 = await db.executequery(query1);
  169. if (queryresult1.length > 0) {
  170. for (var i = 0; i < queryresult1.length; i++) {
  171. contactData.push(queryresult1[i])
  172. }
  173. }
  174. const query2 = "SELECT stage_id,stage_desc FROM stage_master";
  175. const queryresult2 = await db.executequery(query2);
  176. if (queryresult2.length > 0) {
  177. for (var i = 0; i < queryresult2.length; i++) {
  178. stageData.push(queryresult2[i])
  179. }
  180. }
  181. const query3 = "SELECT person_id,person_name FROM person_details";
  182. const queryresult3 = await db.executequery(query3);
  183. if (queryresult3.length > 0) {
  184. for (var i = 0; i < queryresult3.length; i++) {
  185. personData.push(queryresult3[i])
  186. }
  187. }
  188. const query4 = "SELECT func_id,func_name FROM function_details";
  189. const queryresult4 = await db.executequery(query4);
  190. if (queryresult4.length > 0) {
  191. for (var i = 0; i < queryresult4.length; i++) {
  192. funcDetails.push(queryresult4[i])
  193. }
  194. }
  195. res.send({
  196. status: true,
  197. data: [{
  198. customerData: customerData
  199. }, {
  200. contactData: contactData
  201. }, {
  202. stageData: stageData
  203. },
  204. {
  205. personData:personData
  206. },
  207. {
  208. funcDetails: funcDetails
  209. }
  210. ],
  211. error: ""
  212. })
  213. }
  214. catch (err) {
  215. console.log(err)
  216. res.send({
  217. status: true, data: [], error: err
  218. })
  219. }
  220. }
  221. module.exports.getdashboarddetails = async (req, res) => {
  222. try {
  223. var login_id = req.query.login_id;
  224. var sale_person = req.query.salePerson;
  225. var customer = req.query.customer;
  226. var customer_id = req.query.customerid;
  227. var rol_des;
  228. var dvrlist = [];
  229. var rolData;
  230. var rolData1;
  231. var dates, firstdate, seconddate;
  232. var user_id_for_mapp;
  233. var emai_id;
  234. const findRole = "call SP_roleidentify1('" + login_id + "')";
  235. const roleidentify = await db.executequery(findRole);
  236. rolData = roleidentify[0];
  237. console.log("findRole", findRole);
  238. rolData.forEach(function (item) {
  239. console.log(item.role_des);
  240. rolData1 = item.role_des;
  241. user_id_for_mapp = item.user_id11;
  242. });
  243. //console.log("item",item);
  244. rol_des = rolData1;
  245. console.log("user_id_for_mapp", user_id_for_mapp)
  246. if (rol_des == 'admin') {
  247. //admin
  248. console.log("req.query.searchfiltertype", req.query.searchfiltertype);
  249. if (req.query.searchfiltertype) {
  250. if (req.query.searchfiltertype.length > 1) {
  251. //date seach filter
  252. console.log("in ifffffffffffffffffffffffffffff");
  253. var searchfilter = req.query.searchfiltertype;
  254. console.log("searchfilter", searchfilter);
  255. if (searchfilter == "undefineddate") {
  256. console.log("date not pass");
  257. firstdate = '';
  258. seconddate = '';
  259. } else {
  260. dates = searchfilter.split("-");
  261. console.log("dates", dates)
  262. firstdate = dates[0] + ' 00:00:00';
  263. seconddate = dates[1] + ' 23:59:59';
  264. }
  265. var querydvr;
  266. var countquery;
  267. console.log("firstdate", firstdate);
  268. console.log("seconddate", seconddate);
  269. console.log("ooooooooooooo", sale_person);
  270. if (sale_person != undefined && sale_person != 'undefined' && sale_person != 'all') {
  271. var data = sale_person.split(" ");
  272. console.log("data----->", data)
  273. console.log("need to find sale person email id for cound data");
  274. var query = "select user_id,login_id from user_master where first_name like '%" + data[0] + "%' and last_name like '%" + data[1] + "%'";
  275. const res_user = await db.executequery(query);
  276. console.log("res_user", res_user);
  277. console.log("res_user----------->", res_user[0].login_id)
  278. emai_id = res_user[0].login_id;
  279. }
  280. console.log("customer", customer, "customer_id", customer_id, " email_id-->", emai_id);
  281. if (sale_person != undefined && customer == undefined && searchfilter == 'undefineddate' && sale_person != 'all') {
  282. console.log("only for sale_person");
  283. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where sale_person like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  284. countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + '' + "','" + '' + "')";
  285. } else if (sale_person == undefined && customer != undefined && searchfilter == 'undefineddate' && sale_person != 'all' && customer != 'all') {
  286. console.log("only for customer");
  287. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where customer_name like '%" + customer + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  288. countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + customer + "','" + customer_id + "')";
  289. } else if (sale_person != undefined && customer != undefined && customer_id != undefined && sale_person != 'all') {
  290. console.log("for sales_person and Customer");
  291. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where customer_name like '%" + customer + "%' and sale_person like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  292. countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + customer + "','" + customer_id + "')";
  293. } else if (sale_person != 'all' && firstdate != undefined && seconddate != undefined && sale_person != undefined) {
  294. console.log("date and sale_person");
  295. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + firstdate + "' and '" + seconddate + "' and sale_person like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  296. countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + '' + "','" + '' + "')";
  297. } else if (customer != undefined && firstdate != undefined && seconddate != undefined && sale_person == undefined) {
  298. console.log("for date and customer");
  299. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + firstdate + "' and '" + seconddate + "' and customer_name like '%" + customer + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  300. countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + customer + "','" + customer_id + "')";
  301. } else if (customer != undefined && firstdate != undefined && seconddate != undefined && sale_person != undefined) {
  302. console.log("all filters");
  303. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + firstdate + "' and '" + seconddate + "' and customer_name like '%" + customer + "%' and sale_person like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  304. countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + customer + "','" + customer_id + "')";
  305. }
  306. else {
  307. console.log("only for date");
  308. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + firstdate + "' and '" + seconddate + "' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  309. countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + '' + "','" + '' + "')";
  310. }
  311. // if (sale_person == undefined && customer == undefined && searchfilter != "undefineddate" && sale_person == 'undefined') {
  312. // console.log("only for date")
  313. // querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person from dvr_report where date_of_visit between'" + firstdate + "' and '" + seconddate + "' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  314. // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + '' + "','" + '' + "')";
  315. // } else if (sale_person != undefined && searchfilter == "undefineddate" && customer == undefined && sale_person !='undefined') {
  316. // console.log("for sale_peron only")
  317. // querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person from dvr_report where sale_person like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  318. // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + '' + "','" + '' + "')";
  319. // }else if(customer != undefined && customer_id !=undefined && searchfilter == "undefineddate" && sale_person !=undefined && sale_person != 'undefined'){
  320. // console.log("for customer only");
  321. // querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person from dvr_report where customer_name like '%" + customer + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  322. // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + customer + "','" + customer_id + "')";
  323. // }else if(customer !=undefined && sale_person !='undefined' && sale_person !=undefined && searchfilter == "undefineddate"){
  324. // console.log("for customer and sale_person")
  325. // querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person from dvr_report where customer_name like '%" + customer + "%' and sale_person like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  326. // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + customer + "','" + customer_id + "')";
  327. // }else if(customer !=undefined && searchfilter != "undefineddate" && sale_person ==undefined){
  328. // console.log("customer and date filter");
  329. // querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person from dvr_report where date_of_visit between'" + firstdate + "' and '" + seconddate + "' and customer_name like '%" + customer + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  330. // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + customer + "','" + customer_id + "')";
  331. // }else if(customer !=undefined && searchfilter != "undefineddate" && sale_person !=undefined){
  332. // console.log("customer, sale person and date")
  333. // querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person from dvr_report where date_of_visit between'" + firstdate + "' and '" + seconddate + "' and customer_name like '%" + customer + "%' and sale_person like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  334. // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + customer + "','" + customer_id + "')";
  335. // }
  336. // else{
  337. // console.log("for date and sale_person filters");
  338. // querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person from dvr_report where date_of_visit between'" + firstdate + "' and '" + seconddate + "' and sale_person like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  339. // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + '' + "','" + '' + "')";
  340. // }
  341. console.log(querydvr);
  342. const queryresult = await db.executequery(querydvr);
  343. console.log("firstdate------>", firstdate, "seconddate-------->", seconddate)
  344. if (firstdate == undefined && seconddate == undefined) {
  345. } else {
  346. //date is request of api
  347. }
  348. console.log("countquery=========>", countquery)
  349. const queryresult1 = await db.executequery(countquery);
  350. console.log("queryresult1========>", queryresult1)
  351. var countdata = queryresult1[0];
  352. console.log("countdata", countdata, queryresult.length);
  353. for (var i = 0; i < queryresult.length; i++) {
  354. // console.log(queryresult[i]);
  355. dvrlist.push(queryresult[i])
  356. }
  357. if (queryresult.length > 0) {
  358. res.send({
  359. status: true,
  360. data: [{
  361. getdvrDataStatus: '0',
  362. mesasge: "Data Found",
  363. countdata: [{
  364. no_of_visit: (countdata == undefined ? queryresult.length : countdata[0].allcount),
  365. no_of_completed: (countdata == undefined ? 0 : countdata[0].completed),
  366. no_of_incompleted: (countdata == undefined ? 0 : countdata[0].incompleted),
  367. no_of_contact: (countdata == undefined ? 0 : countdata[0].contactcount)
  368. }],
  369. dvrlist,
  370. }],
  371. error: " "
  372. })
  373. } else {
  374. res.send({
  375. status: false,
  376. data: [{
  377. getdvrDataStatus: '1',
  378. mesasge: "Data Not Found"
  379. }],
  380. error: " "
  381. })
  382. }
  383. } else {
  384. //last week, month,year searchfilter
  385. console.log("in admin else part")
  386. if (req.query.searchfiltertype == '0') {
  387. //for last week
  388. var dvrlist = [];
  389. const lastweek = await getLastWeeksDate();
  390. const currentDate = await getcurrentDate();
  391. console.log(lastweek)
  392. if (sale_person == undefined) {
  393. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastweek + "' and '" + currentDate + "' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  394. } else {
  395. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastweek + "' and '" + currentDate + "' and contact_name like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  396. }
  397. const countquery = "call SP_CountDashboard ('" + lastweek + "','" + currentDate + "','" + '' + "')";
  398. const queryresult = await db.executequery(querydvr);
  399. console.log("countquery", countquery);
  400. const queryresult1 = await db.executequery(countquery);
  401. var countdata = queryresult1[0];
  402. for (var i = 0; i < queryresult.length; i++) {
  403. // console.log(queryresult[i]);
  404. dvrlist.push(queryresult[i])
  405. }
  406. if (queryresult.length > 0) {
  407. res.send({
  408. status: true,
  409. data: [{
  410. getdvrDataStatus: '0',
  411. mesasge: "Data Found",
  412. countdata: [{
  413. no_of_visit: countdata[0].allcount,
  414. no_of_completed: countdata[0].completed,
  415. no_of_incompleted: countdata[0].incompleted,
  416. no_of_contact: countdata[0].contactcount
  417. }],
  418. dvrlist,
  419. }],
  420. error: " "
  421. })
  422. } else {
  423. res.send({
  424. status: false,
  425. data: [{
  426. getdvrDataStatus: '1',
  427. mesasge: "Data Not Found"
  428. }],
  429. error: " "
  430. })
  431. }
  432. } else if (req.query.searchfiltertype == '2') {
  433. //for last year
  434. var dvrlist = [];
  435. const lastyeardate = await getLastYearDate();
  436. const currentDate = await getcurrentDate();
  437. if (sale_person == undefined) {
  438. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastyeardate + "' and '" + currentDate + "' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  439. } else {
  440. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastyeardate + "' and '" + currentDate + "' and contact_name like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc ";
  441. }
  442. console.log("lastyeardate", lastyeardate, " ", currentDate);
  443. const countquery = "call SP_CountDashboard ('" + lastyeardate + "' , '" + currentDate + "','" + '' + "')";
  444. const queryresult = await db.executequery(querydvr);
  445. console.log("querydvr-------->", querydvr);
  446. const queryresult1 = await db.executequery(countquery);
  447. var countdata = queryresult1[0];
  448. for (var i = 0; i < queryresult.length; i++) {
  449. // console.log(queryresult[i]);
  450. dvrlist.push(queryresult[i])
  451. }
  452. if (queryresult.length > 0) {
  453. // res.send({
  454. // getdvrDataStatus: '0',
  455. // mesasge: "Data Found",
  456. // countdata: [{
  457. // no_of_visit: countdata[0].allcount,
  458. // no_of_completed: countdata[0].completed,
  459. // no_of_incompleted: countdata[0].incompleted,
  460. // no_of_contact: countdata[0].contactcount
  461. // }],
  462. // dvrlist
  463. // })
  464. res.send({
  465. status: true,
  466. data: [{
  467. getdvrDataStatus: '0',
  468. mesasge: "Data Found",
  469. countdata: [{
  470. no_of_visit: countdata[0].allcount,
  471. no_of_completed: countdata[0].completed,
  472. no_of_incompleted: countdata[0].incompleted,
  473. no_of_contact: countdata[0].contactcount
  474. }],
  475. dvrlist,
  476. }],
  477. error: " "
  478. })
  479. } else {
  480. // res.send({
  481. // getdvrDataStatus: '1',
  482. // mesasge: "Data Not Found"
  483. // })
  484. res.send({
  485. status: false,
  486. data: [{
  487. getdvrDataStatus: '1',
  488. mesasge: "Data Not Found"
  489. }],
  490. error: " "
  491. })
  492. }
  493. } else {
  494. //by default for last month
  495. console.log("normal month");
  496. var dvrlist = [];
  497. const lastmonthDate = await getLastMonthDate();
  498. const currentDate = await getcurrentDate();
  499. console.log("lastmonthDate", lastmonthDate, "currentDate", currentDate);
  500. if (sale_person == undefined) {
  501. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastmonthDate + "' and '" + currentDate + "' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  502. }
  503. else {
  504. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastmonthDate + "' and '" + currentDate + "' and contact_name like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  505. }
  506. const countquery = "call SP_CountDashboard ('" + lastmonthDate + "' , '" + currentDate + "','" + '' + "')";
  507. const queryresult = await db.executequery(querydvr);
  508. const queryresult1 = await db.executequery(countquery);
  509. var countdata = queryresult1[0];
  510. for (var i = 0; i < queryresult.length; i++) {
  511. dvrlist.push(queryresult[i])
  512. }
  513. if (queryresult.length > 0) {
  514. res.send({
  515. status: true,
  516. data: [{
  517. getdvrDataStatus: '0',
  518. mesasge: "Data Found",
  519. countdata: [{
  520. no_of_visit: countdata[0].allcount,
  521. no_of_completed: countdata[0].completed,
  522. no_of_incompleted: countdata[0].incompleted,
  523. no_of_contact: countdata[0].contactcount
  524. }],
  525. dvrlist,
  526. }],
  527. error: " "
  528. })
  529. } else {
  530. // res.send({
  531. // getdvrDataStatus: '1',
  532. // mesasge: "Data Not Found"
  533. // })
  534. res.send({
  535. status: false,
  536. data: [{
  537. getdvrDataStatus: '1',
  538. mesasge: "Data Not Found"
  539. }],
  540. error: " "
  541. })
  542. }
  543. }
  544. }
  545. } else {
  546. var dvrlist = [];
  547. console.log("in else latest condition")
  548. const lastmonthDate = await getLastMonthDate();
  549. const currentDate = await getcurrentDate();
  550. console.log("lastmonthDate ", lastmonthDate, " currentDate", currentDate)
  551. if (sale_person == undefined) {
  552. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastmonthDate + "' and '" + currentDate + "' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  553. } else {
  554. console.log("by default value82829293839398")
  555. querydvr = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastmonthDate + "' and '" + currentDate + "' and contact_name like '%" + sale_person + "%' and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc ";
  556. }
  557. const countquery = "call SP_CountDashboard ('" + lastmonthDate + "' , '" + currentDate + "' ,'" + '' + "')";
  558. console.log("countquery", countquery);
  559. console.log("querydvr", querydvr)
  560. const queryresult1 = await db.executequery(countquery);
  561. var countdata = queryresult1[0];
  562. console.log("countdata", countdata);
  563. const queryresult = await db.executequery(querydvr);
  564. for (var i = 0; i < queryresult.length; i++) {
  565. // console.log(queryresult[i]);
  566. dvrlist.push(queryresult[i])
  567. }
  568. // if (dvrlist.length > 0) {
  569. // for (var i = 0; i < dvrlist.length; i++) {
  570. // }
  571. // }
  572. if (queryresult.length > 0) {
  573. res.send({
  574. status: true,
  575. data: [{
  576. getdvrDataStatus: '0',
  577. mesasge: "Data Found",
  578. countdata: [{
  579. no_of_visit: countdata[0].allcount,
  580. no_of_completed: countdata[0].completed,
  581. no_of_incompleted: countdata[0].incompleted,
  582. no_of_contact: countdata[0].contactcount
  583. }],
  584. dvrlist,
  585. }],
  586. error: " "
  587. })
  588. } else {
  589. res.send({
  590. status: false,
  591. data: [{
  592. getdvrDataStatus: '1',
  593. mesasge: "Data Not Found"
  594. }],
  595. error: " "
  596. })
  597. }
  598. }
  599. } else {
  600. //other user
  601. console.log("in other users");
  602. var getcustomer_id = [];
  603. var getcustomer_name = [];
  604. if (user_id_for_mapp) {
  605. const query = "select customer_id,user_id from customer_user_mapping where user_id=" + user_id_for_mapp;
  606. const queryresult_id = await db.executequery(query);
  607. console.log("queryresult", queryresult_id);
  608. for (var i = 0; i < queryresult_id.length; i++) {
  609. getcustomer_id.push(queryresult_id[i].customer_id);
  610. }
  611. console.log(getcustomer_id);
  612. }
  613. if (req.query.searchfiltertype) {
  614. console.log("in searchfiltertype ");
  615. if (req.query.searchfiltertype.length > 1) {
  616. console.log("datafliter");
  617. //date seach filter
  618. var searchfilter = req.query.searchfiltertype;
  619. const dates = searchfilter.split("-");
  620. console.log("dates", dates)
  621. const firstdate = dates[0] + ' 00:00:01';
  622. const seconddate = dates[1] + ' 23:59:59';
  623. console.log(firstdate);
  624. console.log(seconddate);
  625. if (getcustomer_id.length > 0) {
  626. console.log("data present in custmer mapping table");
  627. const getcust_name = "select customer_id,customer_name from customer_master where customer_id in(" + getcustomer_id + ")";
  628. const getqueryresult1 = await db.executequery(getcust_name);
  629. console.log("getcust_name", getcust_name)
  630. console.log("getcust_name============>", getqueryresult1);
  631. for (var i = 0; i < getqueryresult1.length; i++) {
  632. getcustomer_name.push(getqueryresult1[i].customer_name);
  633. }
  634. console.log("getcustomer_name", getcustomer_name);
  635. if (getcustomer_name) {
  636. for (var i = 0; i < getcustomer_name.length; i++) {
  637. const query = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + firstdate + "' and '" + seconddate + "' and customer_name in ('" + getcustomer_name[i] + "') and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  638. dvrlist[i] = await db.executequery(query);
  639. }
  640. var plano = dvrlist.reduce((acc, el) => acc.concat(el), []);
  641. //console.log("plano",plano)
  642. dvrlist = plano;
  643. console.log("finalResult=================>", dvrlist);
  644. const countquery = "call SP_CountDashboard ('" + firstdate + "' , '" + seconddate + "','" + login_id + "')";
  645. const queryresult1 = await db.executequery(countquery);
  646. console.log("queryresult1", countquery);
  647. var countdata = queryresult1[0];
  648. if (dvrlist.length > 0) {
  649. res.send({
  650. status: true,
  651. data: [{
  652. getdvrDataStatus: '0',
  653. mesasge: "Data Found",
  654. countdata: [{
  655. no_of_visit: countdata[0].allcount,
  656. no_of_completed: countdata[0].completed,
  657. no_of_incompleted: countdata[0].incompleted,
  658. no_of_contact: countdata[0].contactcount
  659. }],
  660. dvrlist
  661. }],
  662. error: " "
  663. })
  664. } else {
  665. res.send({
  666. status: false,
  667. data: [{
  668. getdvrDataStatus: '1',
  669. mesasge: "Data Not Found"
  670. }],
  671. error: " "
  672. })
  673. }
  674. }
  675. } else {
  676. console.log("data not present in custmer mapping table");
  677. res.send({
  678. status: false,
  679. data: [{
  680. getdvrDataStatus: '1',
  681. mesasge: "Data Not Found"
  682. }],
  683. error: " "
  684. })
  685. }
  686. // const query = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person from dvr_report where date_of_visit between'" + firstdate + "' and '" + seconddate + "' and login_id='" + login_id + "' order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  687. // const countquery = "call SP_CountDashboard ('" + firstdate + "' , '" + seconddate + + "','" + login_id + "')";
  688. // const queryresult = await db.executequery(query);
  689. // const queryresult1 = await db.executequery(countquery);
  690. // var countdata = queryresult1[0];
  691. // for (var i = 0; i < queryresult.length; i++) {
  692. // console.log(queryresult[i]);
  693. // dvrlist.push(queryresult[i])
  694. // }
  695. // if (queryresult.length > 0) {
  696. // res.send({
  697. // status: true,
  698. // data: [{
  699. // getdvrDataStatus: '0',
  700. // mesasge: "Data Found",
  701. // countdata: [{
  702. // no_of_visit: countdata[0].allcount,
  703. // no_of_completed: countdata[0].completed,
  704. // no_of_incompleted: countdata[0].incompleted,
  705. // no_of_contact: countdata[0].contactcount
  706. // }],
  707. // dvrlist,
  708. // }],
  709. // error: " "
  710. // })
  711. // } else {
  712. // res.send({
  713. // status: false,
  714. // data: [{
  715. // getdvrDataStatus: '1',
  716. // mesasge: "Data Not Found"
  717. // }],
  718. // error: " "
  719. // })
  720. // }
  721. } else {
  722. //last week, month,year searchfilter
  723. if (req.query.searchfiltertype == '0') {
  724. //for last week
  725. var dvrlist = [];
  726. const lastweek = await getLastWeeksDate();
  727. const currentDate = await getcurrentDate();
  728. if (getcustomer_id.length > 0) {
  729. console.log("data present in custmer mapping table");
  730. const getcust_name = "select customer_id,customer_name from customer_master where customer_id in(" + getcustomer_id + ")";
  731. const getqueryresult1 = await db.executequery(getcust_name);
  732. console.log("getcust_name", getcust_name)
  733. console.log("getcust_name============>", getqueryresult1);
  734. for (var i = 0; i < getqueryresult1.length; i++) {
  735. getcustomer_name.push(getqueryresult1[i].customer_name);
  736. }
  737. console.log("getcustomer_name", getcustomer_name);
  738. if (getcustomer_name) {
  739. for (var i = 0; i < getcustomer_name.length; i++) {
  740. const query = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastweek + "' and '" + currentDate + "' and customer_name in ('" + getcustomer_name[i] + "') and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  741. dvrlist[i] = await db.executequery(query);
  742. }
  743. var plano = dvrlist.reduce((acc, el) => acc.concat(el), []);
  744. //console.log("plano",plano)
  745. dvrlist = plano;
  746. console.log("finalResult=================>", dvrlist);
  747. const countquery = "call SP_CountDashboard ('" + lastweek + "' , '" + currentDate + "','" + login_id + "')";
  748. const queryresult1 = await db.executequery(countquery);
  749. console.log("queryresult1", countquery);
  750. var countdata = queryresult1[0];
  751. if (dvrlist.length > 0) {
  752. res.send({
  753. status: true,
  754. data: [{
  755. getdvrDataStatus: '0',
  756. mesasge: "Data Found",
  757. countdata: [{
  758. no_of_visit: countdata[0].allcount,
  759. no_of_completed: countdata[0].completed,
  760. no_of_incompleted: countdata[0].incompleted,
  761. no_of_contact: countdata[0].contactcount
  762. }],
  763. dvrlist
  764. }],
  765. error: " "
  766. })
  767. } else {
  768. res.send({
  769. status: false,
  770. data: [{
  771. getdvrDataStatus: '1',
  772. mesasge: "Data Not Found"
  773. }],
  774. error: " "
  775. })
  776. }
  777. }
  778. } else {
  779. console.log("data not present in custmer mapping table");
  780. res.send({
  781. status: false,
  782. data: [{
  783. getdvrDataStatus: '1',
  784. mesasge: "Data Not Found"
  785. }],
  786. error: " "
  787. })
  788. }
  789. // const query = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person from dvr_report where date_of_visit between'" + lastweek + "' and '" + currentDate + "' and login_id=" + login_id + "' order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  790. // const countquery = "call SP_CountDashboard ('" + lastweek + "' , '" + currentDate + "','" + login_id + "')";
  791. // const queryresult = await db.executequery(query);
  792. // const queryresult1 = await db.executequery(countquery);
  793. // var countdata = queryresult1[0];
  794. // for (var i = 0; i < queryresult.length; i++) {
  795. // console.log(queryresult[i]);
  796. // dvrlist.push(queryresult[i])
  797. // }
  798. // if (queryresult.length > 0) {
  799. // res.send({
  800. // status: true,
  801. // data: [{
  802. // getdvrDataStatus: '0',
  803. // mesasge: "Data Found",
  804. // countdata: [{
  805. // no_of_visit: countdata[0].allcount,
  806. // no_of_completed: countdata[0].completed,
  807. // no_of_incompleted: countdata[0].incompleted,
  808. // no_of_contact: countdata[0].contactcount
  809. // }],
  810. // dvrlist
  811. // }],
  812. // error: " "
  813. // })
  814. // } else {
  815. // res.send({
  816. // status: false,
  817. // data: [{
  818. // getdvrDataStatus: '1',
  819. // mesasge: "Data Not Found"
  820. // }],
  821. // error: " "
  822. // })
  823. // }
  824. } else if (req.query.searchfiltertype == '2') {
  825. //for last year
  826. var dvrlist = [];
  827. const lastyeardate = await getLastYearDate();
  828. const currentDate = await getcurrentDate();
  829. if (getcustomer_id.length > 0) {
  830. console.log("data present in custmer mapping table");
  831. const getcust_name = "select customer_id,customer_name from customer_master where customer_id in(" + getcustomer_id + ")";
  832. const getqueryresult1 = await db.executequery(getcust_name);
  833. console.log("getcust_name", getcust_name)
  834. console.log("getcust_name============>", getqueryresult1);
  835. for (var i = 0; i < getqueryresult1.length; i++) {
  836. getcustomer_name.push(getqueryresult1[i].customer_name);
  837. }
  838. console.log("getcustomer_name", getcustomer_name);
  839. if (getcustomer_name) {
  840. for (var i = 0; i < getcustomer_name.length; i++) {
  841. const query = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastyeardate + "' and '" + currentDate + "' and customer_name in ('" + getcustomer_name[i] + "') and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  842. dvrlist[i] = await db.executequery(query);
  843. }
  844. var plano = dvrlist.reduce((acc, el) => acc.concat(el), []);
  845. // console.log("plano",plano)
  846. dvrlist = plano;
  847. console.log("finalResult=================>", dvrlist);
  848. const countquery = "call SP_CountDashboard ('" + lastyeardate + "' , '" + currentDate + "','" + login_id + "')";
  849. const queryresult1 = await db.executequery(countquery);
  850. console.log("queryresult1", countquery);
  851. var countdata = queryresult1[0];
  852. if (dvrlist.length > 0) {
  853. res.send({
  854. status: true,
  855. data: [{
  856. getdvrDataStatus: '0',
  857. mesasge: "Data Found",
  858. countdata: [{
  859. no_of_visit: countdata[0].allcount,
  860. no_of_completed: countdata[0].completed,
  861. no_of_incompleted: countdata[0].incompleted,
  862. no_of_contact: countdata[0].contactcount
  863. }],
  864. dvrlist
  865. }],
  866. error: " "
  867. })
  868. } else {
  869. res.send({
  870. status: false,
  871. data: [{
  872. getdvrDataStatus: '1',
  873. mesasge: "Data Not Found"
  874. }],
  875. error: " "
  876. })
  877. }
  878. }
  879. } else {
  880. console.log("data not present in custmer mapping table");
  881. res.send({
  882. status: false,
  883. data: [{
  884. getdvrDataStatus: '1',
  885. mesasge: "Data Not Found"
  886. }],
  887. error: " "
  888. })
  889. }
  890. // const query = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person from dvr_report where date_of_visit between'" + lastyeardate + "' and '" + currentDate + "' and login_id=" + login_id + "' order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  891. // const countquery = "call SP_CountDashboard ('" + lastyeardate + "' , '" + currentDate + "','" + login_id + "')";
  892. // const queryresult = await db.executequery(query);
  893. // const queryresult1 = await db.executequery(countquery);
  894. // var countdata = queryresult1[0];
  895. // for (var i = 0; i < queryresult.length; i++) {
  896. // console.log(queryresult[i]);
  897. // dvrlist.push(queryresult[i])
  898. // }
  899. // if (queryresult.length > 0) {
  900. // res.send({
  901. // status: true,
  902. // data: [{
  903. // getdvrDataStatus: '0',
  904. // mesasge: "Data Found",
  905. // countdata: [{
  906. // no_of_visit: countdata[0].allcount,
  907. // no_of_completed: countdata[0].completed,
  908. // no_of_incompleted: countdata[0].incompleted,
  909. // no_of_contact: countdata[0].contactcount
  910. // }],
  911. // dvrlist
  912. // }],
  913. // error: " "
  914. // })
  915. // } else {
  916. // res.send({
  917. // status: false,
  918. // data: [{
  919. // getdvrDataStatus: '1',
  920. // mesasge: "Data Not Found"
  921. // }],
  922. // error: " "
  923. // })
  924. // }
  925. } else {
  926. //by default for last month
  927. console.log("users by last month", login_id);
  928. var dvrlist = [];
  929. const lastmonthDate = await getLastMonthDate();
  930. const currentDate = await getcurrentDate();
  931. if (getcustomer_id.length > 0) {
  932. console.log("data present in custmer mapping table");
  933. const getcust_name = "select customer_id,customer_name from customer_master where customer_id in(" + getcustomer_id + ")";
  934. const getqueryresult1 = await db.executequery(getcust_name);
  935. console.log("getcust_name", getcust_name)
  936. console.log("getcust_name============>", getqueryresult1);
  937. for (var i = 0; i < getqueryresult1.length; i++) {
  938. getcustomer_name.push(getqueryresult1[i].customer_name);
  939. }
  940. console.log("getcustomer_name", getcustomer_name);
  941. if (getcustomer_name) {
  942. for (var i = 0; i < getcustomer_name.length; i++) {
  943. const query = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastmonthDate + "' and '" + currentDate + "' and customer_name in ('" + getcustomer_name[i] + "') and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  944. dvrlist[i] = await db.executequery(query);
  945. }
  946. var plano = dvrlist.reduce((acc, el) => acc.concat(el), []);
  947. //console.log("plano",plano)
  948. dvrlist = plano;
  949. console.log("finalResult=================>", dvrlist);
  950. const countquery = "call SP_CountDashboard ('" + lastmonthDate + "' , '" + currentDate + "','" + login_id + "')";
  951. const queryresult1 = await db.executequery(countquery);
  952. console.log("queryresult1", countquery);
  953. var countdata = queryresult1[0];
  954. if (dvrlist.length > 0) {
  955. res.send({
  956. status: true,
  957. data: [{
  958. getdvrDataStatus: '0',
  959. mesasge: "Data Found",
  960. countdata: [{
  961. no_of_visit: countdata[0].allcount,
  962. no_of_completed: countdata[0].completed,
  963. no_of_incompleted: countdata[0].incompleted,
  964. no_of_contact: countdata[0].contactcount
  965. }],
  966. dvrlist
  967. }],
  968. error: " "
  969. })
  970. } else {
  971. res.send({
  972. status: false,
  973. data: [{
  974. getdvrDataStatus: '1',
  975. mesasge: "Data Not Found"
  976. }],
  977. error: " "
  978. })
  979. }
  980. }
  981. } else {
  982. console.log("data not present in custmer mapping table");
  983. res.send({
  984. status: false,
  985. data: [{
  986. getdvrDataStatus: '1',
  987. mesasge: "Data Not Found"
  988. }],
  989. error: " "
  990. })
  991. }
  992. // const query = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person from dvr_report where date_of_visit between'" + lastmonthDate + "' and '" + currentDate + "' and login_id=" + login_id + "' order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  993. // const countquery = "call SP_CountDashboard ('" + lastmonthDate + "' , '" + currentDate + "','" + login_id + "')";
  994. // const queryresult = await db.executequery(query);
  995. // const queryresult1 = await db.executequery(countquery);
  996. // var countdata = queryresult1[0];
  997. // for (var i = 0; i < queryresult.length; i++) {
  998. // console.log(queryresult[i]);
  999. // dvrlist.push(queryresult[i])
  1000. // }
  1001. // if (queryresult.length > 0) {
  1002. // console.log("dvrlist12345", dvrlist);
  1003. // res.send({
  1004. // status: true,
  1005. // data: [{
  1006. // getdvrDataStatus: 0,
  1007. // mesasge: "Data Found",
  1008. // countdata: [{
  1009. // no_of_visit: countdata[0].allcount,
  1010. // no_of_completed: countdata[0].completed,
  1011. // no_of_incompleted: countdata[0].incompleted,
  1012. // no_of_contact: countdata[0].contactcount
  1013. // }],
  1014. // dvrlist
  1015. // }],
  1016. // error: " "
  1017. // })
  1018. // } else {
  1019. // res.send({
  1020. // status: false,
  1021. // data: [{
  1022. // getdvrDataStatus: '1',
  1023. // mesasge: "Data Not Found"
  1024. // }],
  1025. // error: " "
  1026. // })
  1027. // }
  1028. }
  1029. }
  1030. } else {
  1031. console.log("in else part of bydefult");
  1032. var dvrlist = [];
  1033. const lastmonthDate = await getLastMonthDate();
  1034. const currentDate = await getcurrentDate();
  1035. console.log("lastmonthDate", lastmonthDate, "currentDate", currentDate);
  1036. if (getcustomer_id.length > 0) {
  1037. console.log("data present in custmer mapping table");
  1038. const getcust_name = "select customer_id,customer_name from customer_master where customer_id in(" + getcustomer_id + ")";
  1039. const getqueryresult1 = await db.executequery(getcust_name);
  1040. console.log("getcust_name", getcust_name)
  1041. console.log("getcust_name============>", getqueryresult1);
  1042. for (var i = 0; i < getqueryresult1.length; i++) {
  1043. getcustomer_name.push(getqueryresult1[i].customer_name);
  1044. }
  1045. console.log("getcustomer_name", getcustomer_name);
  1046. if (getcustomer_name) {
  1047. for (var i = 0; i < getcustomer_name.length; i++) {
  1048. const query = "select dvr_id, date_of_visit,customer_name,contact_name,message,physical_meeting,sale_person,nextstep,second_contact,objective,est_Date,estvalue,func,person,stage_id from dvr_report where date_of_visit between'" + lastmonthDate + "' and '" + currentDate + "' and customer_name in ('" + getcustomer_name[i] + "') and delete_id=0 order by DATE_FORMAT(date_of_visit, '%Y%m%d') desc";
  1049. dvrlist[i] = await db.executequery(query);
  1050. }
  1051. var plano = dvrlist.reduce((acc, el) => acc.concat(el), []);
  1052. //console.log("plano",plano)
  1053. dvrlist = plano;
  1054. console.log("finalResult=================>", dvrlist);
  1055. const countquery = "call SP_CountDashboard ('" + lastmonthDate + "' , '" + currentDate + "','" + login_id + "')";
  1056. const queryresult1 = await db.executequery(countquery);
  1057. console.log("queryresult1", countquery);
  1058. var countdata = queryresult1[0];
  1059. if (dvrlist.length > 0) {
  1060. res.send({
  1061. status: true,
  1062. data: [{
  1063. getdvrDataStatus: '0',
  1064. mesasge: "Data Found",
  1065. countdata: [{
  1066. no_of_visit: countdata[0].allcount,
  1067. no_of_completed: countdata[0].completed,
  1068. no_of_incompleted: countdata[0].incompleted,
  1069. no_of_contact: countdata[0].contactcount
  1070. }],
  1071. dvrlist
  1072. }],
  1073. error: " "
  1074. })
  1075. } else {
  1076. res.send({
  1077. status: false,
  1078. data: [{
  1079. getdvrDataStatus: '1',
  1080. mesasge: "Data Not Found"
  1081. }],
  1082. error: " "
  1083. })
  1084. }
  1085. }
  1086. } else {
  1087. console.log("data not present in custmer mapping table");
  1088. res.send({
  1089. status: false,
  1090. data: [{
  1091. getdvrDataStatus: '1',
  1092. mesasge: "Data Not Found"
  1093. }],
  1094. error: " "
  1095. })
  1096. }
  1097. }
  1098. }
  1099. }
  1100. catch (err) {
  1101. console.log(err)
  1102. res.send({
  1103. status: true,
  1104. data: [],
  1105. error: err,
  1106. getdvrDataStatus: '1',
  1107. })
  1108. }
  1109. }
  1110. module.exports.createDvrEntry = async (req, res) => {
  1111. const validationResp = await validation.createDvrentrycheck(req);
  1112. const createdate = new Date();
  1113. if (validationResp.status) {
  1114. try {
  1115. console.log(" req.body.login_id", req.body.created_by);
  1116. const date_of_visit = new Date(req.body.visit_date);
  1117. //const date_of_visit=req.body.visit_date;
  1118. console.log("estvalue:::::::::::::::::::::::::::::::::::::::::::", req.body)
  1119. const query = "INSERT INTO dvr_report(date_of_visit,customer_name,contact_name,physical_meeting,message,created_by,created_on,stage_id,login_id,sale_person,delete_id,nextstep,second_contact,objective,est_Date,estvalue,func,person)" +
  1120. "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  1121. const values = [date_of_visit, req.body.customer_name, req.body.contact_name, req.body.physical_metting, req.body.message, req.body.created_by, createdate, req.body.stage_id, req.body.created_by, req.body.sale_person, 0, req.body.nextstep, req.body.second_contact, req.body.objective, req.body.estDate, req.body.deal,req.body.func,req.body.person]
  1122. // console.log("query",query);
  1123. //console.log("values",values);
  1124. const res1 = await db.executevaluesquery(query, values);
  1125. console.log("res1", res1);
  1126. if (res1) {
  1127. res.send({
  1128. status: true,
  1129. data: [{
  1130. message: "Daily visit Entry created Successfully.",
  1131. createDvrStatus: "0",
  1132. exception: {
  1133. errorid: "",
  1134. errormessage: "No Errors"
  1135. }
  1136. }],
  1137. errors: ""
  1138. })
  1139. } else {
  1140. res.send({
  1141. status: true,
  1142. data: [{
  1143. message: "",
  1144. createDvrStatus: "1",
  1145. exception: {
  1146. errorid: "404",
  1147. errormessage: "Bad request"
  1148. }
  1149. }],
  1150. errors: ""
  1151. })
  1152. }
  1153. }
  1154. catch (err) {
  1155. console.log(err)
  1156. res.send({
  1157. status: false,
  1158. data: [{
  1159. message: "",
  1160. createDvrStatus: "1",
  1161. exception: {
  1162. errorid: "404",
  1163. errormessage: "Bad request"
  1164. }
  1165. }],
  1166. errors: ""
  1167. })
  1168. }
  1169. } else {
  1170. res.send(validationResp)
  1171. }
  1172. }
  1173. module.exports.updatedvrDetails = async (req, res) => {
  1174. const validationResp = await validation.updatedvrDetailscheck(req);
  1175. const updatedDate = await getcurrentDate();
  1176. if (validationResp.status) {
  1177. try {
  1178. const query = "UPDATE dvr_report SET date_of_visit = '" + req.body.visit_date + "' ,customer_name= '" + req.body.customer_name + "',contact_name= '" + req.body.contact_name + "',message= '" + req.body.message + "' ,physical_meeting= '" + req.body.physical_metting + "' ,updated_by= '" + req.body.updated_by + "', updated_on= '" + updatedDate + "', stage_id= '" + req.body.stage_id + "' , nextstep= '" + req.body.nextstep + "', second_contact= '" + req.body.second_contact + "', objective= '" + req.body.objective + "', estDate= '" + req.body.estDate + "', deal= '" + req.body.deal + "',func= '" + req.body.func + "',person= '" + req.body.person + "' where dvr_id= '" + req.body.dvr_id + "'";
  1179. console.log("query", query);
  1180. const queryresult = await db.executequery(query);
  1181. console.log("queryresult", queryresult);
  1182. if (queryresult) {
  1183. res.send({
  1184. status: true,
  1185. data: [
  1186. {
  1187. getdvrDataStatus: '0',
  1188. message: "Daliy visit Report Entry updated suceesfully."
  1189. }
  1190. ],
  1191. errors: " "
  1192. })
  1193. } else {
  1194. res.send({
  1195. status: true,
  1196. data: [{
  1197. getdvrDataStatus: '1',
  1198. message: "Daliy visit Report Entry not updated. Please try again after some time!"
  1199. }],
  1200. errors: ""
  1201. })
  1202. }
  1203. }
  1204. catch (err) {
  1205. console.log(err)
  1206. res.send({
  1207. status: true, data: [], errors: err
  1208. })
  1209. }
  1210. } else {
  1211. res.send(validationResp)
  1212. }
  1213. }
  1214. module.exports.createCustomerentry = async (req, res) => {
  1215. const validationResp = await validation.createCustomerentrycheck(req);
  1216. const createdate = new Date();
  1217. if (validationResp.status) {
  1218. try {
  1219. const query = "INSERT INTO customer_master(customer_name,created_by,created_on)" +
  1220. "VALUES(?,?,?)";
  1221. const values = [req.body.customer_name, req.body.created_by, createdate]
  1222. const res3 = await db.executevaluesquery(query, values);
  1223. //console.log("res1", res1);
  1224. if (res3) {
  1225. res.send({
  1226. message: "Customer Entry created Successfully ",
  1227. createcustomerStatus: "0",
  1228. exception: {
  1229. errorid: "",
  1230. errormessage: "No Errors"
  1231. }
  1232. })
  1233. } else {
  1234. res.send({
  1235. message: "",
  1236. createStatus: "1",
  1237. exception: {
  1238. errorid: "404",
  1239. errormessage: "Bad request"
  1240. }
  1241. })
  1242. }
  1243. }
  1244. catch (err) {
  1245. console.log(err)
  1246. res.send({
  1247. status: true, data: []
  1248. })
  1249. }
  1250. } else {
  1251. res.send(validationResp)
  1252. }
  1253. }
  1254. module.exports.updateContactDetails = async (req, res) => {
  1255. const validationResp = await validation.updateContactDetailscheck(req);
  1256. const updatedDate = await getcurrentDate();
  1257. if (validationResp.status) {
  1258. try {
  1259. const query = "UPDATE contact_master SET customer_id= '" + req.body.customer_id + "',first_name= '" + req.body.first_name + "',last_name= '" + req.body.last_name + "' ,mobile_number= '" + req.body.mobile_number + "' ,email_id= '" + req.body.email_id + "', designation= '" + req.body.designation + "', department= '" + req.body.department + "', updated_on= '" + updatedDate + "' , mob_no= '" + req.body.mob_no + "' where customer_id= '" + req.body.customer_id + "'";
  1260. console.log("query", query);
  1261. const queryresult = await db.executequery(query);
  1262. console.log("queryresult", queryresult);
  1263. if (queryresult) {
  1264. res.send({
  1265. updateContactStatus: '0',
  1266. mesasge: "Contact Entry updated suceesfully."
  1267. })
  1268. } else {
  1269. res.send({
  1270. updateContactStatus: '1',
  1271. mesasge: "Contact Entry not updated."
  1272. })
  1273. }
  1274. }
  1275. catch (err) {
  1276. console.log(err)
  1277. res.send({
  1278. status: true, data: []
  1279. })
  1280. }
  1281. } else {
  1282. res.send(validationResp)
  1283. }
  1284. }
  1285. module.exports.updateCustomerDetails = async (req, res) => {
  1286. const validationResp = await validation.updateCustomerDetailscheck(req);
  1287. const updatedDate = await getcurrentDate();
  1288. if (validationResp.status) {
  1289. try {
  1290. const query = "UPDATE customer_master SET customer_id = '" + req.body.customer_id + "', updated_on= '" + updatedDate + "' where customer_master= '" + req.body.contact_master + "'";
  1291. console.log("query", query);
  1292. const queryresult = await db.executequery(query);
  1293. console.log("queryresult", queryresult);
  1294. if (queryresult) {
  1295. res.send({
  1296. updateCustomerStatus: '0',
  1297. mesasge: "Customer Entry updated suceesfully."
  1298. })
  1299. } else {
  1300. res.send({
  1301. updateCustomerStatus: '1',
  1302. mesasge: "Customer Entry not updated."
  1303. })
  1304. }
  1305. }
  1306. catch (err) {
  1307. console.log(err)
  1308. res.send({
  1309. status: true, data: []
  1310. })
  1311. }
  1312. } else {
  1313. res.send(validationResp)
  1314. }
  1315. }
  1316. module.exports.getlastestdvr = async (req, res) => {
  1317. try {
  1318. var insertedRecord = [];
  1319. var startdate = new Date();
  1320. var enddate = new Date();
  1321. const format2 = "YYYY-MM-DD";
  1322. startdate = moment(startdate).format(format2) + ' 00:00:01';
  1323. enddate = moment(enddate).format(format2) + ' 23:59:59';
  1324. var person_role = req.query.role;
  1325. var login_id = req.query.login_id;
  1326. console.log("login_id", login_id);
  1327. if (person_role == 'admin') {
  1328. //admin show all data
  1329. const query = "SELECT d.dvr_id,d.date_of_visit,d.customer_name,d.contact_name,d.physical_meeting,d.message,s.stage_desc,d.stage_id,d.nextstep,d.second_contact,d.objective,d.est_Date,d.estvalue,d.func,d.person FROM dvr_report d JOIN stage_master s ON d.stage_id=s.stage_id where d.created_on between '" + startdate + "' and '" + enddate + "' and d.delete_id=0 order by d.date_of_visit desc";
  1330. const queryresult = await db.executequery(query);
  1331. console.log("query", query);
  1332. for (var i = 0; i < queryresult.length; i++) {
  1333. console.log(queryresult[i]);
  1334. insertedRecord.push(queryresult[i])
  1335. }
  1336. //console.log("res1", res1);
  1337. if (queryresult.length > 0) {
  1338. res.send({
  1339. status: true,
  1340. data: [{
  1341. dvrData: insertedRecord
  1342. }],
  1343. error: ""
  1344. })
  1345. } else {
  1346. res.send({
  1347. status: true,
  1348. data: [{
  1349. getdvrDataStatus: '1',
  1350. mesasge: "Data Not Found"
  1351. }],
  1352. error: ""
  1353. })
  1354. }
  1355. } else {
  1356. // other users
  1357. console.log("other users");
  1358. const query = "SELECT d.dvr_id,d.date_of_visit,d.customer_name,d.contact_name,d.physical_meeting,d.message,s.stage_desc,d.stage_id,d.nextstep,d.second_contact,d.objective,d.est_Date,d.estvalue,d.func,d.person FROM dvr_report d JOIN stage_master s ON d.stage_id=s.stage_id where d.login_id='" + login_id + "' and d.created_on between '" + startdate + "' and '" + enddate + "' and d.delete_id=0 order by d.date_of_visit desc";
  1359. const queryresult = await db.executequery(query);
  1360. console.log("query", query);
  1361. for (var i = 0; i < queryresult.length; i++) {
  1362. console.log(queryresult[i]);
  1363. insertedRecord.push(queryresult[i])
  1364. }
  1365. console.log("queryresult", queryresult);
  1366. if (queryresult.length > 0) {
  1367. res.send({
  1368. status: true,
  1369. data: [{
  1370. dvrData: insertedRecord
  1371. }],
  1372. error: ""
  1373. })
  1374. } else {
  1375. res.send({
  1376. status: true,
  1377. data: [{
  1378. getdvrDataStatus: '1',
  1379. mesasge: "Data Not Found"
  1380. }],
  1381. error: ""
  1382. })
  1383. }
  1384. }
  1385. }
  1386. catch (err) {
  1387. console.log(err)
  1388. res.send({
  1389. status: true,
  1390. data: [],
  1391. getdvrDataStatus: '1',
  1392. })
  1393. }
  1394. }
  1395. module.exports.getcontactDetails = async (req, res) => {
  1396. try {
  1397. var insertedRecord = [];
  1398. var startdate = new Date();
  1399. var enddate = new Date();
  1400. const format2 = "YYYY-MM-DD";
  1401. startdate = moment(startdate).format(format2) + ' 00:00:01';
  1402. enddate = moment(enddate).format(format2) + ' 23:59:59';
  1403. var person_role = req.query.role;
  1404. var login_id = req.query.login_id;
  1405. if (person_role == 'admin') {
  1406. //admin show all data
  1407. const query = "SELECT first_name,last_name,mobile_number,email_id,designation,department FROM contact_master where created_on between '" + startdate + "' and '" + enddate + "' order by contact_id desc";
  1408. const queryresult = await db.executequery(query);
  1409. console.log("query", query);
  1410. for (var i = 0; i < queryresult.length; i++) {
  1411. console.log(queryresult[i]);
  1412. insertedRecord.push(queryresult[i])
  1413. }
  1414. if (queryresult.length > 0) {
  1415. res.send({
  1416. status: true,
  1417. data: [{
  1418. conrtactData: insertedRecord
  1419. }],
  1420. error: ""
  1421. })
  1422. } else {
  1423. res.send({
  1424. status: true,
  1425. data: [{
  1426. getdvrDataStatus: '1',
  1427. mesasge: "Data Not Found"
  1428. }],
  1429. error: ""
  1430. })
  1431. }
  1432. } else {
  1433. //others users
  1434. const query = "SELECT first_name,last_name,mobile_number,email_id,designation,department FROM contact_master where created_by= '" + login_id + "' and created_on between '" + startdate + "' and '" + enddate + "' order by contact_id desc";
  1435. const queryresult = await db.executequery(query);
  1436. console.log("query", query);
  1437. for (var i = 0; i < queryresult.length; i++) {
  1438. console.log(queryresult[i]);
  1439. insertedRecord.push(queryresult[i])
  1440. }
  1441. if (queryresult.length > 0) {
  1442. res.send({
  1443. status: true,
  1444. data: [{
  1445. conrtactData: insertedRecord
  1446. }],
  1447. error: ""
  1448. })
  1449. } else {
  1450. res.send({
  1451. status: true,
  1452. data: [{
  1453. getdvrDataStatus: '1',
  1454. mesasge: "Data Not Found"
  1455. }],
  1456. error: ""
  1457. })
  1458. }
  1459. }
  1460. } catch (err) {
  1461. console.log(err)
  1462. res.send({
  1463. status: true,
  1464. data: [],
  1465. getdvrDataStatus: '1',
  1466. })
  1467. }
  1468. }
  1469. module.exports.getsalePersonList = async (req, res) => {
  1470. console.log("in getsalePersonList");
  1471. try {
  1472. var salePerson = [];
  1473. var full_name = [];
  1474. const query = "SELECT user_id,first_name,last_name from user_master;";
  1475. const queryresult = await db.executequery(query);
  1476. if (queryresult.length > 0) {
  1477. for (var i = 0; i < queryresult.length; i++) {
  1478. console.log("queryresult", queryresult[i])
  1479. salePerson.push(queryresult[i]);
  1480. }
  1481. }
  1482. console.log("salePerson", salePerson);
  1483. res.send({
  1484. status: true,
  1485. data: [{
  1486. salePerson: salePerson
  1487. }],
  1488. error: ""
  1489. })
  1490. } catch (err) {
  1491. console.log(err)
  1492. res.send({
  1493. status: true, data: [], error: err
  1494. })
  1495. }
  1496. }
  1497. module.exports.getCustcontactDetails = async (req, res) => {
  1498. try {
  1499. var contactdetails = [];
  1500. var customer_id = req.query.customer_id;
  1501. var check_api = req.query.passid;
  1502. var passing_id;
  1503. console.log("customer_id", customer_id);
  1504. console.log("check api", check_api);
  1505. if (check_api == undefined) {
  1506. console.log("pass customer name");
  1507. const query = "SELECT customer_id,customer_name FROM customer_master where customer_name= '" + customer_id + "' ";
  1508. const queryresult = await db.executequery(query);
  1509. console.log("queryresult", queryresult);
  1510. console.log("result------>", queryresult[0].customer_id);
  1511. passing_id = queryresult[0].customer_id;
  1512. const query_id = "SELECT first_name,last_name,mobile_number,email_id,designation,department,function_area,mob_no,stage_id FROM contact_master where customer_id= '" + passing_id + "' order by first_name";
  1513. const queryresult_id = await db.executequery(query_id);
  1514. console.log("query", query);
  1515. for (var i = 0; i < queryresult_id.length; i++) {
  1516. console.log(queryresult_id[i]);
  1517. contactdetails.push(queryresult_id[i])
  1518. }
  1519. if (queryresult.length > 0) {
  1520. res.send({
  1521. status: true,
  1522. data: [{
  1523. conrtactData: contactdetails
  1524. }],
  1525. error: ""
  1526. })
  1527. } else {
  1528. res.send({
  1529. status: true,
  1530. data: [{
  1531. getdvrDataStatus: '1',
  1532. mesasge: "Data Not Found"
  1533. }],
  1534. error: ""
  1535. })
  1536. }
  1537. } else {
  1538. console.log("pass number");
  1539. if (customer_id == 0) {
  1540. console.log("getting all contact data");
  1541. const query = "SELECT first_name,last_name,mobile_number,email_id,designation,department,function_area,mob_no,stage_id FROM contact_master order by first_name";
  1542. const queryresult = await db.executequery(query);
  1543. console.log("query", query);
  1544. for (var i = 0; i < queryresult.length; i++) {
  1545. console.log(queryresult[i]);
  1546. contactdetails.push(queryresult[i])
  1547. }
  1548. if (queryresult.length > 0) {
  1549. res.send({
  1550. status: true,
  1551. data: [{
  1552. conrtactData: contactdetails
  1553. }],
  1554. error: ""
  1555. })
  1556. } else {
  1557. res.send({
  1558. status: true,
  1559. data: [{
  1560. getdvrDataStatus: '1',
  1561. mesasge: "Data Not Found"
  1562. }],
  1563. error: ""
  1564. })
  1565. }
  1566. } else {
  1567. console.log("getting only specific customer contact data");
  1568. const query = "SELECT first_name,last_name,mobile_number,email_id,designation,department,function_area,mob_no,stage_id FROM contact_master where customer_id= '" + customer_id + "' order by first_name";
  1569. const queryresult = await db.executequery(query);
  1570. console.log("query", query);
  1571. for (var i = 0; i < queryresult.length; i++) {
  1572. console.log(queryresult[i]);
  1573. contactdetails.push(queryresult[i])
  1574. }
  1575. if (queryresult.length > 0) {
  1576. res.send({
  1577. status: true,
  1578. data: [{
  1579. conrtactData: contactdetails
  1580. }],
  1581. error: ""
  1582. })
  1583. } else {
  1584. res.send({
  1585. status: true,
  1586. data: [{
  1587. getdvrDataStatus: '1',
  1588. mesasge: "Data Not Found"
  1589. }],
  1590. error: ""
  1591. })
  1592. }
  1593. }
  1594. }
  1595. } catch (err) {
  1596. console.log(err)
  1597. res.send({
  1598. status: true,
  1599. data: [],
  1600. getdvrDataStatus: '1',
  1601. })
  1602. }
  1603. }
  1604. module.exports.createUpdateCustomerentry = async (req, res) => {
  1605. const validationResp = await validation.createCustomerentrycheck(req);
  1606. const createdate = new Date();
  1607. if (validationResp.status) {
  1608. try {
  1609. if (req.body.action == 'insert') {
  1610. console.log("customer added");
  1611. const checkdub = "select * from customer_master where customer_name='" + req.body.customer_name + "'";
  1612. const checkqueryresult = await db.executequery(checkdub);
  1613. console.log("checkqueryresult", checkqueryresult.length)
  1614. if (checkqueryresult.length > 0) {
  1615. //allready all present
  1616. res.send({
  1617. status: false,
  1618. data: [],
  1619. errors: "Customer Entry allready Exit ! Please Enter Correct Customer Name"
  1620. })
  1621. } else {
  1622. //data not is present
  1623. const query = "INSERT INTO customer_master(customer_name,created_by,created_on)" +
  1624. "VALUES(?,?,?)";
  1625. const values = [req.body.customer_name, req.body.created_by, createdate]
  1626. const res3 = await db.executevaluesquery(query, values);
  1627. console.log("response", res3);
  1628. if (res3) {
  1629. const query = "select customer_id from customer_master order by customer_id desc limit 1";
  1630. const queryresult = await db.executequery(query);
  1631. console.log("query result----->", queryresult);
  1632. console.log("query result----->", queryresult[0].customer_id);
  1633. if (queryresult) {
  1634. // const query = "select customer_id from customer_master order by customer_id desc limit 1";
  1635. // const queryresult = await db.executequery(query);
  1636. var sale_person = req.body.sale_person;
  1637. var name = sale_person.split(" ");
  1638. console.log("name", name);
  1639. var first_name = name[0];
  1640. var last_name = name[1];
  1641. console.log(first_name, last_name);
  1642. const queryuserID = "SELECT user_id FROM user_master where first_name='" + first_name + "' and last_name= '" + last_name + "'";
  1643. console.log("queryuserID", queryuserID);
  1644. const queryresultID = await db.executequery(queryuserID);
  1645. console.log("queryresultID", queryresultID);
  1646. const finalquery = "INSERT INTO customer_user_mapping(customer_id,user_id,created_by,created_on)" +
  1647. "VALUES(?,?,?,?)";
  1648. const values = [queryresult[0].customer_id, queryresultID[0].user_id, req.body.created_by, createdate]
  1649. const res3 = await db.executevaluesquery(finalquery, values);
  1650. console.log("res3", res3);
  1651. if (res3) {
  1652. res.send({
  1653. status: true,
  1654. data: [{
  1655. createcustomerStatus: "0",
  1656. message: "Customer Entry created Successfully!",
  1657. lastinsertedData: req.body.customer_name,
  1658. exception: {
  1659. errorid: "",
  1660. errormessage: "No Errors"
  1661. }
  1662. }],
  1663. error: " "
  1664. })
  1665. } else {
  1666. res.send({
  1667. status: false,
  1668. data: [{
  1669. message: "Customer Entry Not created",
  1670. createcustomerStatus: "1",
  1671. exception: {
  1672. errorid: "404",
  1673. errormessage: "Bad request"
  1674. }
  1675. }],
  1676. error: ""
  1677. })
  1678. }
  1679. }
  1680. } else {
  1681. res.send({
  1682. status: true,
  1683. data: [],
  1684. errors: "Bad Request"
  1685. })
  1686. }
  1687. }
  1688. } else {
  1689. console.log("customer update");
  1690. const query = "UPDATE customer_master SET customer_name= '" + req.body.customer_name + "',updated_on= '" + createdate + "' ,updated_by= '" + req.body.created_by + "' where customer_id= '" + req.body.customer_id + "'";
  1691. console.log("query", query);
  1692. const queryresult = await db.executequery(query);
  1693. console.log("queryresult", queryresult);
  1694. //dates = searchfilter.split("-");
  1695. var saleData = req.body.sale_person.split(" ");
  1696. console.log("saleData");
  1697. //select user_id from user_master where first_name= "" and last_name="";
  1698. if (queryresult) {
  1699. const getsaleperson = "select user_id from user_master where first_name= '" + saleData[0] + "' and last_name= '" + saleData[1] + "'";
  1700. const getqueryresult = await db.executequery(getsaleperson);
  1701. if (getqueryresult) {
  1702. const checkdupli = "select * from customer_user_mapping where user_id=" + getqueryresult[0].user_id + " and customer_id= '" + req.body.customer_id + "' order by idcustCont_mapp desc limit 1";
  1703. const checkexcutequer = await db.executequery(checkdupli);
  1704. if (checkexcutequer[0].user_id == getqueryresult[0].user_id) {
  1705. //same user for customer update
  1706. console.log("same user for customer update");
  1707. console.log("database date", formatDateAsPer(checkexcutequer[0].effectivedate_to));
  1708. console.log("req body", req.body.effectivedate_to)
  1709. if (req.body.effectivedate_to.length > 0) {
  1710. if (req.body.effectivedate_from > req.body.effectivedate_to) {
  1711. res.send({
  1712. status: false,
  1713. data: [],
  1714. errors: "Please enter correct Effective From Date! Make sure Efffective From Date is less than Effective To Date"
  1715. })
  1716. } else {
  1717. const query = "INSERT INTO customer_user_mapping(customer_id,user_id,effiectivedate_from,effectivedate_to,created_by,created_on)" +
  1718. "VALUES(?,?,?,?,?,?)";
  1719. const values = [req.body.customer_id, getqueryresult[0].user_id, req.body.effectivedate_from, req.body.effectivedate_to.length > 0 ? req.body.effectivedate_to : null, req.body.created_by, createdate]
  1720. const res3 = await db.executevaluesquery(query, values);
  1721. console.log("response--------->", res3);
  1722. if (res3) {
  1723. res.send({
  1724. status: true,
  1725. data: [{
  1726. message: "Customer Entry Update Successfully!",
  1727. createcustomerStatus: "0",
  1728. lastinsertedData: req.body.customer_name,
  1729. exception: {
  1730. errorid: "",
  1731. errormessage: "No Errors"
  1732. }
  1733. }],
  1734. error: " "
  1735. })
  1736. } else {
  1737. res.send({
  1738. status: true,
  1739. data: [{
  1740. message: "Customer Entry Not Updated.",
  1741. createStatus: "1",
  1742. exception: {
  1743. errorid: "404",
  1744. errormessage: "Bad request"
  1745. }
  1746. }],
  1747. error: ""
  1748. })
  1749. }
  1750. }
  1751. } else {
  1752. //same user id for effective different date.
  1753. const query = "INSERT INTO customer_user_mapping(customer_id,user_id,effiectivedate_from,effectivedate_to,created_by,created_on)" +
  1754. "VALUES(?,?,?,?,?,?)";
  1755. const values = [req.body.customer_id, getqueryresult[0].user_id, req.body.effectivedate_from, req.body.effectivedate_to.length > 0 ? req.body.effectivedate_to : null, req.body.created_by, createdate]
  1756. const res3 = await db.executevaluesquery(query, values);
  1757. console.log("response--------->", res3);
  1758. if (res3) {
  1759. res.send({
  1760. status: true,
  1761. data: [{
  1762. message: "Customer Entry Update Successfully!",
  1763. createcustomerStatus: "0",
  1764. lastinsertedData: req.body.customer_name,
  1765. exception: {
  1766. errorid: "",
  1767. errormessage: "No Errors"
  1768. }
  1769. }],
  1770. error: " "
  1771. })
  1772. } else {
  1773. res.send({
  1774. status: true,
  1775. data: [{
  1776. message: "Customer Entry Not Updated.",
  1777. createStatus: "1",
  1778. exception: {
  1779. errorid: "404",
  1780. errormessage: "Bad request"
  1781. }
  1782. }],
  1783. error: ""
  1784. })
  1785. }
  1786. }
  1787. } else {
  1788. //other user for customer update
  1789. if (req.body.effectivedate_to.length > 0 && checkexcutequer[0].effectivedate_to.length > 0) {
  1790. if (req.body.effectivedate_to == formatDateAsPer(checkexcutequer[0].effectivedate_to)) {
  1791. res.send({
  1792. status: false,
  1793. data: [],
  1794. errors: "Please enter correct Effective To Date are same for other sales Person "
  1795. })
  1796. }
  1797. } else if (req.body.effectivedate_to.length > 0) {
  1798. if (req.body.effectivedate_from > req.body.effectivedate_to) {
  1799. res.send({
  1800. status: false,
  1801. data: [],
  1802. errors: "Please enter correct Effective From Date! Make sure Efffective From Date is less than Effective To Date"
  1803. })
  1804. } else if (req.body.effectivedate_from == req.body.effectivedate_to) {
  1805. res.send({
  1806. status: false,
  1807. data: [],
  1808. errors: "Please enter correct Effective From and Effection To Date ! Both Dates are same"
  1809. })
  1810. } else {
  1811. const query = "INSERT INTO customer_user_mapping(customer_id,user_id,effiectivedate_from,effectivedate_to,created_by,created_on)" +
  1812. "VALUES(?,?,?,?,?,?)";
  1813. const values = [req.body.customer_id, getqueryresult[0].user_id, req.body.effectivedate_from, req.body.effectivedate_to.length > 0 ? req.body.effectivedate_to : null, req.body.created_by, createdate]
  1814. const res3 = await db.executevaluesquery(query, values);
  1815. console.log("response--------->", res3);
  1816. if (res3) {
  1817. res.send({
  1818. status: true,
  1819. data: [{
  1820. message: "Customer Entry Update Successfully!",
  1821. createcustomerStatus: "0",
  1822. lastinsertedData: req.body.customer_name,
  1823. exception: {
  1824. errorid: "",
  1825. errormessage: "No Errors"
  1826. }
  1827. }],
  1828. error: " "
  1829. })
  1830. } else {
  1831. res.send({
  1832. status: true,
  1833. data: [{
  1834. message: "Customer Entry Not Updated",
  1835. createStatus: "1",
  1836. exception: {
  1837. errorid: "404",
  1838. errormessage: "Bad request"
  1839. }
  1840. }],
  1841. error: ""
  1842. })
  1843. }
  1844. }
  1845. } else {
  1846. //all ok
  1847. const query = "INSERT INTO customer_user_mapping(customer_id,user_id,effiectivedate_from,effectivedate_to,created_by,created_on)" +
  1848. "VALUES(?,?,?,?,?,?)";
  1849. const values = [req.body.customer_id, getqueryresult[0].user_id, req.body.effectivedate_from, req.body.effectivedate_to.length > 0 ? req.body.effectivedate_to : null, req.body.created_by, createdate]
  1850. const res3 = await db.executevaluesquery(query, values);
  1851. console.log("response--------->", res3);
  1852. if (res3) {
  1853. res.send({
  1854. status: true,
  1855. data: [{
  1856. message: "Customer Entry Update Successfully!",
  1857. createcustomerStatus: "0",
  1858. lastinsertedData: req.body.customer_name,
  1859. exception: {
  1860. errorid: "",
  1861. errormessage: "No Errors"
  1862. }
  1863. }],
  1864. error: " "
  1865. })
  1866. } else {
  1867. res.send({
  1868. status: true,
  1869. data: [{
  1870. message: "Customer Entry Not Updated",
  1871. createStatus: "1",
  1872. exception: {
  1873. errorid: "404",
  1874. errormessage: "Bad request"
  1875. }
  1876. }],
  1877. error: ""
  1878. })
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. catch (err) {
  1887. console.log(err)
  1888. res.send({
  1889. status: true, data: [],
  1890. errors: err
  1891. })
  1892. }
  1893. } else {
  1894. res.send(validationResp)
  1895. }
  1896. }
  1897. module.exports.deletedvrEntry = async (req, res) => {
  1898. try {
  1899. //DELETE FROM table_name WHERE condition;
  1900. console.log("req.body", req.body);
  1901. const updatedDate = await getcurrentDate();
  1902. const query = "UPDATE dvr_report SET delete_id = 1,updated_by= '" + req.body.created_by + "', updated_on= '" + updatedDate + "' where dvr_id= " + req.body.dvr_id + "";
  1903. const checkqueryresult = await db.executequery(query);
  1904. console.log("checkqueryresult", checkqueryresult)
  1905. console.log("eeeeeeee", checkqueryresult.affectedRows);
  1906. if (checkqueryresult) {
  1907. //entry not deleted
  1908. res.send({
  1909. status: true,
  1910. data: [{
  1911. message: "DVR Entry Deleted Successfully!",
  1912. deleteStatus: "0"
  1913. }],
  1914. error: ""
  1915. })
  1916. } else {
  1917. //entry deleted
  1918. res.send({
  1919. status: true,
  1920. data: [{
  1921. message: "DVR Entry Not Deleted.",
  1922. deleteStatus: "1",
  1923. exception: {
  1924. errorid: "404",
  1925. errormessage: "Bad request"
  1926. }
  1927. }],
  1928. error: ""
  1929. })
  1930. }
  1931. } catch (err) {
  1932. console.log(err)
  1933. res.send({
  1934. status: true,
  1935. data: [],
  1936. getdvrDataStatus: '1',
  1937. })
  1938. }
  1939. }
  1940. // module.exports.mappingCustomerDetails = async (req, res) => {
  1941. // // Validate the request
  1942. // const validationResp = await validation.mappingCustomerDetailsCheck(req);
  1943. // if (validationResp.status) {
  1944. // try {
  1945. // // Extract salesperson's name
  1946. // const sale_person = req.body.sale_person;
  1947. // const name = sale_person.split(" ");
  1948. // const first_name = name[0];
  1949. // const last_name = name[1];
  1950. // console.log("Extracted names:", first_name, last_name);
  1951. // // SQL query to get user_id from user_master
  1952. // const queryUserID = "SELECT user_id FROM user_master WHERE first_name='" + first_name + "' AND last_name='" + last_name + "'";
  1953. // console.log("queryUserID", queryUserID);
  1954. // const queryResultID = await db.executequery(queryUserID);
  1955. // console.log("User ID query result:", queryResultID);
  1956. // if (queryResultID.length > 0) {
  1957. // res.send({
  1958. // status: true,
  1959. // data: {
  1960. // user_id: queryResultID[0].user_id
  1961. // },
  1962. // error: null
  1963. // });
  1964. // } else {
  1965. // res.send({
  1966. // status: false,
  1967. // data: [],
  1968. // errors: "No user found with the specified name."
  1969. // });
  1970. // }
  1971. // } catch (err) {
  1972. // console.error("Error occurred:", err);
  1973. // res.send({
  1974. // status: false,
  1975. // data: [],
  1976. // errors: "An error occurred while fetching the user ID."
  1977. // });
  1978. // }
  1979. // } else {
  1980. // res.send(validationResp);
  1981. // }
  1982. // }
  1983. module.exports.mappingCustomerDetails = async (req, res) => {
  1984. // Validate the request
  1985. console.log("sale_", req.query.sale_person)
  1986. const validationResp = await validation.mappingCustomerDetailsCheck(req);
  1987. if (validationResp.status) {
  1988. try {
  1989. const sale_person = req.query.sale_person;
  1990. const name = sale_person.split(" ");
  1991. const first_name = name[0];
  1992. const last_name = name[1];
  1993. console.log("Extracted names:", first_name, last_name);
  1994. // SQL query to get user_id from user_master
  1995. const queryUserID = "SELECT user_id FROM user_master WHERE first_name='" + first_name + "' AND last_name='" + last_name + "'";
  1996. console.log("queryUserID", queryUserID);
  1997. const queryResultID = await db.executequery(queryUserID);
  1998. console.log("User ID query result:", queryResultID);
  1999. if (queryResultID.length > 0) {
  2000. const userId = queryResultID[0].user_id;
  2001. // SQL query to get customer details associated with the user_id
  2002. const queryCustomerDetails = `
  2003. SELECT c.customer_id, c.customer_name, u.user_id
  2004. FROM customer_master c
  2005. JOIN customer_user_mapping u ON c.customer_id = u.customer_id
  2006. WHERE u.user_id = '${userId}'`;
  2007. console.log("queryCustomerDetails", queryCustomerDetails);
  2008. const customerDetailsResult = await db.executequery(queryCustomerDetails);
  2009. console.log("Customer details result:", customerDetailsResult);
  2010. if (customerDetailsResult.length > 0) {
  2011. res.send({
  2012. status: true,
  2013. data: customerDetailsResult,
  2014. error: null
  2015. });
  2016. } else {
  2017. res.send({
  2018. status: false,
  2019. data: [],
  2020. errors: "No customer details found for the specified salesperson."
  2021. });
  2022. }
  2023. } else {
  2024. res.send({
  2025. status: false,
  2026. data: [],
  2027. errors: "No user found with the specified name."
  2028. });
  2029. }
  2030. } catch (err) {
  2031. console.error("Error occurred:", err);
  2032. res.send({
  2033. status: false,
  2034. data: [],
  2035. errors: "An error occurred while fetching the customer details."
  2036. });
  2037. }
  2038. } else {
  2039. res.send(validationResp);
  2040. }
  2041. }
  2042. module.exports.mappingFuncIDToPersonNames = async (req, res) => {
  2043. // Validate the request
  2044. console.log("func_id_", req.query.func_id);
  2045. const validationResp = await validation.mappingFuncIDToPersonNamesCheck(req);
  2046. if (validationResp.status) {
  2047. try {
  2048. const func_id = req.query.func_id;
  2049. // SQL query to get all persons mapped to the given func_id
  2050. const queryFunctionPersonMapping = `
  2051. SELECT f.func_id, p.person_name
  2052. FROM dvr_local.function_person_mapping fp
  2053. JOIN dvr_local.function_details f ON f.func_id = fp.func_id
  2054. JOIN dvr_local.person_details p ON p.person_id = fp.person_id
  2055. WHERE fp.func_id = '${func_id}'`;
  2056. console.log("queryFunctionPersonMapping", queryFunctionPersonMapping);
  2057. // Use parameterized query to avoid SQL injection
  2058. const queryResult = await db.executequery(queryFunctionPersonMapping, [func_id]);
  2059. console.log("Function-person mapping query result:", queryResult);
  2060. if (queryResult.length > 0) {
  2061. res.send({
  2062. status: true,
  2063. data: queryResult,
  2064. error: null
  2065. });
  2066. } else {
  2067. res.send({
  2068. status: false,
  2069. data: [],
  2070. errors: "No persons are mapped to the specified function ID."
  2071. });
  2072. }
  2073. } catch (err) {
  2074. console.error("Error occurred:", err);
  2075. res.send({
  2076. status: false,
  2077. data: [],
  2078. errors: "An error occurred while fetching the person details for the specified function ID."
  2079. });
  2080. }
  2081. } else {
  2082. res.send(validationResp);
  2083. }
  2084. };
  2085. function getLastWeeksDate() {
  2086. const now = new Date();
  2087. const format2 = "YYYY-MM-DD";
  2088. const date = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
  2089. // console.log("date", date);
  2090. const dateTime2 = moment(date).format(format2) + ' 00:00:00';
  2091. // console.log("date------>", dateTime2);
  2092. return dateTime2;
  2093. }
  2094. function getcurrentDate() {
  2095. const now = new Date();
  2096. const format2 = "YYYY-MM-DD";
  2097. const dateTime2 = moment(now).format(format2) + ' 23:59:59';
  2098. // console.log("date------>", dateTime2);
  2099. return dateTime2;
  2100. }
  2101. function getLastMonthDate() {
  2102. const now = new Date();
  2103. const format2 = "YYYY-MM-DD";
  2104. const date = new Date(now.getFullYear(), now.getMonth() - 1, 1);
  2105. // console.log("date", date);
  2106. const dateTime2 = moment(date).format(format2) + ' 00:00:00';
  2107. //console.log("date------>", dateTime2);
  2108. return dateTime2;
  2109. }
  2110. function getLastYearDate() {
  2111. const now = new Date();
  2112. const format2 = "YYYY-MM-DD";
  2113. const date = new Date(now.setFullYear(now.getFullYear() - 1));
  2114. // console.log("date", date);
  2115. const dateTime2 = moment(date).format(format2) + ' 00:00:00';
  2116. //console.log("date------>", dateTime2);
  2117. return dateTime2;
  2118. }