123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706 |
- const db = require("../services/dbconnection");
- const validation = require("../controllers/validation")
- const moment = require("moment");
- const logger = require('../utils/logger');
- module.exports.createContactEntry = async (req, res) => {
- const validationResp = await validation.createContactentrycheck(req);
- const createdate = new Date();
- if (validationResp.status) {
- try {
- var stage_id;
- if (req.body.email_id == null || req.body.mobile_no == null) {
- //|| req.body.department == null || req.body.designation == null) {
- stage_id = 2;
- console.log(stage_id);
- } else {
- stage_id = 1;
- }
- 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 + "'";
- console.log("querycount", querycount);
- const querycountresult = await db.executequery(querycount);
- console.log("querycountresult", querycountresult);
- console.log("querycountresult1", querycountresult[0].count);
- if (querycountresult[0].count > 0) {
- console.log("duplicate entry present");
- res.send({
- status: true,
- data: [{
- message: "",
- createStatus: "1",
- exception: {
- errorid: "400",
- errormessage: "Duplicate Entry: This contact alrady exists in the database."
- }
- }],
- error: ""
- })
- } else {
- console.log("new contact details")
- 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)" +
- "VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
- 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]
- const res1 = await db.executevaluesquery(query, values);
- logger.info('log to file', res);
- if (res1) {
- const query = "select contact_id,customer_id,first_name,last_name from contact_master order by contact_id desc limit 1";
- const queryresult = await db.executequery(query);
- console.log("queryresult", queryresult);
- res.send({
- status: true,
- data: [{
- message: "Contact Entry created Successfully ",
- createStatus: "0",
- lastinsertedData: queryresult[0].first_name + " " + queryresult[0].last_name,
- exception: {
- errorid: "",
- errormessage: "No Errors"
- }
- }],
- error: " "
- })
- } else {
- res.send({
- status: true,
- data: [{
- message: "",
- createStatus: "1",
- exception: {
- errorid: "404",
- errormessage: "Bad request"
- }
- }],
- error: ""
- })
- }
- }
- }
- catch (err) {
- console.log(err)
- res.send({
- status: true,
- data: [{
- message: "",
- createStatus: "1",
- exception: {
- errorid: "404",
- errormessage: "Bad request"
- }
- }],
- error: err
- })
- }
- } else {
- res.send(validationResp)
- }
- }
- module.exports.getdvrDetails = async (req, res) => {
- console.log("in dvr details for one id");
- const validationResp = await validation.getdvrDetailscheck(req);
- if (validationResp.status) {
- try {
- 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";
- console.log("query", query)
- const queryresult = await db.executequery(query);
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [
- {
- getdvrDataStatus: '0',
- mesasge: "Data Found",
- visit_date: queryresult[0].date_of_visit,
- customer_name: queryresult[0].customer_name,
- contact_name: queryresult[0].contact_name,
- mesasge: queryresult[0].message,
- physical_metting: queryresult[0].physical_meeting,
- stage_desc: queryresult[0].stage_desc,
- stage_id: queryresult[0].stage_id,
- created_on: queryresult[0].created_on,
- nextstep: queryresult[0].nextstep,
- second_contact:queryresult[0].second_contact,
- objective:queryresult[0].objective,
- est_Date:queryresult[0].est_Date,
- deal:queryresult[0].estvalue,
- func:queryresult[0].func,
- person:queryresult[0].person
- }
- ],
- errors: ""
- })
- } else {
- res.send({
- status: false,
- data: [
- {
- getdvrDataStatus: '1',
- mesasge: "Data not Found"
- }
- ],
- errors: ""
- })
- }
- }
- catch (err) {
- console.log(err)
- res.send({
- status: true, data: []
- })
- }
- } else {
- res.send(validationResp)
- }
- }
- module.exports.getselectionData = async (req, res) => {
- try {
- var customerData = [];
- var contactData = [];
- var stageData = [];
- var personData = [];
- var funcDetails = [];
- const query = "SELECT customer_id,customer_name FROM customer_master";
- const queryresult = await db.executequery(query);
- if (queryresult.length > 0) {
- for (var i = 0; i < queryresult.length; i++) {
- customerData.push(queryresult[i])
- }
- }
- const query1 = "SELECT contact_id,first_name,last_name FROM contact_master order by first_name";
- const queryresult1 = await db.executequery(query1);
- if (queryresult1.length > 0) {
- for (var i = 0; i < queryresult1.length; i++) {
- contactData.push(queryresult1[i])
- }
- }
- const query2 = "SELECT stage_id,stage_desc FROM stage_master";
- const queryresult2 = await db.executequery(query2);
- if (queryresult2.length > 0) {
- for (var i = 0; i < queryresult2.length; i++) {
- stageData.push(queryresult2[i])
- }
- }
- const query3 = "SELECT person_id,person_name FROM person_details";
- const queryresult3 = await db.executequery(query3);
- if (queryresult3.length > 0) {
- for (var i = 0; i < queryresult3.length; i++) {
- personData.push(queryresult3[i])
- }
- }
- const query4 = "SELECT func_id,func_name FROM function_details";
- const queryresult4 = await db.executequery(query4);
- if (queryresult4.length > 0) {
- for (var i = 0; i < queryresult4.length; i++) {
- funcDetails.push(queryresult4[i])
- }
- }
- res.send({
- status: true,
- data: [{
- customerData: customerData
- }, {
- contactData: contactData
- }, {
- stageData: stageData
- },
- {
- personData:personData
- },
- {
- funcDetails: funcDetails
- }
- ],
- error: ""
- })
- }
- catch (err) {
- console.log(err)
- res.send({
- status: true, data: [], error: err
- })
- }
- }
- module.exports.getdashboarddetails = async (req, res) => {
- try {
- var login_id = req.query.login_id;
- var sale_person = req.query.salePerson;
- var customer = req.query.customer;
- var customer_id = req.query.customerid;
- var rol_des;
- var dvrlist = [];
- var rolData;
- var rolData1;
- var dates, firstdate, seconddate;
- var user_id_for_mapp;
- var emai_id;
- const findRole = "call SP_roleidentify1('" + login_id + "')";
- const roleidentify = await db.executequery(findRole);
- rolData = roleidentify[0];
- console.log("findRole", findRole);
- rolData.forEach(function (item) {
- console.log(item.role_des);
- rolData1 = item.role_des;
- user_id_for_mapp = item.user_id11;
- });
- //console.log("item",item);
- rol_des = rolData1;
- console.log("user_id_for_mapp", user_id_for_mapp)
- if (rol_des == 'admin') {
- //admin
- console.log("req.query.searchfiltertype", req.query.searchfiltertype);
- if (req.query.searchfiltertype) {
- if (req.query.searchfiltertype.length > 1) {
- //date seach filter
- console.log("in ifffffffffffffffffffffffffffff");
- var searchfilter = req.query.searchfiltertype;
- console.log("searchfilter", searchfilter);
- if (searchfilter == "undefineddate") {
- console.log("date not pass");
- firstdate = '';
- seconddate = '';
- } else {
- dates = searchfilter.split("-");
- console.log("dates", dates)
- firstdate = dates[0] + ' 00:00:00';
- seconddate = dates[1] + ' 23:59:59';
- }
- var querydvr;
- var countquery;
- console.log("firstdate", firstdate);
- console.log("seconddate", seconddate);
- console.log("ooooooooooooo", sale_person);
- if (sale_person != undefined && sale_person != 'undefined' && sale_person != 'all') {
- var data = sale_person.split(" ");
- console.log("data----->", data)
- console.log("need to find sale person email id for cound data");
- var query = "select user_id,login_id from user_master where first_name like '%" + data[0] + "%' and last_name like '%" + data[1] + "%'";
- const res_user = await db.executequery(query);
- console.log("res_user", res_user);
- console.log("res_user----------->", res_user[0].login_id)
- emai_id = res_user[0].login_id;
- }
- console.log("customer", customer, "customer_id", customer_id, " email_id-->", emai_id);
- if (sale_person != undefined && customer == undefined && searchfilter == 'undefineddate' && sale_person != 'all') {
- console.log("only for sale_person");
- 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";
- countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + '' + "','" + '' + "')";
- } else if (sale_person == undefined && customer != undefined && searchfilter == 'undefineddate' && sale_person != 'all' && customer != 'all') {
- console.log("only for customer");
- 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";
- countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + customer + "','" + customer_id + "')";
- } else if (sale_person != undefined && customer != undefined && customer_id != undefined && sale_person != 'all') {
- console.log("for sales_person and Customer");
- 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";
- countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + customer + "','" + customer_id + "')";
- } else if (sale_person != 'all' && firstdate != undefined && seconddate != undefined && sale_person != undefined) {
- console.log("date and sale_person");
- 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";
- countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + '' + "','" + '' + "')";
- } else if (customer != undefined && firstdate != undefined && seconddate != undefined && sale_person == undefined) {
- console.log("for date and customer");
- 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";
- countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + customer + "','" + customer_id + "')";
- } else if (customer != undefined && firstdate != undefined && seconddate != undefined && sale_person != undefined) {
- console.log("all filters");
- 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";
- countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + customer + "','" + customer_id + "')";
- }
- else {
- console.log("only for date");
- 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";
- countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + '' + "','" + '' + "')";
- }
- // if (sale_person == undefined && customer == undefined && searchfilter != "undefineddate" && sale_person == 'undefined') {
- // console.log("only for date")
- // 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";
- // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + '' + "','" + '' + "')";
- // } else if (sale_person != undefined && searchfilter == "undefineddate" && customer == undefined && sale_person !='undefined') {
- // console.log("for sale_peron only")
- // 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";
- // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + '' + "','" + '' + "')";
- // }else if(customer != undefined && customer_id !=undefined && searchfilter == "undefineddate" && sale_person !=undefined && sale_person != 'undefined'){
- // console.log("for customer only");
- // 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";
- // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + customer + "','" + customer_id + "')";
- // }else if(customer !=undefined && sale_person !='undefined' && sale_person !=undefined && searchfilter == "undefineddate"){
- // console.log("for customer and sale_person")
- // 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";
- // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + customer + "','" + customer_id + "')";
- // }else if(customer !=undefined && searchfilter != "undefineddate" && sale_person ==undefined){
- // console.log("customer and date filter");
- // 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";
- // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + '' + "','" + customer + "','" + customer_id + "')";
- // }else if(customer !=undefined && searchfilter != "undefineddate" && sale_person !=undefined){
- // console.log("customer, sale person and date")
- // 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";
- // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + customer + "','" + customer_id + "')";
- // }
- // else{
- // console.log("for date and sale_person filters");
- // 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";
- // countquery = "call SP_CountDashboard_admin ('" + firstdate + "','" + seconddate + "','" + emai_id + "','" + '' + "','" + '' + "')";
- // }
- console.log(querydvr);
- const queryresult = await db.executequery(querydvr);
- console.log("firstdate------>", firstdate, "seconddate-------->", seconddate)
- if (firstdate == undefined && seconddate == undefined) {
- } else {
- //date is request of api
- }
- console.log("countquery=========>", countquery)
- const queryresult1 = await db.executequery(countquery);
- console.log("queryresult1========>", queryresult1)
- var countdata = queryresult1[0];
- console.log("countdata", countdata, queryresult.length);
- for (var i = 0; i < queryresult.length; i++) {
- // console.log(queryresult[i]);
- dvrlist.push(queryresult[i])
- }
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '0',
- mesasge: "Data Found",
- countdata: [{
- no_of_visit: (countdata == undefined ? queryresult.length : countdata[0].allcount),
- no_of_completed: (countdata == undefined ? 0 : countdata[0].completed),
- no_of_incompleted: (countdata == undefined ? 0 : countdata[0].incompleted),
- no_of_contact: (countdata == undefined ? 0 : countdata[0].contactcount)
- }],
- dvrlist,
- }],
- error: " "
- })
- } else {
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- } else {
- //last week, month,year searchfilter
- console.log("in admin else part")
- if (req.query.searchfiltertype == '0') {
- //for last week
- var dvrlist = [];
- const lastweek = await getLastWeeksDate();
- const currentDate = await getcurrentDate();
- console.log(lastweek)
- if (sale_person == undefined) {
- 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";
- } else {
- 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";
- }
- const countquery = "call SP_CountDashboard ('" + lastweek + "','" + currentDate + "','" + '' + "')";
- const queryresult = await db.executequery(querydvr);
- console.log("countquery", countquery);
- const queryresult1 = await db.executequery(countquery);
- var countdata = queryresult1[0];
- for (var i = 0; i < queryresult.length; i++) {
- // console.log(queryresult[i]);
- dvrlist.push(queryresult[i])
- }
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '0',
- mesasge: "Data Found",
- countdata: [{
- no_of_visit: countdata[0].allcount,
- no_of_completed: countdata[0].completed,
- no_of_incompleted: countdata[0].incompleted,
- no_of_contact: countdata[0].contactcount
- }],
- dvrlist,
- }],
- error: " "
- })
- } else {
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- } else if (req.query.searchfiltertype == '2') {
- //for last year
- var dvrlist = [];
- const lastyeardate = await getLastYearDate();
- const currentDate = await getcurrentDate();
- if (sale_person == undefined) {
- 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";
- } else {
- 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 ";
- }
- console.log("lastyeardate", lastyeardate, " ", currentDate);
- const countquery = "call SP_CountDashboard ('" + lastyeardate + "' , '" + currentDate + "','" + '' + "')";
- const queryresult = await db.executequery(querydvr);
- console.log("querydvr-------->", querydvr);
- const queryresult1 = await db.executequery(countquery);
- var countdata = queryresult1[0];
- for (var i = 0; i < queryresult.length; i++) {
- // console.log(queryresult[i]);
- dvrlist.push(queryresult[i])
- }
- if (queryresult.length > 0) {
- // res.send({
- // getdvrDataStatus: '0',
- // mesasge: "Data Found",
- // countdata: [{
- // no_of_visit: countdata[0].allcount,
- // no_of_completed: countdata[0].completed,
- // no_of_incompleted: countdata[0].incompleted,
- // no_of_contact: countdata[0].contactcount
- // }],
- // dvrlist
- // })
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '0',
- mesasge: "Data Found",
- countdata: [{
- no_of_visit: countdata[0].allcount,
- no_of_completed: countdata[0].completed,
- no_of_incompleted: countdata[0].incompleted,
- no_of_contact: countdata[0].contactcount
- }],
- dvrlist,
- }],
- error: " "
- })
- } else {
- // res.send({
- // getdvrDataStatus: '1',
- // mesasge: "Data Not Found"
- // })
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- } else {
- //by default for last month
- console.log("normal month");
- var dvrlist = [];
- const lastmonthDate = await getLastMonthDate();
- const currentDate = await getcurrentDate();
- console.log("lastmonthDate", lastmonthDate, "currentDate", currentDate);
- if (sale_person == undefined) {
- 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";
- }
- else {
- 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";
- }
- const countquery = "call SP_CountDashboard ('" + lastmonthDate + "' , '" + currentDate + "','" + '' + "')";
- const queryresult = await db.executequery(querydvr);
- const queryresult1 = await db.executequery(countquery);
- var countdata = queryresult1[0];
- for (var i = 0; i < queryresult.length; i++) {
- dvrlist.push(queryresult[i])
- }
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '0',
- mesasge: "Data Found",
- countdata: [{
- no_of_visit: countdata[0].allcount,
- no_of_completed: countdata[0].completed,
- no_of_incompleted: countdata[0].incompleted,
- no_of_contact: countdata[0].contactcount
- }],
- dvrlist,
- }],
- error: " "
- })
- } else {
- // res.send({
- // getdvrDataStatus: '1',
- // mesasge: "Data Not Found"
- // })
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- }
- }
- } else {
- var dvrlist = [];
- console.log("in else latest condition")
- const lastmonthDate = await getLastMonthDate();
- const currentDate = await getcurrentDate();
- console.log("lastmonthDate ", lastmonthDate, " currentDate", currentDate)
- if (sale_person == undefined) {
- 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";
- } else {
- console.log("by default value82829293839398")
- 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 ";
- }
- const countquery = "call SP_CountDashboard ('" + lastmonthDate + "' , '" + currentDate + "' ,'" + '' + "')";
- console.log("countquery", countquery);
- console.log("querydvr", querydvr)
- const queryresult1 = await db.executequery(countquery);
- var countdata = queryresult1[0];
- console.log("countdata", countdata);
- const queryresult = await db.executequery(querydvr);
- for (var i = 0; i < queryresult.length; i++) {
- // console.log(queryresult[i]);
- dvrlist.push(queryresult[i])
- }
- // if (dvrlist.length > 0) {
- // for (var i = 0; i < dvrlist.length; i++) {
- // }
- // }
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '0',
- mesasge: "Data Found",
- countdata: [{
- no_of_visit: countdata[0].allcount,
- no_of_completed: countdata[0].completed,
- no_of_incompleted: countdata[0].incompleted,
- no_of_contact: countdata[0].contactcount
- }],
- dvrlist,
- }],
- error: " "
- })
- } else {
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- }
- } else {
- //other user
- console.log("in other users");
- var getcustomer_id = [];
- var getcustomer_name = [];
- if (user_id_for_mapp) {
- const query = "select customer_id,user_id from customer_user_mapping where user_id=" + user_id_for_mapp;
- const queryresult_id = await db.executequery(query);
- console.log("queryresult", queryresult_id);
- for (var i = 0; i < queryresult_id.length; i++) {
- getcustomer_id.push(queryresult_id[i].customer_id);
- }
- console.log(getcustomer_id);
- }
- if (req.query.searchfiltertype) {
- console.log("in searchfiltertype ");
- if (req.query.searchfiltertype.length > 1) {
- console.log("datafliter");
- //date seach filter
- var searchfilter = req.query.searchfiltertype;
- const dates = searchfilter.split("-");
- console.log("dates", dates)
- const firstdate = dates[0] + ' 00:00:01';
- const seconddate = dates[1] + ' 23:59:59';
- console.log(firstdate);
- console.log(seconddate);
- if (getcustomer_id.length > 0) {
- console.log("data present in custmer mapping table");
- const getcust_name = "select customer_id,customer_name from customer_master where customer_id in(" + getcustomer_id + ")";
- const getqueryresult1 = await db.executequery(getcust_name);
- console.log("getcust_name", getcust_name)
- console.log("getcust_name============>", getqueryresult1);
- for (var i = 0; i < getqueryresult1.length; i++) {
- getcustomer_name.push(getqueryresult1[i].customer_name);
- }
- console.log("getcustomer_name", getcustomer_name);
- if (getcustomer_name) {
- for (var i = 0; i < getcustomer_name.length; i++) {
- 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";
- dvrlist[i] = await db.executequery(query);
- }
- var plano = dvrlist.reduce((acc, el) => acc.concat(el), []);
- //console.log("plano",plano)
- dvrlist = plano;
- console.log("finalResult=================>", dvrlist);
- const countquery = "call SP_CountDashboard ('" + firstdate + "' , '" + seconddate + "','" + login_id + "')";
- const queryresult1 = await db.executequery(countquery);
- console.log("queryresult1", countquery);
- var countdata = queryresult1[0];
- if (dvrlist.length > 0) {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '0',
- mesasge: "Data Found",
- countdata: [{
- no_of_visit: countdata[0].allcount,
- no_of_completed: countdata[0].completed,
- no_of_incompleted: countdata[0].incompleted,
- no_of_contact: countdata[0].contactcount
- }],
- dvrlist
- }],
- error: " "
- })
- } else {
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- }
- } else {
- console.log("data not present in custmer mapping table");
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- // 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";
- // const countquery = "call SP_CountDashboard ('" + firstdate + "' , '" + seconddate + + "','" + login_id + "')";
- // const queryresult = await db.executequery(query);
- // const queryresult1 = await db.executequery(countquery);
- // var countdata = queryresult1[0];
- // for (var i = 0; i < queryresult.length; i++) {
- // console.log(queryresult[i]);
- // dvrlist.push(queryresult[i])
- // }
- // if (queryresult.length > 0) {
- // res.send({
- // status: true,
- // data: [{
- // getdvrDataStatus: '0',
- // mesasge: "Data Found",
- // countdata: [{
- // no_of_visit: countdata[0].allcount,
- // no_of_completed: countdata[0].completed,
- // no_of_incompleted: countdata[0].incompleted,
- // no_of_contact: countdata[0].contactcount
- // }],
- // dvrlist,
- // }],
- // error: " "
- // })
- // } else {
- // res.send({
- // status: false,
- // data: [{
- // getdvrDataStatus: '1',
- // mesasge: "Data Not Found"
- // }],
- // error: " "
- // })
- // }
- } else {
- //last week, month,year searchfilter
- if (req.query.searchfiltertype == '0') {
- //for last week
- var dvrlist = [];
- const lastweek = await getLastWeeksDate();
- const currentDate = await getcurrentDate();
- if (getcustomer_id.length > 0) {
- console.log("data present in custmer mapping table");
- const getcust_name = "select customer_id,customer_name from customer_master where customer_id in(" + getcustomer_id + ")";
- const getqueryresult1 = await db.executequery(getcust_name);
- console.log("getcust_name", getcust_name)
- console.log("getcust_name============>", getqueryresult1);
- for (var i = 0; i < getqueryresult1.length; i++) {
- getcustomer_name.push(getqueryresult1[i].customer_name);
- }
- console.log("getcustomer_name", getcustomer_name);
- if (getcustomer_name) {
- for (var i = 0; i < getcustomer_name.length; i++) {
- 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";
- dvrlist[i] = await db.executequery(query);
- }
- var plano = dvrlist.reduce((acc, el) => acc.concat(el), []);
- //console.log("plano",plano)
- dvrlist = plano;
- console.log("finalResult=================>", dvrlist);
- const countquery = "call SP_CountDashboard ('" + lastweek + "' , '" + currentDate + "','" + login_id + "')";
- const queryresult1 = await db.executequery(countquery);
- console.log("queryresult1", countquery);
- var countdata = queryresult1[0];
- if (dvrlist.length > 0) {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '0',
- mesasge: "Data Found",
- countdata: [{
- no_of_visit: countdata[0].allcount,
- no_of_completed: countdata[0].completed,
- no_of_incompleted: countdata[0].incompleted,
- no_of_contact: countdata[0].contactcount
- }],
- dvrlist
- }],
- error: " "
- })
- } else {
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- }
- } else {
- console.log("data not present in custmer mapping table");
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- // 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";
- // const countquery = "call SP_CountDashboard ('" + lastweek + "' , '" + currentDate + "','" + login_id + "')";
- // const queryresult = await db.executequery(query);
- // const queryresult1 = await db.executequery(countquery);
- // var countdata = queryresult1[0];
- // for (var i = 0; i < queryresult.length; i++) {
- // console.log(queryresult[i]);
- // dvrlist.push(queryresult[i])
- // }
- // if (queryresult.length > 0) {
- // res.send({
- // status: true,
- // data: [{
- // getdvrDataStatus: '0',
- // mesasge: "Data Found",
- // countdata: [{
- // no_of_visit: countdata[0].allcount,
- // no_of_completed: countdata[0].completed,
- // no_of_incompleted: countdata[0].incompleted,
- // no_of_contact: countdata[0].contactcount
- // }],
- // dvrlist
- // }],
- // error: " "
- // })
- // } else {
- // res.send({
- // status: false,
- // data: [{
- // getdvrDataStatus: '1',
- // mesasge: "Data Not Found"
- // }],
- // error: " "
- // })
- // }
- } else if (req.query.searchfiltertype == '2') {
- //for last year
- var dvrlist = [];
- const lastyeardate = await getLastYearDate();
- const currentDate = await getcurrentDate();
- if (getcustomer_id.length > 0) {
- console.log("data present in custmer mapping table");
- const getcust_name = "select customer_id,customer_name from customer_master where customer_id in(" + getcustomer_id + ")";
- const getqueryresult1 = await db.executequery(getcust_name);
- console.log("getcust_name", getcust_name)
- console.log("getcust_name============>", getqueryresult1);
- for (var i = 0; i < getqueryresult1.length; i++) {
- getcustomer_name.push(getqueryresult1[i].customer_name);
- }
- console.log("getcustomer_name", getcustomer_name);
- if (getcustomer_name) {
- for (var i = 0; i < getcustomer_name.length; i++) {
- 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";
- dvrlist[i] = await db.executequery(query);
- }
- var plano = dvrlist.reduce((acc, el) => acc.concat(el), []);
- // console.log("plano",plano)
- dvrlist = plano;
- console.log("finalResult=================>", dvrlist);
- const countquery = "call SP_CountDashboard ('" + lastyeardate + "' , '" + currentDate + "','" + login_id + "')";
- const queryresult1 = await db.executequery(countquery);
- console.log("queryresult1", countquery);
- var countdata = queryresult1[0];
- if (dvrlist.length > 0) {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '0',
- mesasge: "Data Found",
- countdata: [{
- no_of_visit: countdata[0].allcount,
- no_of_completed: countdata[0].completed,
- no_of_incompleted: countdata[0].incompleted,
- no_of_contact: countdata[0].contactcount
- }],
- dvrlist
- }],
- error: " "
- })
- } else {
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- }
- } else {
- console.log("data not present in custmer mapping table");
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- // 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";
- // const countquery = "call SP_CountDashboard ('" + lastyeardate + "' , '" + currentDate + "','" + login_id + "')";
- // const queryresult = await db.executequery(query);
- // const queryresult1 = await db.executequery(countquery);
- // var countdata = queryresult1[0];
- // for (var i = 0; i < queryresult.length; i++) {
- // console.log(queryresult[i]);
- // dvrlist.push(queryresult[i])
- // }
- // if (queryresult.length > 0) {
- // res.send({
- // status: true,
- // data: [{
- // getdvrDataStatus: '0',
- // mesasge: "Data Found",
- // countdata: [{
- // no_of_visit: countdata[0].allcount,
- // no_of_completed: countdata[0].completed,
- // no_of_incompleted: countdata[0].incompleted,
- // no_of_contact: countdata[0].contactcount
- // }],
- // dvrlist
- // }],
- // error: " "
- // })
- // } else {
- // res.send({
- // status: false,
- // data: [{
- // getdvrDataStatus: '1',
- // mesasge: "Data Not Found"
- // }],
- // error: " "
- // })
- // }
- } else {
- //by default for last month
- console.log("users by last month", login_id);
- var dvrlist = [];
- const lastmonthDate = await getLastMonthDate();
- const currentDate = await getcurrentDate();
- if (getcustomer_id.length > 0) {
- console.log("data present in custmer mapping table");
- const getcust_name = "select customer_id,customer_name from customer_master where customer_id in(" + getcustomer_id + ")";
- const getqueryresult1 = await db.executequery(getcust_name);
- console.log("getcust_name", getcust_name)
- console.log("getcust_name============>", getqueryresult1);
- for (var i = 0; i < getqueryresult1.length; i++) {
- getcustomer_name.push(getqueryresult1[i].customer_name);
- }
- console.log("getcustomer_name", getcustomer_name);
- if (getcustomer_name) {
- for (var i = 0; i < getcustomer_name.length; i++) {
- 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";
- dvrlist[i] = await db.executequery(query);
- }
- var plano = dvrlist.reduce((acc, el) => acc.concat(el), []);
- //console.log("plano",plano)
- dvrlist = plano;
- console.log("finalResult=================>", dvrlist);
- const countquery = "call SP_CountDashboard ('" + lastmonthDate + "' , '" + currentDate + "','" + login_id + "')";
- const queryresult1 = await db.executequery(countquery);
- console.log("queryresult1", countquery);
- var countdata = queryresult1[0];
- if (dvrlist.length > 0) {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '0',
- mesasge: "Data Found",
- countdata: [{
- no_of_visit: countdata[0].allcount,
- no_of_completed: countdata[0].completed,
- no_of_incompleted: countdata[0].incompleted,
- no_of_contact: countdata[0].contactcount
- }],
- dvrlist
- }],
- error: " "
- })
- } else {
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- }
- } else {
- console.log("data not present in custmer mapping table");
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- // 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";
- // const countquery = "call SP_CountDashboard ('" + lastmonthDate + "' , '" + currentDate + "','" + login_id + "')";
- // const queryresult = await db.executequery(query);
- // const queryresult1 = await db.executequery(countquery);
- // var countdata = queryresult1[0];
- // for (var i = 0; i < queryresult.length; i++) {
- // console.log(queryresult[i]);
- // dvrlist.push(queryresult[i])
- // }
- // if (queryresult.length > 0) {
- // console.log("dvrlist12345", dvrlist);
- // res.send({
- // status: true,
- // data: [{
- // getdvrDataStatus: 0,
- // mesasge: "Data Found",
- // countdata: [{
- // no_of_visit: countdata[0].allcount,
- // no_of_completed: countdata[0].completed,
- // no_of_incompleted: countdata[0].incompleted,
- // no_of_contact: countdata[0].contactcount
- // }],
- // dvrlist
- // }],
- // error: " "
- // })
- // } else {
- // res.send({
- // status: false,
- // data: [{
- // getdvrDataStatus: '1',
- // mesasge: "Data Not Found"
- // }],
- // error: " "
- // })
- // }
- }
- }
- } else {
- console.log("in else part of bydefult");
- var dvrlist = [];
- const lastmonthDate = await getLastMonthDate();
- const currentDate = await getcurrentDate();
- console.log("lastmonthDate", lastmonthDate, "currentDate", currentDate);
- if (getcustomer_id.length > 0) {
- console.log("data present in custmer mapping table");
- const getcust_name = "select customer_id,customer_name from customer_master where customer_id in(" + getcustomer_id + ")";
- const getqueryresult1 = await db.executequery(getcust_name);
- console.log("getcust_name", getcust_name)
- console.log("getcust_name============>", getqueryresult1);
- for (var i = 0; i < getqueryresult1.length; i++) {
- getcustomer_name.push(getqueryresult1[i].customer_name);
- }
- console.log("getcustomer_name", getcustomer_name);
- if (getcustomer_name) {
- for (var i = 0; i < getcustomer_name.length; i++) {
- 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";
- dvrlist[i] = await db.executequery(query);
- }
- var plano = dvrlist.reduce((acc, el) => acc.concat(el), []);
- //console.log("plano",plano)
- dvrlist = plano;
- console.log("finalResult=================>", dvrlist);
- const countquery = "call SP_CountDashboard ('" + lastmonthDate + "' , '" + currentDate + "','" + login_id + "')";
- const queryresult1 = await db.executequery(countquery);
- console.log("queryresult1", countquery);
- var countdata = queryresult1[0];
- if (dvrlist.length > 0) {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '0',
- mesasge: "Data Found",
- countdata: [{
- no_of_visit: countdata[0].allcount,
- no_of_completed: countdata[0].completed,
- no_of_incompleted: countdata[0].incompleted,
- no_of_contact: countdata[0].contactcount
- }],
- dvrlist
- }],
- error: " "
- })
- } else {
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- }
- } else {
- console.log("data not present in custmer mapping table");
- res.send({
- status: false,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: " "
- })
- }
- }
- }
- }
- catch (err) {
- console.log(err)
- res.send({
- status: true,
- data: [],
- error: err,
- getdvrDataStatus: '1',
- })
- }
- }
- module.exports.createDvrEntry = async (req, res) => {
- const validationResp = await validation.createDvrentrycheck(req);
- const createdate = new Date();
- if (validationResp.status) {
- try {
- console.log(" req.body.login_id", req.body.created_by);
- const date_of_visit = new Date(req.body.visit_date);
- //const date_of_visit=req.body.visit_date;
- console.log("estvalue:::::::::::::::::::::::::::::::::::::::::::", req.body)
- 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)" +
- "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- 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]
- // console.log("query",query);
- //console.log("values",values);
- const res1 = await db.executevaluesquery(query, values);
- console.log("res1", res1);
- if (res1) {
- res.send({
- status: true,
- data: [{
- message: "Daily visit Entry created Successfully.",
- createDvrStatus: "0",
- exception: {
- errorid: "",
- errormessage: "No Errors"
- }
- }],
- errors: ""
- })
- } else {
- res.send({
- status: true,
- data: [{
- message: "",
- createDvrStatus: "1",
- exception: {
- errorid: "404",
- errormessage: "Bad request"
- }
- }],
- errors: ""
- })
- }
- }
- catch (err) {
- console.log(err)
- res.send({
- status: false,
- data: [{
- message: "",
- createDvrStatus: "1",
- exception: {
- errorid: "404",
- errormessage: "Bad request"
- }
- }],
- errors: ""
- })
- }
- } else {
- res.send(validationResp)
- }
- }
- module.exports.updatedvrDetails = async (req, res) => {
- const validationResp = await validation.updatedvrDetailscheck(req);
- const updatedDate = await getcurrentDate();
- if (validationResp.status) {
- try {
- 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 + "'";
- console.log("query", query);
- const queryresult = await db.executequery(query);
- console.log("queryresult", queryresult);
- if (queryresult) {
- res.send({
- status: true,
- data: [
- {
- getdvrDataStatus: '0',
- message: "Daliy visit Report Entry updated suceesfully."
- }
- ],
- errors: " "
- })
- } else {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '1',
- message: "Daliy visit Report Entry not updated. Please try again after some time!"
- }],
- errors: ""
- })
- }
- }
- catch (err) {
- console.log(err)
- res.send({
- status: true, data: [], errors: err
- })
- }
- } else {
- res.send(validationResp)
- }
- }
- module.exports.createCustomerentry = async (req, res) => {
- const validationResp = await validation.createCustomerentrycheck(req);
- const createdate = new Date();
- if (validationResp.status) {
- try {
- const query = "INSERT INTO customer_master(customer_name,created_by,created_on)" +
- "VALUES(?,?,?)";
- const values = [req.body.customer_name, req.body.created_by, createdate]
- const res3 = await db.executevaluesquery(query, values);
- //console.log("res1", res1);
- if (res3) {
- res.send({
- message: "Customer Entry created Successfully ",
- createcustomerStatus: "0",
- exception: {
- errorid: "",
- errormessage: "No Errors"
- }
- })
- } else {
- res.send({
- message: "",
- createStatus: "1",
- exception: {
- errorid: "404",
- errormessage: "Bad request"
- }
- })
- }
- }
- catch (err) {
- console.log(err)
- res.send({
- status: true, data: []
- })
- }
- } else {
- res.send(validationResp)
- }
- }
- module.exports.updateContactDetails = async (req, res) => {
- const validationResp = await validation.updateContactDetailscheck(req);
- const updatedDate = await getcurrentDate();
- if (validationResp.status) {
- try {
- 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 + "'";
- console.log("query", query);
- const queryresult = await db.executequery(query);
- console.log("queryresult", queryresult);
- if (queryresult) {
- res.send({
- updateContactStatus: '0',
- mesasge: "Contact Entry updated suceesfully."
- })
- } else {
- res.send({
- updateContactStatus: '1',
- mesasge: "Contact Entry not updated."
- })
- }
- }
- catch (err) {
- console.log(err)
- res.send({
- status: true, data: []
- })
- }
- } else {
- res.send(validationResp)
- }
- }
- module.exports.updateCustomerDetails = async (req, res) => {
- const validationResp = await validation.updateCustomerDetailscheck(req);
- const updatedDate = await getcurrentDate();
- if (validationResp.status) {
- try {
- const query = "UPDATE customer_master SET customer_id = '" + req.body.customer_id + "', updated_on= '" + updatedDate + "' where customer_master= '" + req.body.contact_master + "'";
- console.log("query", query);
- const queryresult = await db.executequery(query);
- console.log("queryresult", queryresult);
- if (queryresult) {
- res.send({
- updateCustomerStatus: '0',
- mesasge: "Customer Entry updated suceesfully."
- })
- } else {
- res.send({
- updateCustomerStatus: '1',
- mesasge: "Customer Entry not updated."
- })
- }
- }
- catch (err) {
- console.log(err)
- res.send({
- status: true, data: []
- })
- }
- } else {
- res.send(validationResp)
- }
- }
- module.exports.getlastestdvr = async (req, res) => {
- try {
- var insertedRecord = [];
- var startdate = new Date();
- var enddate = new Date();
- const format2 = "YYYY-MM-DD";
- startdate = moment(startdate).format(format2) + ' 00:00:01';
- enddate = moment(enddate).format(format2) + ' 23:59:59';
- var person_role = req.query.role;
- var login_id = req.query.login_id;
- console.log("login_id", login_id);
- if (person_role == 'admin') {
- //admin show all data
- 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";
- const queryresult = await db.executequery(query);
- console.log("query", query);
- for (var i = 0; i < queryresult.length; i++) {
- console.log(queryresult[i]);
- insertedRecord.push(queryresult[i])
- }
- //console.log("res1", res1);
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [{
- dvrData: insertedRecord
- }],
- error: ""
- })
- } else {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: ""
- })
- }
- } else {
- // other users
- console.log("other users");
- 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";
- const queryresult = await db.executequery(query);
- console.log("query", query);
- for (var i = 0; i < queryresult.length; i++) {
- console.log(queryresult[i]);
- insertedRecord.push(queryresult[i])
- }
- console.log("queryresult", queryresult);
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [{
- dvrData: insertedRecord
- }],
- error: ""
- })
- } else {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: ""
- })
- }
- }
- }
- catch (err) {
- console.log(err)
- res.send({
- status: true,
- data: [],
- getdvrDataStatus: '1',
- })
- }
- }
- module.exports.getcontactDetails = async (req, res) => {
- try {
- var insertedRecord = [];
- var startdate = new Date();
- var enddate = new Date();
- const format2 = "YYYY-MM-DD";
- startdate = moment(startdate).format(format2) + ' 00:00:01';
- enddate = moment(enddate).format(format2) + ' 23:59:59';
- var person_role = req.query.role;
- var login_id = req.query.login_id;
- if (person_role == 'admin') {
- //admin show all data
- 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";
- const queryresult = await db.executequery(query);
- console.log("query", query);
- for (var i = 0; i < queryresult.length; i++) {
- console.log(queryresult[i]);
- insertedRecord.push(queryresult[i])
- }
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [{
- conrtactData: insertedRecord
- }],
- error: ""
- })
- } else {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: ""
- })
- }
- } else {
- //others users
- 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";
- const queryresult = await db.executequery(query);
- console.log("query", query);
- for (var i = 0; i < queryresult.length; i++) {
- console.log(queryresult[i]);
- insertedRecord.push(queryresult[i])
- }
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [{
- conrtactData: insertedRecord
- }],
- error: ""
- })
- } else {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: ""
- })
- }
- }
- } catch (err) {
- console.log(err)
- res.send({
- status: true,
- data: [],
- getdvrDataStatus: '1',
- })
- }
- }
- module.exports.getsalePersonList = async (req, res) => {
- console.log("in getsalePersonList");
- try {
- var salePerson = [];
- var full_name = [];
- const query = "SELECT user_id,first_name,last_name from user_master;";
- const queryresult = await db.executequery(query);
- if (queryresult.length > 0) {
- for (var i = 0; i < queryresult.length; i++) {
- console.log("queryresult", queryresult[i])
- salePerson.push(queryresult[i]);
- }
- }
- console.log("salePerson", salePerson);
- res.send({
- status: true,
- data: [{
- salePerson: salePerson
- }],
- error: ""
- })
- } catch (err) {
- console.log(err)
- res.send({
- status: true, data: [], error: err
- })
- }
- }
- module.exports.getCustcontactDetails = async (req, res) => {
- try {
- var contactdetails = [];
- var customer_id = req.query.customer_id;
- var check_api = req.query.passid;
- var passing_id;
- console.log("customer_id", customer_id);
- console.log("check api", check_api);
- if (check_api == undefined) {
- console.log("pass customer name");
- const query = "SELECT customer_id,customer_name FROM customer_master where customer_name= '" + customer_id + "' ";
- const queryresult = await db.executequery(query);
- console.log("queryresult", queryresult);
- console.log("result------>", queryresult[0].customer_id);
- passing_id = queryresult[0].customer_id;
- 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";
- const queryresult_id = await db.executequery(query_id);
- console.log("query", query);
- for (var i = 0; i < queryresult_id.length; i++) {
- console.log(queryresult_id[i]);
- contactdetails.push(queryresult_id[i])
- }
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [{
- conrtactData: contactdetails
- }],
- error: ""
- })
- } else {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: ""
- })
- }
- } else {
- console.log("pass number");
- if (customer_id == 0) {
- console.log("getting all contact data");
- 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";
- const queryresult = await db.executequery(query);
- console.log("query", query);
- for (var i = 0; i < queryresult.length; i++) {
- console.log(queryresult[i]);
- contactdetails.push(queryresult[i])
- }
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [{
- conrtactData: contactdetails
- }],
- error: ""
- })
- } else {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: ""
- })
- }
- } else {
- console.log("getting only specific customer contact data");
- 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";
- const queryresult = await db.executequery(query);
- console.log("query", query);
- for (var i = 0; i < queryresult.length; i++) {
- console.log(queryresult[i]);
- contactdetails.push(queryresult[i])
- }
- if (queryresult.length > 0) {
- res.send({
- status: true,
- data: [{
- conrtactData: contactdetails
- }],
- error: ""
- })
- } else {
- res.send({
- status: true,
- data: [{
- getdvrDataStatus: '1',
- mesasge: "Data Not Found"
- }],
- error: ""
- })
- }
- }
- }
- } catch (err) {
- console.log(err)
- res.send({
- status: true,
- data: [],
- getdvrDataStatus: '1',
- })
- }
- }
- module.exports.createUpdateCustomerentry = async (req, res) => {
- const validationResp = await validation.createCustomerentrycheck(req);
- const createdate = new Date();
- if (validationResp.status) {
- try {
- if (req.body.action == 'insert') {
- console.log("customer added");
- const checkdub = "select * from customer_master where customer_name='" + req.body.customer_name + "'";
- const checkqueryresult = await db.executequery(checkdub);
- console.log("checkqueryresult", checkqueryresult.length)
- if (checkqueryresult.length > 0) {
- //allready all present
- res.send({
- status: false,
- data: [],
- errors: "Customer Entry allready Exit ! Please Enter Correct Customer Name"
- })
- } else {
- //data not is present
- const query = "INSERT INTO customer_master(customer_name,created_by,created_on)" +
- "VALUES(?,?,?)";
- const values = [req.body.customer_name, req.body.created_by, createdate]
- const res3 = await db.executevaluesquery(query, values);
- console.log("response", res3);
- if (res3) {
- const query = "select customer_id from customer_master order by customer_id desc limit 1";
- const queryresult = await db.executequery(query);
- console.log("query result----->", queryresult);
- console.log("query result----->", queryresult[0].customer_id);
- if (queryresult) {
- // const query = "select customer_id from customer_master order by customer_id desc limit 1";
- // const queryresult = await db.executequery(query);
- var sale_person = req.body.sale_person;
- var name = sale_person.split(" ");
- console.log("name", name);
- var first_name = name[0];
- var last_name = name[1];
- console.log(first_name, last_name);
- const queryuserID = "SELECT user_id FROM user_master where first_name='" + first_name + "' and last_name= '" + last_name + "'";
- console.log("queryuserID", queryuserID);
- const queryresultID = await db.executequery(queryuserID);
- console.log("queryresultID", queryresultID);
- const finalquery = "INSERT INTO customer_user_mapping(customer_id,user_id,created_by,created_on)" +
- "VALUES(?,?,?,?)";
- const values = [queryresult[0].customer_id, queryresultID[0].user_id, req.body.created_by, createdate]
- const res3 = await db.executevaluesquery(finalquery, values);
- console.log("res3", res3);
- if (res3) {
- res.send({
- status: true,
- data: [{
- createcustomerStatus: "0",
- message: "Customer Entry created Successfully!",
- lastinsertedData: req.body.customer_name,
- exception: {
- errorid: "",
- errormessage: "No Errors"
- }
- }],
- error: " "
- })
- } else {
- res.send({
- status: false,
- data: [{
- message: "Customer Entry Not created",
- createcustomerStatus: "1",
- exception: {
- errorid: "404",
- errormessage: "Bad request"
- }
- }],
- error: ""
- })
- }
- }
- } else {
- res.send({
- status: true,
- data: [],
- errors: "Bad Request"
- })
- }
- }
- } else {
- console.log("customer update");
- 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 + "'";
- console.log("query", query);
- const queryresult = await db.executequery(query);
- console.log("queryresult", queryresult);
- //dates = searchfilter.split("-");
- var saleData = req.body.sale_person.split(" ");
- console.log("saleData");
- //select user_id from user_master where first_name= "" and last_name="";
- if (queryresult) {
- const getsaleperson = "select user_id from user_master where first_name= '" + saleData[0] + "' and last_name= '" + saleData[1] + "'";
- const getqueryresult = await db.executequery(getsaleperson);
- if (getqueryresult) {
- 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";
- const checkexcutequer = await db.executequery(checkdupli);
- if (checkexcutequer[0].user_id == getqueryresult[0].user_id) {
- //same user for customer update
- console.log("same user for customer update");
- console.log("database date", formatDateAsPer(checkexcutequer[0].effectivedate_to));
- console.log("req body", req.body.effectivedate_to)
- if (req.body.effectivedate_to.length > 0) {
- if (req.body.effectivedate_from > req.body.effectivedate_to) {
- res.send({
- status: false,
- data: [],
- errors: "Please enter correct Effective From Date! Make sure Efffective From Date is less than Effective To Date"
- })
- } else {
- const query = "INSERT INTO customer_user_mapping(customer_id,user_id,effiectivedate_from,effectivedate_to,created_by,created_on)" +
- "VALUES(?,?,?,?,?,?)";
- 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]
- const res3 = await db.executevaluesquery(query, values);
- console.log("response--------->", res3);
- if (res3) {
- res.send({
- status: true,
- data: [{
- message: "Customer Entry Update Successfully!",
- createcustomerStatus: "0",
- lastinsertedData: req.body.customer_name,
- exception: {
- errorid: "",
- errormessage: "No Errors"
- }
- }],
- error: " "
- })
- } else {
- res.send({
- status: true,
- data: [{
- message: "Customer Entry Not Updated.",
- createStatus: "1",
- exception: {
- errorid: "404",
- errormessage: "Bad request"
- }
- }],
- error: ""
- })
- }
- }
- } else {
- //same user id for effective different date.
- const query = "INSERT INTO customer_user_mapping(customer_id,user_id,effiectivedate_from,effectivedate_to,created_by,created_on)" +
- "VALUES(?,?,?,?,?,?)";
- 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]
- const res3 = await db.executevaluesquery(query, values);
- console.log("response--------->", res3);
- if (res3) {
- res.send({
- status: true,
- data: [{
- message: "Customer Entry Update Successfully!",
- createcustomerStatus: "0",
- lastinsertedData: req.body.customer_name,
- exception: {
- errorid: "",
- errormessage: "No Errors"
- }
- }],
- error: " "
- })
- } else {
- res.send({
- status: true,
- data: [{
- message: "Customer Entry Not Updated.",
- createStatus: "1",
- exception: {
- errorid: "404",
- errormessage: "Bad request"
- }
- }],
- error: ""
- })
- }
- }
- } else {
- //other user for customer update
- if (req.body.effectivedate_to.length > 0 && checkexcutequer[0].effectivedate_to.length > 0) {
- if (req.body.effectivedate_to == formatDateAsPer(checkexcutequer[0].effectivedate_to)) {
- res.send({
- status: false,
- data: [],
- errors: "Please enter correct Effective To Date are same for other sales Person "
- })
- }
- } else if (req.body.effectivedate_to.length > 0) {
- if (req.body.effectivedate_from > req.body.effectivedate_to) {
- res.send({
- status: false,
- data: [],
- errors: "Please enter correct Effective From Date! Make sure Efffective From Date is less than Effective To Date"
- })
- } else if (req.body.effectivedate_from == req.body.effectivedate_to) {
- res.send({
- status: false,
- data: [],
- errors: "Please enter correct Effective From and Effection To Date ! Both Dates are same"
- })
- } else {
- const query = "INSERT INTO customer_user_mapping(customer_id,user_id,effiectivedate_from,effectivedate_to,created_by,created_on)" +
- "VALUES(?,?,?,?,?,?)";
- 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]
- const res3 = await db.executevaluesquery(query, values);
- console.log("response--------->", res3);
- if (res3) {
- res.send({
- status: true,
- data: [{
- message: "Customer Entry Update Successfully!",
- createcustomerStatus: "0",
- lastinsertedData: req.body.customer_name,
- exception: {
- errorid: "",
- errormessage: "No Errors"
- }
- }],
- error: " "
- })
- } else {
- res.send({
- status: true,
- data: [{
- message: "Customer Entry Not Updated",
- createStatus: "1",
- exception: {
- errorid: "404",
- errormessage: "Bad request"
- }
- }],
- error: ""
- })
- }
- }
- } else {
- //all ok
- const query = "INSERT INTO customer_user_mapping(customer_id,user_id,effiectivedate_from,effectivedate_to,created_by,created_on)" +
- "VALUES(?,?,?,?,?,?)";
- 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]
- const res3 = await db.executevaluesquery(query, values);
- console.log("response--------->", res3);
- if (res3) {
- res.send({
- status: true,
- data: [{
- message: "Customer Entry Update Successfully!",
- createcustomerStatus: "0",
- lastinsertedData: req.body.customer_name,
- exception: {
- errorid: "",
- errormessage: "No Errors"
- }
- }],
- error: " "
- })
- } else {
- res.send({
- status: true,
- data: [{
- message: "Customer Entry Not Updated",
- createStatus: "1",
- exception: {
- errorid: "404",
- errormessage: "Bad request"
- }
- }],
- error: ""
- })
- }
- }
- }
- }
- }
- }
- }
- catch (err) {
- console.log(err)
- res.send({
- status: true, data: [],
- errors: err
- })
- }
- } else {
- res.send(validationResp)
- }
- }
- module.exports.deletedvrEntry = async (req, res) => {
- try {
- //DELETE FROM table_name WHERE condition;
- console.log("req.body", req.body);
- const updatedDate = await getcurrentDate();
- 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 + "";
- const checkqueryresult = await db.executequery(query);
- console.log("checkqueryresult", checkqueryresult)
- console.log("eeeeeeee", checkqueryresult.affectedRows);
- if (checkqueryresult) {
- //entry not deleted
- res.send({
- status: true,
- data: [{
- message: "DVR Entry Deleted Successfully!",
- deleteStatus: "0"
- }],
- error: ""
- })
- } else {
- //entry deleted
- res.send({
- status: true,
- data: [{
- message: "DVR Entry Not Deleted.",
- deleteStatus: "1",
- exception: {
- errorid: "404",
- errormessage: "Bad request"
- }
- }],
- error: ""
- })
- }
- } catch (err) {
- console.log(err)
- res.send({
- status: true,
- data: [],
- getdvrDataStatus: '1',
- })
- }
- }
- // module.exports.mappingCustomerDetails = async (req, res) => {
- // // Validate the request
- // const validationResp = await validation.mappingCustomerDetailsCheck(req);
- // if (validationResp.status) {
- // try {
- // // Extract salesperson's name
- // const sale_person = req.body.sale_person;
- // const name = sale_person.split(" ");
- // const first_name = name[0];
- // const last_name = name[1];
- // console.log("Extracted names:", first_name, last_name);
- // // SQL query to get user_id from user_master
- // const queryUserID = "SELECT user_id FROM user_master WHERE first_name='" + first_name + "' AND last_name='" + last_name + "'";
- // console.log("queryUserID", queryUserID);
- // const queryResultID = await db.executequery(queryUserID);
- // console.log("User ID query result:", queryResultID);
- // if (queryResultID.length > 0) {
- // res.send({
- // status: true,
- // data: {
- // user_id: queryResultID[0].user_id
- // },
- // error: null
- // });
- // } else {
- // res.send({
- // status: false,
- // data: [],
- // errors: "No user found with the specified name."
- // });
- // }
- // } catch (err) {
- // console.error("Error occurred:", err);
- // res.send({
- // status: false,
- // data: [],
- // errors: "An error occurred while fetching the user ID."
- // });
- // }
- // } else {
- // res.send(validationResp);
- // }
- // }
- module.exports.mappingCustomerDetails = async (req, res) => {
- // Validate the request
- console.log("sale_", req.query.sale_person)
- const validationResp = await validation.mappingCustomerDetailsCheck(req);
- if (validationResp.status) {
- try {
- const sale_person = req.query.sale_person;
- const name = sale_person.split(" ");
- const first_name = name[0];
- const last_name = name[1];
- console.log("Extracted names:", first_name, last_name);
- // SQL query to get user_id from user_master
- const queryUserID = "SELECT user_id FROM user_master WHERE first_name='" + first_name + "' AND last_name='" + last_name + "'";
- console.log("queryUserID", queryUserID);
- const queryResultID = await db.executequery(queryUserID);
- console.log("User ID query result:", queryResultID);
- if (queryResultID.length > 0) {
- const userId = queryResultID[0].user_id;
- // SQL query to get customer details associated with the user_id
- const queryCustomerDetails = `
- SELECT c.customer_id, c.customer_name, u.user_id
- FROM customer_master c
- JOIN customer_user_mapping u ON c.customer_id = u.customer_id
- WHERE u.user_id = '${userId}'`;
- console.log("queryCustomerDetails", queryCustomerDetails);
- const customerDetailsResult = await db.executequery(queryCustomerDetails);
- console.log("Customer details result:", customerDetailsResult);
- if (customerDetailsResult.length > 0) {
- res.send({
- status: true,
- data: customerDetailsResult,
- error: null
- });
- } else {
- res.send({
- status: false,
- data: [],
- errors: "No customer details found for the specified salesperson."
- });
- }
- } else {
- res.send({
- status: false,
- data: [],
- errors: "No user found with the specified name."
- });
- }
- } catch (err) {
- console.error("Error occurred:", err);
- res.send({
- status: false,
- data: [],
- errors: "An error occurred while fetching the customer details."
- });
- }
- } else {
- res.send(validationResp);
- }
- }
- module.exports.mappingFuncIDToPersonNames = async (req, res) => {
- // Validate the request
- console.log("func_id_", req.query.func_id);
- const validationResp = await validation.mappingFuncIDToPersonNamesCheck(req);
- if (validationResp.status) {
- try {
- const func_id = req.query.func_id;
-
- // SQL query to get all persons mapped to the given func_id
- const queryFunctionPersonMapping = `
- SELECT f.func_id, p.person_name
- FROM dvr_local.function_person_mapping fp
- JOIN dvr_local.function_details f ON f.func_id = fp.func_id
- JOIN dvr_local.person_details p ON p.person_id = fp.person_id
- WHERE fp.func_id = '${func_id}'`;
- console.log("queryFunctionPersonMapping", queryFunctionPersonMapping);
- // Use parameterized query to avoid SQL injection
- const queryResult = await db.executequery(queryFunctionPersonMapping, [func_id]);
- console.log("Function-person mapping query result:", queryResult);
- if (queryResult.length > 0) {
- res.send({
- status: true,
- data: queryResult,
- error: null
- });
- } else {
- res.send({
- status: false,
- data: [],
- errors: "No persons are mapped to the specified function ID."
- });
- }
- } catch (err) {
- console.error("Error occurred:", err);
- res.send({
- status: false,
- data: [],
- errors: "An error occurred while fetching the person details for the specified function ID."
- });
- }
- } else {
- res.send(validationResp);
- }
- };
- function getLastWeeksDate() {
- const now = new Date();
- const format2 = "YYYY-MM-DD";
- const date = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
- // console.log("date", date);
- const dateTime2 = moment(date).format(format2) + ' 00:00:00';
- // console.log("date------>", dateTime2);
- return dateTime2;
- }
- function getcurrentDate() {
- const now = new Date();
- const format2 = "YYYY-MM-DD";
- const dateTime2 = moment(now).format(format2) + ' 23:59:59';
- // console.log("date------>", dateTime2);
- return dateTime2;
- }
- function getLastMonthDate() {
- const now = new Date();
- const format2 = "YYYY-MM-DD";
- const date = new Date(now.getFullYear(), now.getMonth() - 1, 1);
- // console.log("date", date);
- const dateTime2 = moment(date).format(format2) + ' 00:00:00';
- //console.log("date------>", dateTime2);
- return dateTime2;
- }
- function getLastYearDate() {
- const now = new Date();
- const format2 = "YYYY-MM-DD";
- const date = new Date(now.setFullYear(now.getFullYear() - 1));
- // console.log("date", date);
- const dateTime2 = moment(date).format(format2) + ' 00:00:00';
- //console.log("date------>", dateTime2);
- return dateTime2;
- }
|