| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188 |
- <?php
- /****************************
- * File : manager.php
- * Author : Cygnusa
- * @2018
- ****************************/
- //SECURITY
- if (!defined('APPLICATION_PATH')) {
- exit('No direct script access allowed');
- }
- define('MIN_ASSESSMENT_PERCENT', "60");
- class manager
- {
- //FUNCTION LISTS
- public function __construct($parent)
- {
- //GET PAGE MESSAGE
- $this->page_data = globalfunc::getMessage($parent, $parent->lang, 'manager');
- if (count($parent->params) == 0) {
- // $this->dashboardfunc($parent);
- } else {
- $qry_params = explode("?", $parent->params[0]);
- $parameter_val = strtolower($qry_params[0]);
- switch ($parameter_val) {
- case "zone":
- case "region":
- case "area":
- case "dealer":
- case "salesreport": //
- case "certifieddsereport": //
- case "assessmentlist":
- case "assessmentreport": //
- case "salesleaderboardreport": //
- case "assessmentleaderboardreport": //
- case "assessmentleaderboardreportnew":
- case "registrationreport": // OLD ONE REPLACED WITH newregistrationreport
- case "coursereport": //
- case "usercoursereport":
- case "usertopicreport":
- case "salestarget": //
- case "salestargetupdate":
- case "newsalestargetupdate":
- case "surveylist":
- case "surveyreport":
- case "surveyuserreport":
- case "uploadtargetsale":
- case "newregistrationreport":
- case "newcoursereport":
- case "newsurveyreport":
- case "newsalesreport":
- case "newcertifieddsereport":
- case "newassessmentreport":
- case "newsalestarget":
- case "newsalesleaderboardreport":
- case "newassessmentleaderboardreport":
- case "asmassessmentreport":
- case "rmassessmentreport":
- case "zmassessmentreport":
- case "trainerassessmentreport":
- case "newsalestargetreport":
- case "managersalestargetreport":
- case "userlist":
- case "dealerlist":
- //case "saletargetapprovallist":
- case "userstatusupdate":
- case "zmcoursereport":
- case "trainercoursereport":
- case "rmcoursereport":
- case "amcoursereport":
- case "dealercoursereport":
- $this->$parameter_val($parent);
- break;
- default:
- break;
- }
- }
- $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
- }
- private function getmanagerconditon_arr($parent)
- {
- projectfunc::authorizedRole($parent, array('3', '4', '5', '6', '7', '14'));
- $zmemail = escape_str($parent->_request["zmemail"]);
- $rmemail = escape_str($parent->_request["rmemail"]);
- $amemail = escape_str($parent->_request["amemail"]);
- $dealer_cond = array();
- if ($parent->current_user_role == '3') {
- $REQUEST_KEYS = array('zmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- if ($zmemail != 'all' && $zmemail != '') {
- $dealer_cond[] = "zm_email='" . $zmemail . "'";
- }
- if ($rmemail != 'all' && $rmemail != '') {
- $dealer_cond[] = "rm_email='" . $rmemail . "'";
- }
- if ($amemail != 'all' && $amemail != '') {
- $dealer_cond[] = "am_email='" . $amemail . "'";
- }
- } else if ($parent->current_user_role == '4') {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $dealer_cond[] = "zm_email='" . $parent->current_user_data->emailid . "'";
- if ($rmemail != 'all' && $rmemail != '') {
- $dealer_cond[] = "rm_email='" . $rmemail . "'";
- }
- if ($amemail != 'all' && $amemail != '') {
- $dealer_cond[] = "am_email='" . $amemail . "'";
- }
- } else if ($parent->current_user_role == '5') {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $dealer_cond[] = (count($trainer_arr) > 0) ? "zone='" . $trainer_arr[0]->zone . "'" : "zone='0'";
- if ($rmemail != 'all' && $rmemail != '') {
- $dealer_cond[] = "rm_email='" . $rmemail . "'";
- }
- if ($amemail != 'all' && $amemail != '') {
- $dealer_cond[] = "am_email='" . $amemail . "'";
- }
- } else if ($parent->current_user_role == '6') {
- $REQUEST_KEYS = array('amemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $dealer_cond[] = "rm_email='" . $parent->current_user_data->emailid . "'";
- if ($amemail != 'all' && $amemail != '') {
- $dealer_cond[] = "am_email='" . $amemail . "'";
- }
- } else if ($parent->current_user_role == '7') {
- $dealer_cond[] = "am_email='" . $parent->current_user_data->emailid . "'";
- } else if ($parent->current_user_role == '14') {
- $dealer_cond[] = "dealer_code='" . $parent->current_user_data->dealer_code . "'";
- }
- return $dealer_cond;
- }
- /* /////////////////////////////// ZONE MANAGER //////////////////////////////////////////////// */
- private function zone($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $rmmanager = isset($parent->_request["rmemail"]) ? escape_str($parent->_request["rmemail"]) : '';
- if ($rmmanager) {
- $query_cond .= " AND rm_email='" . $rmmanager . "'";
- }
- //GET DATA
- $query_str = "SELECT zm_name as name,zm_email as email,zone FROM " . DMS_DEALER . " WHERE zm_name!='' AND status='1' AND is_deleted='0' " . $query_cond . " GROUP BY zm_email ORDER BY zm_name ASC";
- $query_arr = $parent->getQueryValue($query_str);
- //LOG
- $logstr = 'ZONE MANAGER';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'data' => $query_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// REGION MANAGER //////////////////////////////////////////////// */
- private function region($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $query_cond = '';
- if ($parent->current_user_role == '5') {
- $zonename = isset($parent->_request["zonename"]) ? escape_str($parent->_request["zonename"]) : '';
- $query_cond .= " AND zone='" . $zonename . "'";
- } else {
- $zonemanager = isset($parent->_request["zone"]) ? escape_str($parent->_request["zone"]) : '';
- if ($zonemanager) {
- $query_cond .= " AND zm_email='" . $zonemanager . "'";
- }
- $ammanager = isset($parent->_request["amemail"]) ? escape_str($parent->_request["amemail"]) : '';
- if ($ammanager) {
- $query_cond .= " AND am_email='" . $ammanager . "'";
- }
- }
- //GET DATA
- $query_str = "SELECT rm_name as name,rm_email as email FROM " . DMS_DEALER . " WHERE rm_name!='' AND status='1' AND is_deleted='0' " . $query_cond . " GROUP BY rm_email ORDER BY rm_name ASC";
- $query_arr = $parent->getQueryValue($query_str);
- //LOG
- $logstr = 'REGION MANAGER';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'data' => $query_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// AREA MANAGER //////////////////////////////////////////////// */
- private function area($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $query_cond = '';
- $zonemanager = isset($parent->_request["zone"]) ? escape_str($parent->_request["zone"]) : '';
- if ($zonemanager) {
- $query_cond .= " AND zm_email='" . $zonemanager . "'";
- }
- $regionmanager = isset($parent->_request["region"]) ? escape_str($parent->_request["region"]) : '';
- if ($regionmanager) {
- $query_cond .= " AND rm_email='" . $regionmanager . "'";
- }
- $dealer_code = isset($parent->_request["dealer_code"]) ? escape_str($parent->_request["dealer_code"]) : '';
- if ($dealer_code) {
- $query_cond .= " AND dealer_code='" . $dealer_code . "'";
- }
- //GET DATA
- $query_str = "SELECT am_name as name,am_email as email FROM " . DMS_DEALER . " WHERE am_name!='' AND status='1' AND is_deleted='0' " . $query_cond . " GROUP BY am_email ORDER BY am_name ASC";
- $query_arr = $parent->getQueryValue($query_str);
- //LOG
- $logstr = 'AREA MANAGER';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'data' => $query_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// ZONE MANAGER //////////////////////////////////////////////// */
- private function dealer($parent)
- {
- globalfunc::checkMethodType($parent, array('GET'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- //GET DATA
- $query_str = "SELECT dealer_code,dealer_name,CONCAT(dealer_name,' - ',dealer_code) as title FROM " . DMS_DEALER . " WHERE am_email='" . $parent->current_user_data->emailid . "' AND status=1 AND is_deleted='0'";
- $query_arr = $parent->getQueryValue($query_str);
- $query_ar = (count($query_arr) > 0) ? $query_arr : array();
- //LOG
- $logstr = 'DEALER MANAGER';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'data' => $query_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// SALES REPORT //////////////////////////////////////////////// */
- private function salesreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 3);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $year_data = escape_str($parent->params[1]);
- $last_data = escape_str($parent->params[2]);
- $last_data_arr = explode('?', $last_data);
- $month_data = escape_str(trim($last_data_arr[0]));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[2]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- //AREA MANAGER SELF
- if ($parent->current_user_role == '7') {
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- $emailid = $userdata->emailid;
- } else {
- //AREA MANAGER LEVEL REPORT
- $role = '7';
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('area' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $area_manager = escape_str($parent->_request["area"]);
- $emailid = $area_manager;
- }
- $user_cond = "";
- switch ($role) {
- case '3': //HO Manager
- $user_cond .= " AND d.status='1' AND d.is_deleted='0'";
- break;
- case '4': //Zonal Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE zm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '5': //Trainer
- $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.emailid='" . $emailid . "' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $zone_cond .= (count($trainer_arr) > 0) ? " zone='" . $trainer_arr[0]->zone . "'" : " zone='0'";
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE " . $zone_cond . " AND status='1' AND is_deleted='0')";
- break;
- case '6': //Regional Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE rm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '7': //Area Manager
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " AND dealer_code='" . $parent->current_user_data->dealer_code . "'";
- }
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE am_email='" . $emailid . "' " . $dealer_code_cond . " AND status='1' AND is_deleted='0' )";
- break;
- // case '9': break;
- // case '10': break;
- // case '11': break;
- // case '12': break;
- // case '13': break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[2]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.smpin,u.emp_code,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.status='1' AND u.is_deleted='0' AND u.role>7 AND u.role<14 " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- $query_modelarr = $parent->selectQuery(TABLE_MODEL, " model_name,model_image ", "model_is_target=1 AND user_type=0 ORDER BY model_id", "");
- if (count($user_arr) > 0) {
- foreach ($user_arr as $mkey => $res_user) {
- //TARGET
- $user_target = projectfunc::userSalesTarget($parent, $res_user->userid, '', $year_data, $month_data);
- //ACHIEVED
- $user_achieved = projectfunc::userSalesAchieved($parent, $res_user->userid, '', $year_data, $month_data);
- $sales = array('target' => $user_target, 'achieved' => $user_achieved);
- $user_arr[$mkey]->sales = $sales;
- $model_data_arr = array();
- //GET MODEL
- if ($query_modelarr['nr']) {
- foreach ($query_modelarr['result'] as $key => $res) {
- $res->model_image_url = ($res->model_image != '') ? SITE_URL . "hypermupload/model/" . $res->model_image : NOIMAGE_URL;
- $user_target = projectfunc::userSalesTarget($parent, $res_user->userid, $res->model_name, $year_data, $month_data);
- if ($user_target > 0) {
- $res->target = $user_target;
- $res->achieved = projectfunc::userSalesAchieved($parent, $res_user->userid, $res->model_name, $year_data, $month_data);
- $model_data_arr[] = (array) $res;
- }
- }
- }
- $user_arr[$mkey]->model_data = $model_data_arr;
- }
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.status='1' AND u.is_deleted='0' AND u.role>7 AND u.role<14 " . $user_cond . " LIMIT 1 ";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'MANAGER SALES REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'month' => date('M', strtotime('2018-' . $month_data . "-01")), 'year' => $year_data, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// CERTIFIED DSE REPORT //////////////////////////////////////////////// */
- private function certifieddsereport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- //AREA MANAGER SELF
- if ($parent->current_user_role == '7') {
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- $emailid = $userdata->emailid;
- } else {
- //AREA MANAGER LEVEL REPORT
- $role = '7';
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('area' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $area_manager = escape_str($parent->_request["area"]);
- $emailid = $area_manager;
- }
- $user_cond = "";
- switch ($role) {
- case '3': //HO Manager
- $user_cond .= " AND d.status='1' AND d.is_deleted='0'";
- break;
- case '4': //Zonal Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE zm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '5': //Trainer
- $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.emailid='" . $emailid . "' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $zone_cond .= (count($trainer_arr) > 0) ? " zone='" . $trainer_arr[0]->zone . "'" : " zone='0'";
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE " . $zone_cond . " AND status='1' AND is_deleted='0')";
- break;
- case '6': //Regional Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE rm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '7': //Area Manager
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " AND dealer_code='" . $parent->current_user_data->dealer_code . "'";
- }
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE am_email='" . $emailid . "' " . $dealer_code_cond . " AND status='1' AND is_deleted='0')";
- break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.smpin,u.emp_code,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.status='1' AND u.is_deleted='0' AND u.role>7 AND u.role<14 " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $mkey => $res_user) {
- $user_arr[$mkey]->learning = projectfunc::userLearningLevel($parent, $res_user->userid);
- }
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(u.userid) as ucount FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.status='1' AND u.is_deleted='0' AND u.role>7 AND u.role<14 " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'MANAGER CERTIFIED DSE REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// ASSESSMENT LIST //////////////////////////////////////////////// */
- private function assessmentlist($parent)
- {
- globalfunc::checkMethodType($parent, array('GET'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- $query_cond = "";
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- if (isset($filter_arr) && isset($filter_arr['role'])) {
- $user_type = $filter_arr['role'];
- }
- if (isset($filter_arr) && isset($filter_arr['atype'])) {
- switch ($filter_arr['atype']) {
- case '0':$user_cond = " AND atype='" . $filter_arr['atype'] . "'";
- break;
- case '1':$user_cond = " AND atype='" . $filter_arr['atype'] . "'";
- break;
- default:break;
- }
- }
- switch ($user_type) {
- case 'DSE':
- $user_cond .= ' AND user_type=0 ';
- break;
- case 'IDSE':
- $user_cond .= ' AND user_type=1 ';
- break;
- case 'HO':
- $user_cond .= ' AND user_type=2 ';
- break;
- case 'ZM':
- $user_cond .= ' AND user_type=3 ';
- break;
- case 'TR':
- $user_cond .= ' AND user_type=4 ';
- break;
- case 'RM':
- $user_cond .= ' AND user_type=5 ';
- break;
- case 'AM':
- $user_cond .= ' AND user_type=6 ';
- break;
- case 'DR':
- $user_cond .= ' AND user_type=7 ';
- break;
- case 'CE':
- $user_cond .= ' AND user_type=8 ';
- break;
- default:
- $user_cond .= ' AND user_type=0 ';
- break;
- }
- switch ($role) {
- case '3': //HO Manager
- $query_cond .= "";
- break;
- case '4': //Zonal Manager
- $get_zone_str = "SELECT zone FROM " . DMS_DEALER . " WHERE zm_email='" . $userdata->emailid . "' AND status='1' AND is_deleted='0' GROUP BY zone ";
- $zone_arr = $parent->getQueryValue($get_zone_str);
- if (count($zone_arr) > 0) {
- foreach ($zone_arr as $res_zone) {
- $zone_cond_arr[] = " filter_zone LIKE '%" . $res_zone->zone . "%'";
- }
- $query_cond .= " AND (filter_zone='' OR " . @implode(" OR ", $zone_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_zone='') ";
- }
- break;
- case '5': //Trainer
- $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $res_user->userid . "' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $query_cond = " AND (filter_zone='' OR filter_zone LIKE '%" . $trainer_arr[0]->zone . "%') ";
- break;
- case '6': //Regional Manager
- $get_city_str = "SELECT city,zone FROM " . DMS_DEALER . " WHERE rm_email='" . $userdata->emailid . "' AND status='1' AND is_deleted='0' GROUP BY city ";
- $city_arr = $parent->getQueryValue($get_city_str);
- if (count($city_arr) > 0) {
- $zone_arr = array();
- foreach ($city_arr as $res_city) {
- if (!in_array($res_city->zone, $zone_arr)) {
- $zone_arr[] = $res_city->zone;
- }
- $city_cond_arr[] = " filter_region LIKE '%" . $res_city->city . "%'";
- }
- $query_cond .= " AND ( filter_region='' OR " . @implode(" OR ", $city_cond_arr) . " ) ";
- if (count($zone_arr) > 0) {
- foreach ($zone_arr as $zone) {
- $zone_cond_arr[] = " filter_zone LIKE '%" . $zone . "%'";
- }
- $query_cond .= " AND (filter_zone='' OR " . @implode(" OR ", $zone_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_zone='') ";
- }
- } else {
- $query_cond .= " AND (filter_region='' AND filter_zone='') ";
- }
- break;
- case '7': //Area Manager
- $get_dealer_str = "SELECT dealer_code,city,zone FROM " . DMS_DEALER . " WHERE am_email='" . $userdata->emailid . "' AND status='1' AND is_deleted='0' GROUP BY dealer_code ";
- $dealer_arr = $parent->getQueryValue($get_dealer_str);
- if (count($dealer_arr) > 0) {
- $zone_arr = array();
- $city_arr = array();
- foreach ($dealer_arr as $res_dealer) {
- if (!in_array($res_dealer->zone, $zone_arr)) {
- $zone_arr[] = $res_dealer->zone;
- }
- if (!in_array($res_dealer->city, $city_arr)) {
- $city_arr[] = $res_dealer->city;
- }
- $dealer_cond_arr[] = " filter_dealer LIKE '%" . $res_dealer->dealer_code . "%'";
- }
- $query_cond .= " AND ( filter_dealer='' OR " . @implode(" OR ", $dealer_cond_arr) . " ) ";
- if (count($zone_arr) > 0) {
- foreach ($zone_arr as $zone) {
- $zone_cond_arr[] = " filter_zone LIKE '%" . $zone . "%'";
- }
- $query_cond .= " AND (filter_zone='' OR " . @implode(" OR ", $zone_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_zone='') ";
- }
- if (count($city_arr) > 0) {
- foreach ($city_arr as $city) {
- $city_cond_arr[] = " filter_region LIKE '%" . $city . "%'";
- }
- $query_cond .= " AND (filter_region='' OR " . @implode(" OR ", $city_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_region='') ";
- }
- } else {
- $query_cond .= " AND (filter_dealer='' AND filter_region='' AND filter_zone='') ";
- }
- break;
- case '14': //Dealer
- $get_dealer_str = "SELECT dealer_code,city,zone FROM " . DMS_DEALER . " WHERE dealer_code='" . $userdata->dealer_code . "' AND status='1' AND is_deleted='0' GROUP BY dealer_code ";
- $dealer_arr = $parent->getQueryValue($get_dealer_str);
- if (count($dealer_arr) > 0) {
- $zone_arr = array();
- $city_arr = array();
- foreach ($dealer_arr as $res_dealer) {
- if (!in_array($res_dealer->zone, $zone_arr)) {
- $zone_arr[] = $res_dealer->zone;
- }
- if (!in_array($res_dealer->city, $city_arr)) {
- $city_arr[] = $res_dealer->city;
- }
- $dealer_cond_arr[] = " filter_dealer LIKE '%" . $res_dealer->dealer_code . "%'";
- }
- $query_cond .= " AND ( filter_dealer='' OR " . @implode(" OR ", $dealer_cond_arr) . " ) ";
- if (count($zone_arr) > 0) {
- foreach ($zone_arr as $zone) {
- $zone_cond_arr[] = " filter_zone LIKE '%" . $zone . "%'";
- }
- $query_cond .= " AND (filter_zone='' OR " . @implode(" OR ", $zone_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_zone='') ";
- }
- if (count($city_arr) > 0) {
- foreach ($city_arr as $city) {
- $city_cond_arr[] = " filter_region LIKE '%" . $city . "%'";
- }
- $query_cond .= " AND (filter_region='' OR " . @implode(" OR ", $city_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_region='') ";
- }
- } else {
- $query_cond .= " AND (filter_dealer='' AND filter_region='' AND filter_zone='') ";
- }
- break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $data_arr = array();
- //GET COUNT
- $assessment_str = "SELECT assessmentid,assessmentname,atype,pass_score FROM " . TABLE_ASSESSMENT . " WHERE status='1' AND assettypeid='1' AND publisheddate<='" . NOW . "' " . $user_cond . $query_cond . " ORDER BY assessmentid ASC";
- $get_assessment_arr = $parent->getQueryValue($assessment_str);
- if (count($get_assessment_arr) > 0) {
- $data_arr = $get_assessment_arr;
- }
- //LOG
- $logstr = 'ASSESSMENT REPORT LIST';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// ASSESSMENT REPORT //////////////////////////////////////////////// */
- private function assessmentreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('assessmentid' => 'integer');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $assessmentid = escape_str($parent->_request["assessmentid"]);
- $user_cond = "";
- $dealer_code_cond = '';
- //AREA MANAGER SELF
- if ($parent->current_user_role == '7') {
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- $emailid = $userdata->emailid;
- } else {
- //AREA MANAGER LEVEL REPORT
- $role = '7';
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('area' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $area_manager = escape_str($parent->_request["area"]);
- $emailid = $area_manager;
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " AND dealer_code='" . $parent->current_user_data->dealer_code . "'";
- }
- }
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE am_email='" . $emailid . "' " . $dealer_code_cond . " AND status='1' AND is_deleted='0')";
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.smpin,u.emp_code,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.status='1' AND u.is_deleted='0' AND u.role>7 AND u.role<14 AND au.assessmentid='" . $assessmentid . "' " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $mkey => $res_user) {
- $exam_highscore_str = "SELECT * FROM " . TABLE_ASSESSMENT_USER . " WHERE assessmentid='" . $assessmentid . "' AND userid='" . $res_user->userid . "' LIMIT 1";
- $exam_highscore_arr = $parent->getQueryValue($exam_highscore_str);
- $user_arr[$mkey]->highscore = (count($exam_highscore_arr) > 0) ? $exam_highscore_arr[0]->highscore : '0';
- }
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.status='1' AND u.is_deleted='0' AND u.role>7 AND u.role<14 AND au.assessmentid='" . $assessmentid . "' " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'ASSESSMENT REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// SALES LEADERBOARD REPORT //////////////////////////////////////////////// */
- private function salesleaderboardreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 3);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $year_data = escape_str($parent->params[1]);
- $last_data = escape_str($parent->params[2]);
- $last_data_arr = explode('?', $last_data);
- $month_data = escape_str(trim($last_data_arr[0]));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[2]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('email' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $email = escape_str($parent->_request["email"]);
- $user_cond = "";
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[2]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Rank
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = " ORDER BY d.dealer_name,f.rank ASC ";
- break;
- case '2':$order_by_cond = " ORDER BY f.rank,d.dealer_name ASC ";
- break;
- default:$order_by_cond = " ORDER BY f.rank,d.dealer_name ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- if ($parent->current_user_role == '14') {
- $user_cond .= " AND u.dealer_code='" . $dealer_code . "'";
- }
- //GET ALL 20 USER RANK
- $start_date = date('Y-m-d', strtotime($year_data . "-" . $month_data . "-01"));
- $end_date = date('Y-m-t', strtotime($year_data . "-" . $month_data . "-01"));
- $parent->executeQuery("SET @rownum := 0");
- $get_user_str = "SELECT f.*,u.userid,u.fname,u.lname,d.* FROM (SELECT @rownum := @rownum + 1 AS rank, salecount,targetcount,smpin,userid,last_sale,first_sale,sale_per FROM (SELECT c.*, CASE WHEN targetcount=0 THEN 0 ELSE (salecount/targetcount)*100 END as 'sale_per' FROM ( SELECT a.userid,a.smpin,a.salecount,b.targetcount,a.last_sale,a.first_sale FROM (SELECT COALESCE(COUNT(s.id),'0') as scount, COALESCE(SUM(s.sales_count),'0') as salecount, u.smpin,u.userid,MAX(s.sale_date) last_sale,MIN(s.sale_date) first_sale FROM " . TABLE_USER . " as u JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code LEFT JOIN (SELECT id,smpin,sale_date,sales_count FROM " . DMS_EMPLOYEE_SALES . " WHERE sale_date>='" . $start_date . "' AND sale_date<='" . $end_date . "') as s ON s.smpin=u.smpin WHERE u.is_deleted=0 AND u.status=1 AND u.role>7 AND u.role<14 AND d.am_email='" . $email . "' GROUP BY u.smpin ) as a JOIN (SELECT COALESCE(SUM(t.target),'0') as targetcount,u.smpin,u.userid FROM " . TABLE_USER . " as u JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code LEFT JOIN (SELECT id,smpin,target FROM " . TABLE_USER_SALETARGET . " WHERE sale_month>='" . $start_date . "' AND sale_month<='" . $end_date . "')as t ON t.smpin=u.smpin WHERE u.is_deleted=0 AND u.status=1 AND u.role>7 AND u.role<14 AND d.am_email='" . $email . "' GROUP BY u.smpin ) as b ON a.userid=b.userid )c ORDER BY cast(sale_per as SIGNED) DESC,cast(salecount as SIGNED) DESC,cast(targetcount as SIGNED) DESC,last_sale ASC,first_sale ASC,userid ASC)as a )as f JOIN " . TABLE_USER . " as u ON f.userid=u.userid LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE 1=1 " . $user_cond . $order_by_cond . " " . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- //GET COUNT
- $get_user_count_str = "SELECT COUNT(u.userid)as user_count FROM (SELECT salecount,targetcount,smpin,userid,last_sale,first_sale,sale_per FROM (SELECT c.*, CASE WHEN targetcount=0 THEN 0 ELSE (salecount/targetcount)*100 END as 'sale_per' FROM ( SELECT a.userid,a.smpin,a.salecount,b.targetcount,a.last_sale,a.first_sale FROM (SELECT COALESCE(COUNT(s.id),'0') as scount, COALESCE(SUM(s.sales_count),'0') as salecount, u.smpin,u.userid,MAX(s.sale_date) last_sale,MIN(s.sale_date) first_sale FROM " . TABLE_USER . " as u JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code LEFT JOIN (SELECT id,smpin,sale_date,sales_count FROM " . DMS_EMPLOYEE_SALES . " WHERE sale_date>='" . $start_date . "' AND sale_date<='" . $end_date . "') as s ON s.smpin=u.smpin WHERE u.is_deleted=0 AND u.status=1 AND u.role>7 AND u.role<14 AND d.am_email='" . $email . "' GROUP BY u.smpin ) as a JOIN (SELECT COALESCE(SUM(t.target),'0') as targetcount,u.smpin,u.userid FROM " . TABLE_USER . " as u JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code LEFT JOIN (SELECT id,smpin,target FROM " . TABLE_USER_SALETARGET . " WHERE sale_month>='" . $start_date . "' AND sale_month<='" . $end_date . "')as t ON t.smpin=u.smpin WHERE u.is_deleted=0 AND u.status=1 AND u.role>7 AND u.role<14 AND d.am_email='" . $email . "' GROUP BY u.smpin ) as b ON a.userid=b.userid )c ORDER BY cast(sale_per as SIGNED) DESC,cast(salecount as SIGNED) DESC,cast(targetcount as SIGNED) DESC,last_sale ASC,first_sale ASC,userid ASC)as a )as f JOIN " . TABLE_USER . " as u ON f.userid=u.userid LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE 1=1 " . $user_cond . " LIMIT 1";
- $outof = 0;
- if (count($user_arr) > 0) {
- $user_count_arr = $parent->getQueryValue($get_user_count_str);
- $outof = (count($user_count_arr) > 0) ? $user_count_arr[0]->user_count : '0';
- foreach ($user_arr as $mkey => $res_user) {
- $user_arr[$mkey]->outof = $outof;
- }
- } else {
- $user_arr = array();
- }
- //GET COUNT
- $total = $outof;
- //LOG
- $logstr = 'SALES LEADERBOARD REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// ASSESSMENT LEADERBOARD REPORT //////////////////////////////////////////////// */
- private function assessmentleaderboardreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('email' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $email = escape_str($parent->_request["email"]);
- $user_cond = "";
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = " ORDER BY d.dealer_name,f.rank ASC ";
- break;
- case '2':$order_by_cond = " ORDER BY f.rank,d.dealer_name ASC ";
- break;
- default:$order_by_cond = " ORDER BY f.rank,d.dealer_name ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- $get_dealer_str = "SELECT dealer_code,city,zone FROM " . DMS_DEALER . " WHERE am_email='" . $email . "' AND status='1' AND is_deleted='0' GROUP BY dealer_code ";
- $dealer_arr = $parent->getQueryValue($get_dealer_str);
- if (count($dealer_arr) > 0) {
- $zone_arr = array();
- $city_arr = array();
- foreach ($dealer_arr as $res_dealer) {
- if (!in_array($res_dealer->zone, $zone_arr)) {
- $zone_arr[] = $res_dealer->zone;
- }
- if (!in_array($res_dealer->city, $city_arr)) {
- $city_arr[] = $res_dealer->city;
- }
- $dealer_cond_arr[] = " filter_dealer LIKE '%" . $res_dealer->dealer_code . "%'";
- }
- $query_cond .= " AND ( filter_dealer='' OR " . @implode(" OR ", $dealer_cond_arr) . " ) ";
- if (count($zone_arr) > 0) {
- foreach ($zone_arr as $zone) {
- $zone_cond_arr[] = " filter_zone LIKE '%" . $zone . "%'";
- }
- $query_cond .= " AND (filter_zone='' OR " . @implode(" OR ", $zone_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_zone='') ";
- }
- if (count($city_arr) > 0) {
- foreach ($city_arr as $city) {
- $city_cond_arr[] = " filter_region LIKE '%" . $city . "%'";
- }
- $query_cond .= " AND (filter_region='' OR " . @implode(" OR ", $city_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_region='') ";
- }
- } else {
- $query_cond .= " AND (filter_dealer='' AND filter_region='' AND filter_zone='' ) ";
- }
- $outof = 0;
- $query_cond .= ' a.user_type=0 ';
- //GET ALL ASSESSMENT LIST WHICH PUBLISHED
- $assessment_str = "SELECT a.* FROM `" . TABLE_ASSESSMENT . "` as a WHERE a.atype='0' AND a.assettypeid='1' AND a.publisheddate<='" . NOW . "' " . $query_cond;
- $assessment_arr = $parent->getQueryValue($assessment_str);
- $data_arr = array();
- if (count($assessment_arr) > 0) {
- foreach ($assessment_arr as $res_assess) {
- $assessmentid_arr[] = $res_assess->assessmentid;
- }
- $parent->executeQuery("SET @rownum := 0");
- $get_user_rank_str = "SELECT f.*,u.userid,u.fname,u.lname,d.* FROM ( SELECT @rownum := @rownum + 1 AS rank,COALESCE(user_score,'0')as user_score,CASE WHEN user_score IS NULL THEN 0 ELSE (user_score/" . count($assessment_arr) . ") END as percentage_score,userid,total_time,last_modified FROM (SELECT SUM(highscore)as user_score,u.userid,COALESCE(ar.total_time,'0')as total_time,MAX(au.modified_on) as last_modified FROM " . TABLE_USER . " as u JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code JOIN (SELECT * FROM " . TABLE_ASSESSMENT_USER . " WHERE assessmentid IN (" . @implode(',', $assessmentid_arr) . ") AND highscorearid!=0 ) as au ON u.userid=au.userid LEFT JOIN (SELECT SUM(time_taken)as total_time,assessmentid,userid FROM " . TABLE_ASSESSMENTRESULT . " WHERE assessmentid IN (" . @implode(',', $assessmentid_arr) . ") GROUP BY userid )as ar ON u.userid=ar.userid WHERE u.role>7 AND u.role<14 AND u.is_deleted=0 AND u.status=1 AND d.am_email='" . $email . "' GROUP BY u.userid ORDER BY user_score DESC,ar.total_time ASC,last_modified ASC,u.userid ASC )as a )as f JOIN " . TABLE_USER . " as u ON f.userid=u.userid LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE 1=1 " . $user_cond . $order_by_cond . " " . $limit_cond;
- $get_user_rank_arr = $parent->getQueryValue($get_user_rank_str);
- //GET COUNT
- $get_user_count_str = "SELECT COUNT(u.userid)as user_count FROM ( SELECT COALESCE(user_score,'0')as user_score,CASE WHEN user_score IS NULL THEN 0 ELSE (user_score/" . count($assessment_arr) . ") END as percentage_score,userid,total_time,last_modified FROM (SELECT SUM(highscore)as user_score,u.userid,COALESCE(ar.total_time,'0')as total_time,MAX(au.modified_on) as last_modified FROM " . TABLE_USER . " as u JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code JOIN (SELECT * FROM " . TABLE_ASSESSMENT_USER . " WHERE assessmentid IN (" . @implode(',', $assessmentid_arr) . ") AND highscorearid!=0 ) as au ON u.userid=au.userid LEFT JOIN (SELECT SUM(time_taken)as total_time,assessmentid,userid FROM " . TABLE_ASSESSMENTRESULT . " WHERE assessmentid IN (" . @implode(',', $assessmentid_arr) . ") GROUP BY userid )as ar ON u.userid=ar.userid WHERE u.role>7 AND u.role<14 AND u.is_deleted=0 AND u.status=1 AND d.am_email='" . $email . "' GROUP BY u.userid ORDER BY user_score DESC,ar.total_time ASC,last_modified ASC,u.userid ASC )as a )as f JOIN " . TABLE_USER . " as u ON f.userid=u.userid LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE 1=1 AND d.am_email='" . $email . "' " . $user_cond . " LIMIT 1";
- if (count($get_user_rank_arr) > 0) {
- $user_count_arr = $parent->getQueryValue($get_user_count_str);
- $outof = (count($user_count_arr) > 0) ? $user_count_arr[0]->user_count : '0';
- foreach ($get_user_rank_arr as $mkey => $res_user) {
- $get_user_rank_arr[$mkey]->outof = $outof;
- }
- } else {
- $get_user_rank_arr = array();
- }
- }
- $total = $outof;
- //LOG
- $logstr = 'ASSESSMENT LEADERBOARD REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $get_user_rank_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// REGISTRATION REPORT //////////////////////////////////////////////// */
- private function registrationreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $dealer_code_cond = '';
- if ($parent->current_user_role == '7') {
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- $emailid = $userdata->emailid;
- } else {
- //AREA MANAGER LEVEL REPORT
- $role = '7';
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('area' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $area_manager = escape_str($parent->_request["area"]);
- $emailid = $area_manager;
- }
- $user_cond = "";
- switch ($role) {
- case '3': //HO Manager
- $user_cond .= "";
- break;
- case '4': //Zonal Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE zm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '5': //Trainer
- $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.emailid='" . $emailid . "' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $zone_cond .= (count($trainer_arr) > 0) ? " zone='" . $trainer_arr[0]->zone . "'" : " zone='0'";
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE " . $zone_cond . " AND status='1' AND is_deleted='0')";
- break;
- case '6': //Regional Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE rm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '7': //Area Manager
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " AND dealer_code='" . $parent->current_user_data->dealer_code . "'";
- }
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE am_email='" . $emailid . "' " . $dealer_code_cond . " AND status='1' AND is_deleted='0')";
- break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (e.fname LIKE '%" . $search_txt . "%' OR e.lname LIKE '%" . $search_txt . "%' OR e.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- $get_user_str = "SELECT e.`smpin`, e.`emp_code`,e. `fname`,e.`lname`,e.emp_code,u.userid,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name,l.created_on as register_date FROM " . DMS_EMPLOYEE . " e LEFT JOIN " . TABLE_USER . " u ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON e.dealer_code=d.dealer_code LEFT JOIN (SELECT * FROM " . TABLE_USER_LOG . " WHERE module='REGISTER' )as l ON u.userid=l.userid WHERE e.status='1' AND e.smpin!='' " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (!count($user_arr) > 0) {
- $user_arr = array();
- } else {
- foreach ($user_arr as $mkey => $res_val) {
- $user_arr[$mkey]->is_active = ($res_val->userid) ? "1" : "1";
- }
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(e.`smpin`) as ucount FROM " . DMS_EMPLOYEE . " e LEFT JOIN " . TABLE_USER . " u ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON e.dealer_code=d.dealer_code LEFT JOIN (SELECT * FROM " . TABLE_USER_LOG . " WHERE module='REGISTER' )as l ON u.userid=l.userid WHERE e.status='1' AND e.smpin!='' " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'REGISTRATION REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// COURSE REPORT //////////////////////////////////////////////// */
- private function coursereport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $dealer_code_cond = '';
- //AREA MANAGER SELF
- if ($parent->current_user_role == '7') {
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- $emailid = $userdata->emailid;
- } else {
- //AREA MANAGER LEVEL REPORT
- $role = '7';
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('area' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $area_manager = escape_str($parent->_request["area"]);
- $emailid = $area_manager;
- }
- $user_cond = "";
- switch ($role) {
- case '3': //HO Manager
- $user_cond .= "";
- break;
- case '4': //Zonal Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE zm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '5': //Trainer
- $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.emailid='" . $emailid . "' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $zone_cond .= (count($trainer_arr) > 0) ? " zone='" . $trainer_arr[0]->zone . "'" : " zone='0'";
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE " . $zone_cond . " AND status='1' AND is_deleted='0')";
- break;
- case '6': //Regional Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE rm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '7': //Area Manager
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " AND dealer_code='" . $parent->current_user_data->dealer_code . "'";
- }
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE am_email='" . $emailid . "' " . $dealer_code_cond . " AND status='1' AND is_deleted='0')";
- break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (e.fname LIKE '%" . $search_txt . "%' OR e.lname LIKE '%" . $search_txt . "%' OR e.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.smpin,u.emp_code,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.status='1' AND u.is_deleted='0' AND u.role>7 AND u.role<14 " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $ukey => $res) {
- $content_arr = projectfunc::userCourseCompleteStatus($parent, $res->userid);
- $user_arr[$ukey]->total_content = $content_arr['total'];
- $user_arr[$ukey]->completed_content = $content_arr['completed'];
- $user_arr[$ukey]->percentage = ($content_arr['total'] > 0) ? round(($content_arr['completed'] / $content_arr['total']) * 100) : '0';
- }
- } else {
- $user_arr = array();
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.status='1' AND u.is_deleted='0' AND u.role>7 AND u.role<14 " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'COURSE REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// USER COURSE REPORT //////////////////////////////////////////////// */
- private function usercoursereport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 2);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $userid = escape_str($parent->params[1]);
- $check_user_str = "SELECT userid,segment,role FROM " . TABLE_USER . " WHERE status='1' AND is_deleted='0' AND userid='" . $userid . "' LIMIT 1";
- $check_user_arr = $parent->getQueryValue($check_user_str);
- if (!count($check_user_arr) > 0) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error2"]), 406);
- }
- if ($check_user_arr[0]->role > 7 && $check_user_arr[0]->role < 14) {
- $user_filter_str = projectfunc::getUserfiltervalue($parent, array('role', 'zone', 'city', 'dealer_code'), $userid);
- } else {
- $user_filter_str = projectfunc::getUserfiltervalue($parent, array('role'), $userid);
- }
- $user_cond = str_replace("filter_", "c.filter_", $user_filter_str);
- $cat_str = "SELECT cateid,catename FROM " . TABLE_CATEGORY . " ORDER BY cateid ASC";
- $cat_arr = $parent->getQueryValue($cat_str);
- if ($check_user_arr[0]->role > 7 && $check_user_arr[0]->role < 14) {
- switch ($check_user_arr[0]->segment) {
- case "1":$user_cond .= " AND t.segment IN (0,1) AND c.segment IN (0,1)";
- break;
- case "2":$user_cond .= " AND t.segment IN (0,2) AND c.segment IN (0,2)";
- break;
- default:$user_cond .= " AND t.segment IN (0) AND c.segment IN (0)";
- break;
- }
- }
- $data_arr = array();
- if (count($cat_arr) > 0) {
- foreach ($cat_arr as $ckey => $res_cat) {
- //GET USER ALL CONTENT COUNT
- $get_course_str = "SELECT COUNT(c.`contentid`) as totcontent FROM " . TABLE_ASSET_CONTENT . " as c JOIN " . TABLE_ASSET_TOPIC . " as t ON t.assettopicid=c.assettopicid WHERE t.status='1' AND t.is_deleted='0' AND c.status='1' AND c.is_deleted='0' AND t.cateid='" . $res_cat->cateid . "' " . $user_cond;
- $get_course_arr = $parent->getQueryValue($get_course_str);
- $total_content = (count($get_course_arr) > 0) ? $get_course_arr[0]->totcontent : '0';
- //GET USER COMPLETED CONTENT COUNT
- $get_user_completed_str = "SELECT COUNT(c.`contentid`) as totcontent FROM " . TABLE_ASSET_CONTENT . " as c JOIN " . TABLE_ASSET_TOPIC . " as t ON t.assettopicid=c.assettopicid JOIN (SELECT * FROM " . TABLE_USER_COMPLETE_CONTENT . " WHERE userid='" . $userid . "' AND status='2') as a ON a.contentid=c.contentid WHERE t.status='1' AND t.is_deleted='0' AND c.status='1' AND c.is_deleted='0' AND t.cateid='" . $res_cat->cateid . "' " . $user_cond;
- $get_user_completed_arr = $parent->getQueryValue($get_user_completed_str);
- $user_content = (count($get_user_completed_arr) > 0) ? $get_user_completed_arr[0]->totcontent : '0';
- $cat_arr[$ckey]->completed = ($user_content > 0) ? $user_content : '0';
- $cat_arr[$ckey]->total = ($total_content > 0) ? $total_content : '0';
- $cat_arr[$ckey]->percentage = ($total_content > 0) ? round(($user_content / $total_content) * 100) : '0';
- //TOPICS
- $get_asset_topic_str = "SELECT t.assettopicid,t.topicname FROM " . TABLE_ASSET_TOPIC . " as t JOIN " . TABLE_ASSET_CONTENT . " as c ON t.assettopicid=c.assettopicid WHERE t.status='1' AND t.is_deleted='0' AND c.status='1' AND c.is_deleted='0' AND t.cateid='" . $res_cat->cateid . "' " . $user_cond . " GROUP BY t.assettopicid ORDER BY t.assettopicid ASC";
- $get_asset_topic_arr = $parent->getQueryValue($get_asset_topic_str);
- if (count($get_asset_topic_arr) > 0) {
- foreach ($get_asset_topic_arr as $tkey => $res_topic) {
- //GET USER ALL CONTENT COUNT
- $get_course_str = "SELECT COUNT(c.`contentid`) as totcontent FROM " . TABLE_ASSET_CONTENT . " as c JOIN " . TABLE_ASSET_TOPIC . " as t ON t.assettopicid=c.assettopicid WHERE t.status='1' AND t.is_deleted='0' AND c.status='1' AND c.is_deleted='0' AND t.cateid='" . $res_cat->cateid . "' AND t.assettopicid='" . $res_topic->assettopicid . "' " . $user_cond;
- $get_course_arr = $parent->getQueryValue($get_course_str);
- $total_content = (count($get_course_arr) > 0) ? $get_course_arr[0]->totcontent : '0';
- //GET USER COMPLETED CONTENT COUNT
- $get_user_completed_str = "SELECT COUNT(c.`contentid`) as totcontent FROM " . TABLE_ASSET_CONTENT . " as c JOIN " . TABLE_ASSET_TOPIC . " as t ON t.assettopicid=c.assettopicid JOIN (SELECT * FROM " . TABLE_USER_COMPLETE_CONTENT . " WHERE userid='" . $userid . "' AND status='2') as a ON a.contentid=c.contentid WHERE t.status='1' AND t.is_deleted='0' AND c.status='1' AND c.is_deleted='0' AND t.cateid='" . $res_cat->cateid . "' AND t.assettopicid='" . $res_topic->assettopicid . "' " . $user_cond;
- $get_user_completed_arr = $parent->getQueryValue($get_user_completed_str);
- $user_content = (count($get_user_completed_arr) > 0) ? $get_user_completed_arr[0]->totcontent : '0';
- $get_asset_topic_arr[$tkey]->total = ($user_content > 0) ? $user_content : '0';
- $get_asset_topic_arr[$tkey]->completed = ($total_content > 0) ? $total_content : '0';
- $get_asset_topic_arr[$tkey]->percentage = ($total_content > 0) ? round(($user_content / $total_content) * 100) : '0';
- }
- $cat_arr[$ckey]->topic = (count($get_asset_topic_arr) > 0) ? $get_asset_topic_arr : array();
- }
- }
- $data_arr = $cat_arr;
- }
- //LOG
- $logstr = 'USER COURSE REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// USER TOPIC REPORT //////////////////////////////////////////////// */
- private function usertopicreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 3);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $userid = escape_str($parent->params[1]);
- $assettopicid = escape_str($parent->params[2]);
- $check_user_str = "SELECT userid,role,segment FROM " . TABLE_USER . " WHERE status='1' AND is_deleted='0' AND role>3 AND userid='" . $userid . "' LIMIT 1";
- $check_user_arr = $parent->getQueryValue($check_user_str);
- if (!count($check_user_arr) > 0) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error2"]), 406);
- }
- //NEW USER BASED CONDITION
- if ($check_user_arr[0]->role > 7 && $check_user_arr[0]->role < 14) {
- $user_filter_str = projectfunc::getUserfiltervalue($parent, array('role', 'zone', 'city', 'dealer_code'), $userid);
- $user_cond = str_replace("filter_", "c.filter_", $user_filter_str);
- $user_cond .= " AND (c.segment='0' OR c.segment='" . $check_user_arr[0]->segment . "')";
- } else {
- $user_filter_str = projectfunc::getUserfiltervalue($parent, array('role'), $userid);
- $user_cond = str_replace("filter_", "c.filter_", $user_filter_str);
- }
- $get_content_str = "SELECT c.title,c.`contentid`, c.`assettopicid` FROM " . TABLE_ASSET_CONTENT . " as c JOIN " . TABLE_ASSET_TOPIC . " as t ON t.assettopicid=c.assettopicid WHERE t.status='1' AND t.is_deleted='0' AND c.status='1' AND c.is_deleted='0' " . $user_cond . " AND t.assettopicid='" . $assettopicid . "'";
- $get_content_arr = $parent->getQueryValue($get_content_str);
- if (count($get_content_arr) > 0) {
- foreach ($get_content_arr as $ckey => $res_content) {
- //GET FILE TYPE
- $get_content_file_str = "SELECT filetypeid,filetype FROM " . TABLE_ASSET_FILE . " WHERE contentid='" . $res_content->contentid . "' LIMIT 1 ";
- $get_content_file_arr = $parent->getQueryValue($get_content_file_str);
- //USER CONTENT STATUS
- $get_content_status_str = "SELECT status FROM " . TABLE_USER_COMPLETE_CONTENT . " WHERE userid='" . $userid . "' AND contentid='" . $res_content->contentid . "' LIMIT 1 ";
- $get_content_status_arr = $parent->getQueryValue($get_content_status_str);
- $get_content_arr[$ckey]->status = (count($get_content_status_arr) > 0) ? $get_content_status_arr[0]->status : '0';
- $get_content_arr[$ckey]->is_completed = (count($get_content_status_arr) > 0 && $get_content_status_arr[0]->status == '2') ? '1' : '0';
- $get_content_arr[$ckey]->filetypeid = (count($get_content_file_arr) > 0) ? $get_content_file_arr[0]->filetypeid : '';
- $get_content_arr[$ckey]->filetype = (count($get_content_file_arr) > 0) ? $get_content_file_arr[0]->filetype : '';
- }
- $data_arr = $get_content_arr;
- } else {
- $data_arr = array();
- }
- //LOG
- $logstr = 'USER TOPIC REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// SALES TARGET REPORT //////////////////////////////////////////////// */
- private function salestarget($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- globalfunc::checkParamCount($parent, 3);
- $year_data = escape_str($parent->params[1]);
- $last_data = escape_str($parent->params[2]);
- $last_data_arr = explode('?', $last_data);
- $month_data = escape_str(trim($last_data_arr[0]));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[2]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $dealer_code_cond = '';
- //AREA MANAGER SELF
- if ($parent->current_user_role == '7') {
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- $emailid = $userdata->emailid;
- } else {
- //AREA MANAGER LEVEL REPORT
- $role = '7';
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('area' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $area_manager = escape_str($parent->_request["area"]);
- $emailid = $area_manager;
- }
- $user_cond = "";
- switch ($role) {
- case '3': //HO Manager
- $user_cond .= "";
- break;
- case '4': //Zonal Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE zm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '5': //Trainer
- $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.emailid='" . $emailid . "' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $zone_cond .= (count($trainer_arr) > 0) ? " zone='" . $trainer_arr[0]->zone . "'" : " zone='0'";
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE " . $zone_cond . " AND status='1' AND is_deleted='0')";
- break;
- case '6': //Regional Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE rm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '7': //Area Manager
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " AND dealer_code='" . $parent->current_user_data->dealer_code . "'";
- }
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE am_email='" . $emailid . "'" . $dealer_code_cond . " AND status='1' AND is_deleted='0')";
- break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[2]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (e.fname LIKE '%" . $search_txt . "%' OR e.lname LIKE '%" . $search_txt . "%' OR e.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- //GET MODEL
- $query_modelarr = $parent->selectQuery(TABLE_MODEL, "model_id, model_name,model_image ", "model_is_target=1 AND user_type=0 ORDER BY model_id", "");
- $get_user_str = "SELECT e.`smpin`, e.`emp_code`,e. `fname`,e.`lname`,e.emp_code,u.userid,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM " . DMS_EMPLOYEE . " e LEFT JOIN " . TABLE_USER . " u ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON e.dealer_code=d.dealer_code WHERE e.status='1' AND e.smpin!='' " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $ukey => $res) {
- $user_target = projectfunc::userSmpinSalesTarget($parent, $res->smpin, '', $year_data, $month_data);
- $user_arr[$ukey]->salestarget = $user_target;
- $user_arr[$ukey]->model = array();
- $user_arr[$ukey]->is_edit = (strtotime(CUR_DATE) > strtotime(date('Y-m-d', strtotime($year_data . "-" . $month_data . "-" . TRAINER_BUFFER_DATE)))) ? "0" : "1";
- if ($query_modelarr['nr']) {
- foreach ($query_modelarr['result'] as $res_model) {
- $user_target = projectfunc::userSmpinSalesTarget($parent, $res->smpin, $res_model->model_name, $year_data, $month_data);
- if ($user_target > 0) {
- $mobj = new stdClass();
- $mobj->model_id = $res_model->model_id;
- $mobj->model_name = $res_model->model_name;
- $mobj->target = $user_target;
- $mobj->achieved = projectfunc::userSmpinSalesAchieved($parent, $res->smpin, $res_model->model_name, $year_data, $month_data);
- $mobj->model_image_url = ($res_model->model_image != '') ? SITE_URL . "hypermupload/model/" . $res_model->model_image : NOIMAGE_URL;
- $user_arr[$ukey]->model[] = $mobj;
- } else {
- $mobj = new stdClass();
- $mobj->model_id = $res_model->model_id;
- $mobj->model_name = $res_model->model_name;
- $mobj->target = '0';
- $mobj->achieved = projectfunc::userSmpinSalesAchieved($parent, $res->smpin, $res_model->model_name, $year_data, $month_data);
- $mobj->model_image_url = ($res_model->model_image != '') ? SITE_URL . "hypermupload/model/" . $res_model->model_image : NOIMAGE_URL;
- $user_arr[$ukey]->model[] = $mobj;
- }
- }
- }
- }
- } else {
- $user_arr = array();
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(e.`smpin`)as ucount FROM " . DMS_EMPLOYEE . " e LEFT JOIN " . TABLE_USER . " u ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON e.dealer_code=d.dealer_code WHERE e.status='1' AND e.smpin!='' " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'SALES TARGET REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $is_edit = 0;
- if (date('Y-m', strtotime(CUR_DATE)) == date('Y-m', strtotime($year_data . "-" . $month_data . "-01"))) {
- if (strtotime(CUR_DATE) <= strtotime(date('Y-m-d', strtotime($year_data . "-" . $month_data . "-" . TRAINER_BUFFER_DATE)))) {
- $is_edit = 1;
- }
- }
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1'], 'is_edit' => $is_edit), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// SALES TARGET UPDATE //////////////////////////////////////////////// */
- private function salestargetupdate($parent)
- {
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- projectfunc::authorizedRole($parent, array('4', '5', '6', '7', '14'));
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('year' => 'integer', 'month' => 'integer', 'smpin' => 'string', 'model_arr' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $model_json_arr = json_decode($parent->_request["model_arr"]);
- if (!count($model_json_arr) > 0 || !$model_json_arr) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error3"]), 406);
- }
- $year = escape_str($parent->_request["year"]);
- $month = escape_str($parent->_request["month"]);
- $smpin = escape_str($parent->_request["smpin"]);
- $dealer_code_cond = '';
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " AND dealer_code='" . $parent->current_user_data->dealer_code . "'";
- }
- //VALIDATE SMPIN
- $employee_str = "SELECT * FROM " . DMS_EMPLOYEE . " WHERE smpin='" . $smpin . "' AND status='1' " . $dealer_code_cond . " LIMIT 1";
- $employee_arr = $parent->getQueryValue($employee_str);
- if (count($employee_arr) != 1) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error4"]), 406);
- }
- if (strtotime(CUR_DATE) > strtotime(date('Y-m-d', strtotime($year . "-" . $month . "-" . TRAINER_BUFFER_DATE)))) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error6"]), 406);
- }
- $model_str = "SELECT * FROM " . TABLE_MODEL . " WHERE model_is_target='1'";
- $model_arr = $parent->getQueryValue($model_str);
- $model_data_arr = array();
- if (count($model_arr) > 0) {
- foreach ($model_arr as $res) {
- $model_data_arr[$res->model_id] = $res->model_name;
- }
- }
- //VALIDATE MODEL EXIST
- if (count($model_json_arr) > 0) {
- foreach ($model_json_arr as $res_model) {
- if (!isset($model_data_arr[$res_model->model_id])) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error5"]), 406);
- }
- }
- }
- //echo "calling";
- //INSERT OR UPDATE
- if (count($model_json_arr) > 0) {
- foreach ($model_json_arr as $res_model) {
- $model_name = $model_data_arr[$res_model->model_id];
- $month_cond = " AND sale_month>='" . date('Y-m-d', strtotime($year . "-" . $month . "-01")) . "' AND sale_month<='" . date('Y-m-t', strtotime($year . "-" . $month . "-01")) . "'";
- $check_str = "SELECT * FROM " . TABLE_USER_SALETARGET . " WHERE smpin='" . $smpin . "' " . $month_cond . " AND model='" . $model_name . "' LIMIT 1";
- $check_arr = $parent->getQueryValue($check_str);
- if (count($check_arr) > 0) { //UPDATE
- $parent->executeQuery("UPDATE " . TABLE_USER_SALETARGET . " SET `target`='" . $res_model->target . "', `modified_on`='" . NOW . "' WHERE id='" . $check_arr[0]->id . "' ");
- } else { //INSERT
- $parent->executeQuery("INSERT INTO " . TABLE_USER_SALETARGET . " (`smpin`, `model`, `am_id`, `sale_month`, `target`, `created_on`, `modified_on`)VALUES('" . $smpin . "','" . $model_name . "','" . $parent->current_user_id . "','" . date('Y-m-d', strtotime($year . "-" . $month . "-01")) . "','" . $res_model->target . "','" . NOW . "','" . NOW . "')");
- }
- //LOG INSERT
- $parent->executeQuery("INSERT INTO " . TABLE_USER_SALESTARGET_LOG . " (`smpin`, `model`, `roleid`, `userid`, `sale_month`, `target`, `created_on`)VALUES('" . $smpin . "','" . $model_name . "','" . $parent->current_user_role . "','" . $parent->current_user_id . "','" . date('Y-m-d', strtotime($year . "-" . $month . "-01")) . "','" . $res_model->target . "','" . NOW . "','" . NOW . "')");
- // if($parent->current_user_role=='14') //FOR DEALER
- // {
- // $month_cond=" AND sale_month>='".date('Y-m-d',strtotime($year."-".$month."-01"))."' AND sale_month<='".date('Y-m-t',strtotime($year."-".$month."-01"))."'";
- // $check_str = "SELECT * FROM ".TABLE_USER_SALESTARGET_APPROVE." WHERE smpin='".$smpin."' ".$month_cond." AND model='".$model_name."' AND is_deleted=0 LIMIT 1";
- // $check_arr=$parent->getQueryValue($check_str);
- //
- // if(count($check_arr)>0)
- // { //UPDATE
- // $parent->executeQuery("UPDATE ".TABLE_USER_SALESTARGET_APPROVE." SET `target`='".$res_model->target."', `modified_on`='".NOW."' WHERE id='".$check_arr[0]->id."' ");
- // }else
- // { //INSERT
- // $parent->executeQuery("INSERT INTO ".TABLE_USER_SALESTARGET_APPROVE." (`smpin`, `model`, `user_id`, `sale_month`, `target`, `created_on`, `modified_on`)VALUES('".$smpin."','".$model_name."','".$parent->current_user_id."','".date('Y-m-d',strtotime($year."-".$month."-01"))."','".$res_model->target."','".NOW."','".NOW."')");
- // }
- // }else
- // {
- // $month_cond=" AND sale_month>='".date('Y-m-d',strtotime($year."-".$month."-01"))."' AND sale_month<='".date('Y-m-t',strtotime($year."-".$month."-01"))."'";
- // $check_str = "SELECT * FROM ".TABLE_USER_SALETARGET." WHERE smpin='".$smpin."' ".$month_cond." AND model='".$model_name."' LIMIT 1";
- // $check_arr=$parent->getQueryValue($check_str);
- //
- // if(count($check_arr)>0)
- // { //UPDATE
- // $parent->executeQuery("UPDATE ".TABLE_USER_SALETARGET." SET `target`='".$res_model->target."', `modified_on`='".NOW."' WHERE id='".$check_arr[0]->id."' ");
- // }else
- // { //INSERT
- // $parent->executeQuery("INSERT INTO ".TABLE_USER_SALETARGET." (`smpin`, `model`, `am_id`, `sale_month`, `target`, `created_on`, `modified_on`)VALUES('".$smpin."','".$model_name."','".$parent->current_user_id."','".date('Y-m-d',strtotime($year."-".$month."-01"))."','".$res_model->target."','".NOW."','".NOW."')");
- // }
- //
- // }
- }
- // if($parent->current_user_role!='14')
- // {
- // $parent->executeQuery("UPDATE ".TABLE_USER_SALESTARGET_APPROVE." SET am_id='".$parent->current_user_id."',is_deleted=1, `modified_on`='".NOW."' WHERE smpin='".$smpin."' AND is_deleted=0 ");
- // }
- }
- //LOG
- $logstr = 'SALES TARGET UPDATE';
- globalfunc::insertUserLog($parent, $logstr);
- $user_cond = " and u.smpin='" . $smpin . "'";
- $get_user_str = "SELECT e.`smpin`, e.`emp_code`,e. `fname`,e.`lname`,e.emp_code,u.userid,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM " . DMS_EMPLOYEE . " e LEFT JOIN " . TABLE_USER . " u ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON e.dealer_code=d.dealer_code WHERE e.status='1' AND e.smpin!='' " . $user_cond . " LIMIT 1";
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $ukey => $res) {
- $user_target = projectfunc::userSmpinSalesTarget($parent, $res->smpin, '', $year, $month);
- $user_arr[$ukey]->salestarget = $user_target;
- $user_arr[$ukey]->model = array();
- //GET MODEL
- $query_modelarr = $parent->selectQuery(TABLE_MODEL, "model_id, model_name,model_image ", "model_is_target=1 ORDER BY model_id", "");
- if ($query_modelarr['nr']) {
- foreach ($query_modelarr['result'] as $res_model) {
- $user_target = projectfunc::userSmpinSalesTarget($parent, $res->smpin, $res_model->model_name, $year, $month);
- if ($user_target > 0) {
- $mobj = new stdClass();
- $mobj->model_id = $res_model->model_id;
- $mobj->model_name = $res_model->model_name;
- $mobj->target = $user_target;
- $mobj->achieved = projectfunc::userSmpinSalesAchieved($parent, $res->smpin, $res_model->model_name, $year, $month);
- $mobj->model_image_url = ($res_model->model_image != '') ? SITE_URL . "hypermupload/model/" . $res_model->model_image : NOIMAGE_URL;
- $user_arr[$ukey]->model[] = $mobj;
- } else {
- $mobj = new stdClass();
- $mobj->model_id = $res_model->model_id;
- $mobj->model_name = $res_model->model_name;
- $mobj->target = '0';
- $mobj->achieved = projectfunc::userSmpinSalesAchieved($parent, $res->smpin, $res_model->model_name, $year, $month);
- $mobj->model_image_url = ($res_model->model_image != '') ? SITE_URL . "hypermupload/model/" . $res_model->model_image : NOIMAGE_URL;
- $user_arr[$ukey]->model[] = $mobj;
- }
- }
- }
- }
- } else {
- $user_arr = array();
- }
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// NEW SALES TARGET UPDATE //////////////////////////////////////////////// */
- private function newsalestargetupdate($parent)
- {
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- projectfunc::authorizedRole($parent, array('4', '5', '6', '7', '14'));
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('year' => 'integer', 'month' => 'integer', 'model_arr' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $model_json_arr = json_decode($parent->_request["model_arr"]);
- if (!count($model_json_arr) > 0 || !$model_json_arr) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error3"]), 406);
- }
- $year = escape_str($parent->_request["year"]);
- $month = escape_str($parent->_request["month"]);
- //$smpin = escape_str($parent->_request["smpin"]);
- $dealer_code_cond = '';
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " AND dealer_code='" . $parent->current_user_data->dealer_code . "'";
- }
- //if(strtotime(CUR_DATE)>strtotime(date('Y-m-d',strtotime($year."-".$month."-".TRAINER_BUFFER_DATE)))) $parent->response(array('response'=>'failed','message'=>$this->page_data["error6"]),406);
- //$tokenid=TIMETOKEN.globalfunc::generateToken($parent,'',5);
- $model_str = "SELECT * FROM " . TABLE_MODEL . " WHERE model_is_target='1'";
- $model_arr = $parent->getQueryValue($model_str);
- $model_data_arr = array();
- if (count($model_arr) > 0) {
- foreach ($model_arr as $res) {
- $model_data_arr[$res->model_id] = $res->model_name;
- }
- }
- $all_smpin_arr = array();
- //VALIDATE MODEL EXIST
- if (count($model_json_arr) > 0) {
- foreach ($model_json_arr as $res_model) {
- if (!isset($model_data_arr[$res_model->model_id])) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error5"]), 406);
- }
- $smpin = $res_model->smpin;
- //VALIDATE SMPIN
- $employee_str = "SELECT * FROM " . DMS_EMPLOYEE . " WHERE smpin='" . $smpin . "' AND status='1' " . $dealer_code_cond . " LIMIT 1";
- $employee_arr = $parent->getQueryValue($employee_str);
- if (count($employee_arr) != 1) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error4"]), 406);
- }
- if (!in_array($smpin, $all_smpin_arr)) {
- $all_smpin_arr[] = $smpin;
- $is_edit = projectfunc::setSaleEditpermisson($parent, $smpin, date('Y-m-d', strtotime($year . "-" . $month . "-01")));
- if ($is_edit != 1) {
- $manager_error = ($parent->manager_error) ? $parent->manager_error : $this->page_data["error6"];
- $parent->response(array('response' => 'failed', 'message' => $manager_error), 406);
- }
- }
- }
- }
- if (count($model_json_arr) > 0) {
- $smpin_tot_arr = array();
- //REMOVE FOR MANAGERS
- $smpin_quotes = array_map("quotes_array", $all_smpin_arr);
- if ($parent->current_user_role != '14') {
- $month_cond = " AND sale_month>='" . date('Y-m-d', strtotime($year . "-" . $month . "-01")) . "' AND sale_month<='" . date('Y-m-t', strtotime($year . "-" . $month . "-01")) . "'";
- $check_sum_str = "SELECT SUM(target) as tottarget,smpin FROM " . TABLE_USER_SALETARGET . " WHERE smpin IN (" . @implode(',', $smpin_quotes) . ") " . $month_cond . " GROUP BY smpin ";
- $check_sum_arr = $parent->getQueryValue($check_sum_str);
- if (count($check_sum_arr) > 0) {
- foreach ($check_sum_arr as $res) {
- $smpin_tot_arr[$res->smpin] = $res->tottarget;
- }
- }
- }
- // $delete_str=($parent->current_user_role!='14')?"UPDATE ".TABLE_USER_SALESTARGET_APPROVE." SET am_id='".$parent->current_user_id."',is_deleted=1, `modified_on`='".NOW."' WHERE smpin IN (".@implode(',',$smpin_quotes).") AND is_deleted=0 AND sale_month BETWEEN '".date('Y-m-d',strtotime($year."-".$month."-01"))."' AND '".date('Y-m-t',strtotime($year."-".$month."-01"))."'" : "UPDATE ".TABLE_USER_SALESTARGET_APPROVE." SET am_id='0',is_deleted=1, `modified_on`='".NOW."' WHERE smpin IN (".@implode(',',$smpin_quotes).") AND is_deleted=0 AND sale_month BETWEEN '".date('Y-m-d',strtotime($year."-".$month."-01"))."' AND '".date('Y-m-t',strtotime($year."-".$month."-01"))."'";
- // $parent->executeQuery($delete_str);
- foreach ($model_json_arr as $res_model) {
- $model_name = $model_data_arr[$res_model->model_id];
- $smpin = $res_model->smpin;
- // //DELETE FOR MANAGERS
- // if($parent->current_user_role=='14') //FOR DEALER TO MANAGER APPROVAL
- // {
- // $parent->executeQuery("INSERT INTO ".TABLE_USER_SALESTARGET_APPROVE." (`tokenid`, `smpin`, `model`, `am_id`, `user_id`, `sale_month`, `target`, `is_approved`, `is_deleted`, `created_on`, `modified_on`)VALUES('".strtoupper($tokenid)."','".$smpin."','".$model_name."','".$parent->current_user_id."','".$parent->current_user_id."','".date('Y-m-d',strtotime($year."-".$month."-01"))."','".$res_model->target."','1','1','".NOW."','".NOW."')");
- // }else
- // {
- // $month_cond=" AND sale_month>='".date('Y-m-d',strtotime($year."-".$month."-01"))."' AND sale_month<='".date('Y-m-t',strtotime($year."-".$month."-01"))."'";
- // $check_str = "SELECT * FROM ".TABLE_USER_SALETARGET." WHERE smpin='".$smpin."' ".$month_cond." AND model='".$model_name."' LIMIT 1";
- // $check_arr=$parent->getQueryValue($check_str);
- //
- // //AM OWN APPROVAL
- // $parent->executeQuery("INSERT INTO ".TABLE_USER_SALESTARGET_APPROVE." (`tokenid`, `smpin`, `model`, `user_id`, `sale_month`, `target`, `created_on`, `modified_on`)VALUES('".strtoupper($tokenid)."','".$smpin."','".$model_name."','".$parent->current_user_id."','".date('Y-m-d',strtotime($year."-".$month."-01"))."','".$res_model->target."','".NOW."','".NOW."')");
- //
- // if(count($check_arr)>0)
- // {
- // //UPDATE
- // $parent->executeQuery("UPDATE ".TABLE_USER_SALETARGET." SET `target`='".$res_model->target."', `modified_on`='".NOW."' WHERE id='".$check_arr[0]->id."' ");
- // }else
- // { //INSERT
- // $parent->executeQuery("INSERT INTO ".TABLE_USER_SALETARGET." (`smpin`, `model`, `am_id`, `sale_month`, `target`, `created_on`, `modified_on`)VALUES('".$smpin."','".$model_name."','".$parent->current_user_id."','".date('Y-m-d',strtotime($year."-".$month."-01"))."','".$res_model->target."','".NOW."','".NOW."')");
- // }
- //
- // }
- $month_cond = " AND sale_month>='" . date('Y-m-d', strtotime($year . "-" . $month . "-01")) . "' AND sale_month<='" . date('Y-m-t', strtotime($year . "-" . $month . "-01")) . "'";
- $check_str = "SELECT * FROM " . TABLE_USER_SALETARGET . " WHERE smpin='" . $smpin . "' " . $month_cond . " AND model='" . $model_name . "' LIMIT 1";
- $check_arr = $parent->getQueryValue($check_str);
- if (count($check_arr) > 0) {
- //UPDATE
- $parent->executeQuery("UPDATE " . TABLE_USER_SALETARGET . " SET `target`='" . $res_model->target . "', `modified_on`='" . NOW . "' WHERE id='" . $check_arr[0]->id . "' ");
- } else { //INSERT
- $parent->executeQuery("INSERT INTO " . TABLE_USER_SALETARGET . " (`smpin`, `model`, `am_id`, `sale_month`, `target`, `created_on`, `modified_on`)VALUES('" . $smpin . "','" . $model_name . "','" . $parent->current_user_id . "','" . date('Y-m-d', strtotime($year . "-" . $month . "-01")) . "','" . $res_model->target . "','" . NOW . "','" . NOW . "')");
- }
- //LOG INSERT
- $parent->executeQuery("INSERT INTO " . TABLE_USER_SALESTARGET_LOG . " (`smpin`, `model`, `roleid`, `userid`, `sale_month`, `target`, `created_on`)VALUES('" . $smpin . "','" . $model_name . "','" . $parent->current_user_role . "','" . $parent->current_user_id . "','" . date('Y-m-d', strtotime($year . "-" . $month . "-01")) . "','" . $res_model->target . "','" . NOW . "')");
- }
- if (count($all_smpin_arr) > 0) {
- $dealer_notification_type = 0;
- foreach ($all_smpin_arr as $smpin) {
- if ($parent->current_user_role == '14') {
- $status_str = '1';
- } else {
- $month_cond = " AND sale_month>='" . date('Y-m-d', strtotime($year . "-" . $month . "-01")) . "' AND sale_month<='" . date('Y-m-t', strtotime($year . "-" . $month . "-01")) . "'";
- $check_sum_str = "SELECT SUM(target) as tottarget,smpin FROM " . TABLE_USER_SALETARGET . " WHERE smpin ='" . $smpin . "' " . $month_cond . " GROUP BY smpin LIMIT 1 ";
- $check_sum_arr = $parent->getQueryValue($check_sum_str);
- if (count($check_sum_arr) > 0) {
- $status_str = (isset($smpin_tot_arr[$smpin]) && $smpin_tot_arr[$smpin] != $check_sum_arr[0]->tottarget) ? '3' : '2';
- if ($status_str == '3') {
- $dealer_notification_type = "1";
- }
- } else {
- $status_str = '2';
- }
- }
- $parent->executeQuery("INSERT INTO " . TABLE_USER_SALESTARGET_STATUS . " (`smpin`, `roleid`, `userid`, `status`, `sale_month`, `created_on`) VALUES ('" . $smpin . "','" . $parent->current_user_role . "','" . $parent->current_user_id . "','" . $status_str . "','" . date('Y-m-d', strtotime($year . "-" . $month . "-01")) . "','" . NOW . "')");
- }
- //DSE TRIGGER NOTIFICATION
- $notificationtitle = 'Sales target has been updated';
- $notificationtext = 'Sales target has been updated';
- $notificationtype = '5';
- $obj = new stdClass();
- $notificationdata = json_encode($obj);
- $parent->executeQuery("INSERT INTO `" . TABLE_NOTIFICATION . "` ( `notificationtitle`, `notificationtext`, `notificationdata`, `notificationtype`, `status`, `publisheddate`, `created_on`, `modified_on`) VALUES ('" . $notificationtitle . "','" . escape_str($notificationtext) . "','" . $notificationdata . "','" . $notificationtype . "' ,'1','" . NOW . "','" . NOW . "','" . NOW . "')");
- $notificationid = $parent->lastInsertId();
- $data = array('notification_id' => $notificationid, 'title' => $notificationtitle, 'message' => $notificationtext, 'notificationtype' => $notificationtype, 'notificationdata' => $notificationdata, 'created_date' => NOW);
- //TO SMPIN
- $smpin_quotes = array_map("quotes_array", $all_smpin_arr);
- $check_str = "SELECT userid FROM " . TABLE_USER . " WHERE smpin IN (" . @implode(',', $smpin_quotes) . ") AND role>7 AND role<14 AND is_deleted=0 AND status=1";
- $check_user_arr = $parent->getQueryValue($check_str);
- if (count($check_user_arr)) {
- $ins_arr = array();
- foreach ($check_user_arr as $res_user) {
- $ins_arr[] = " ('" . $notificationid . "', '" . $res_user->userid . "', '0', '" . NOW . "')";
- }
- $insert_chunk = array_chunk($ins_arr, 1000);
- foreach ($insert_chunk as $chunk_ins) {
- $parent->executeQuery("INSERT INTO " . TABLE_NOTIFICATION_USER . "(`notificationid`, `userid`, `status`, `created_on`) VALUES " . @implode(',', $chunk_ins) . " ON DUPLICATE KEY UPDATE `status` =0");
- }
- $usertokenarr = array('ios' => array(), 'android' => array());
- $user_device_str = "SELECT ud.devicetype,ud.token FROM `" . TABLE_USER_DEVICES . "` as ud JOIN (SELECT userid FROM " . TABLE_NOTIFICATION_USER . " WHERE notificationid='" . $notificationid . "') as u ON ud.userid=u.userid WHERE ud.is_deleted='0' AND (devicetype='ios' OR devicetype='android') AND token!=''";
- $user_device_arr = $parent->getQueryValue($user_device_str);
- if (count($user_device_arr) > 0) {
- if (strtolower($user_device_arr[0]->devicetype) == 'ios') {
- $usertokenarr['ios'][] = $user_device_arr[0]->token;
- } else if (strtolower($user_device_arr[0]->devicetype) == 'android') {
- $usertokenarr['android'][] = $user_device_arr[0]->token;
- }
- // globalfunc::sendUserNotification($data, $usertokenarr);
- }
- }
- //TO DEALER
- if ($parent->current_user_role != '14') {
- $notificationtitle = ($dealer_notification_type == '1') ? 'Sales target has been modified by AM' : 'Sales target has been approved by AM';
- $notificationtext = ($dealer_notification_type == '1') ? 'Sales target has been modified by AM' : 'Sales target has been approved by AM';
- $notificationtype = '5';
- $obj = new stdClass();
- $notificationdata = json_encode($obj);
- $parent->executeQuery("INSERT INTO `" . TABLE_NOTIFICATION . "` ( `notificationtitle`, `notificationtext`, `notificationdata`, `notificationtype`, `status`, `publisheddate`, `created_on`, `modified_on`) VALUES ('" . $notificationtitle . "','" . escape_str($notificationtext) . "','" . $notificationdata . "','" . $notificationtype . "' ,'1','" . NOW . "','" . NOW . "','" . NOW . "')");
- $notificationid = $parent->lastInsertId();
- $data = array('notification_id' => $notificationid, 'title' => $notificationtitle, 'message' => $notificationtext, 'notificationtype' => $notificationtype, 'notificationdata' => $notificationdata, 'created_date' => NOW);
- $smpin_quotes = array_map("quotes_array", $all_smpin_arr);
- $check_str = "SELECT * FROM " . TABLE_USER . " u JOIN (SELECT dealer_code FROM " . DMS_EMPLOYEE . " WHERE smpin IN (" . @implode(',', $smpin_quotes) . ") GROUP BY dealer_code) as e ON e.dealer_code=u.dealer_code WHERE u.role=14";
- $check_user_arr = $parent->getQueryValue($check_str);
- if (count($check_user_arr)) {
- $ins_arr = array();
- foreach ($check_user_arr as $res_user) {
- $ins_arr[] = " ('" . $notificationid . "', '" . $res_user->userid . "', '0', '" . NOW . "')";
- }
- $insert_chunk = array_chunk($ins_arr, 1000);
- foreach ($insert_chunk as $chunk_ins) {
- $parent->executeQuery("INSERT INTO " . TABLE_NOTIFICATION_USER . "(`notificationid`, `userid`, `status`, `created_on`) VALUES " . @implode(',', $chunk_ins) . " ON DUPLICATE KEY UPDATE `status` =0");
- }
- $usertokenarr = array('ios' => array(), 'android' => array());
- $user_device_str = "SELECT ud.devicetype,ud.token FROM `" . TABLE_USER_DEVICES . "` as ud JOIN (SELECT userid FROM " . TABLE_NOTIFICATION_USER . " WHERE notificationid='" . $notificationid . "') as u ON ud.userid=u.userid WHERE ud.is_deleted='0' AND (devicetype='ios' OR devicetype='android') AND token!=''";
- $user_device_arr = $parent->getQueryValue($user_device_str);
- if (count($user_device_arr) > 0) {
- if (strtolower($user_device_arr[0]->devicetype) == 'ios') {
- $usertokenarr['ios'][] = $user_device_arr[0]->token;
- } else if (strtolower($user_device_arr[0]->devicetype) == 'android') {
- $usertokenarr['android'][] = $user_device_arr[0]->token;
- }
- // globalfunc::sendUserNotification($data, $usertokenarr);
- }
- }
- $dealermail_str = "SELECT d.email FROM (SELECT dealer_code FROM " . DMS_EMPLOYEE . " WHERE smpin IN (" . @implode(',', $smpin_quotes) . ") AND status=1) u JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE d.email!='' GROUP BY d.email";
- $dealer_email_arr = $parent->getQueryValue($dealermail_str);
- if (count($dealer_email_arr) > 0) {
- foreach ($dealer_email_arr as $res_dealer) {
- $subject = 'HYPER-M App - Set Sales Target Update Reminder - ' . date('d-M-Y', strtotime(CUR_DATE));
- $message = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
- <tbody>
- <tr>
- <td>
- <table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
- <tbody>
- <tr>
- <td bgcolor="#2d2d2d" height="36" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#e4e4e4; text-align:left; font-weight:bold; padding-left:14px; border-bottom:2px solid black">' . $subject . '</td>
- </tr>
- <tr>
- <td>
- <table width="85%" align="center">
- <tbody>
- <tr>
- <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
- line-height: 1.5;">
- <div style="font-family:arial; color:#333; font-size:12px; padding:5px;">Dear Dealer Partner,</div>
- </td>
- </tr>
- <tr>
- <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
- line-height: 1.5;">
- <div style="font-family:arial; color:#333; font-size:12px; padding:5px;">Area Manager has Approved / Modified the DSE sales target. Please review and communicate the same to respective DSEs.</div>
- </td>
- </tr>
- </tbody>
- </table>
- </td>
- </tr>
- <tr>
- <td style="padding-top:0px; padding-bottom:10px;"></td>
- </tr>
- <tr>
- <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#3f3f3f; background:#fafafa; line-height:30px; text-align:center; border-bottom:2px solid black"><div class="footer-con"> <p>Thanks & Regards, <strong style="color:#070000;">HYPER-M Support Team</strong></p>
- </div></td>
- </tr>
- </tbody>
- </table>
- </td>
- </tr>
- </tbody>
- </table>';
- $obj = array();
- $obj['from'] = SUPPORT_EMAIL;
- $obj['to'] = $res_dealer->email;
- $obj['subject'] = $subject;
- $obj['message'] = $message;
- // globalfunc::sendMai($parent, $obj);
- }
- }
- } else {
- //TRIGGER NOTIFICATION TO ASM
- //TO SMPIN
- $smpin_quotes = array_map("quotes_array", $all_smpin_arr);
- $check_str = "SELECT a.userid,a.emp_code,a.emailid,d.dealer_name,d.dealer_code FROM (SELECT dealer_code FROM " . TABLE_USER . " WHERE smpin IN (" . @implode(',', $smpin_quotes) . ") AND role>7 AND role<14 AND is_deleted=0 AND status=1) u JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code JOIN (SELECT userid, emp_code, emailid FROM " . TABLE_USER . " WHERE role=7 AND is_deleted=0 AND status=1 ) a ON a.emailid=d.am_email GROUP BY a.userid";
- $check_user_arr = $parent->getQueryValue($check_str);
- if (count($check_user_arr) > 0) {
- $notificationtitle = 'Sales target has been submitted by Dealer';
- $notificationtext = 'Sales target has been submitted by Dealer';
- $notificationtype = '5';
- $obj = new stdClass();
- $notificationdata = json_encode($obj);
- $parent->executeQuery("INSERT INTO `" . TABLE_NOTIFICATION . "` ( `notificationtitle`, `notificationtext`, `notificationdata`, `notificationtype`, `status`, `publisheddate`, `created_on`, `modified_on`) VALUES ('" . $notificationtitle . "','" . escape_str($notificationtext) . "','" . $notificationdata . "','" . $notificationtype . "' ,'1','" . NOW . "','" . NOW . "','" . NOW . "')");
- $notificationid = $parent->lastInsertId();
- $data = array('notification_id' => $notificationid, 'title' => $notificationtitle, 'message' => $notificationtext, 'notificationtype' => $notificationtype, 'notificationdata' => $notificationdata, 'created_date' => NOW);
- $ins_arr = array();
- foreach ($check_user_arr as $res_user) {
- $ins_arr[] = " ('" . $notificationid . "', '" . $res_user->userid . "', '0', '" . NOW . "')";
- }
- $insert_chunk = array_chunk($ins_arr, 1000);
- foreach ($insert_chunk as $chunk_ins) {
- $parent->executeQuery("INSERT INTO " . TABLE_NOTIFICATION_USER . "(`notificationid`, `userid`, `status`, `created_on`) VALUES " . @implode(',', $chunk_ins) . " ON DUPLICATE KEY UPDATE `status` =0");
- }
- $usertokenarr = array('ios' => array(), 'android' => array());
- $user_device_str = "SELECT ud.devicetype,ud.token FROM `" . TABLE_USER_DEVICES . "` as ud JOIN (SELECT userid FROM " . TABLE_NOTIFICATION_USER . " WHERE notificationid='" . $notificationid . "') as u ON ud.userid=u.userid WHERE ud.is_deleted='0' AND (devicetype='ios' OR devicetype='android') AND token!=''";
- $user_device_arr = $parent->getQueryValue($user_device_str);
- if (count($user_device_arr) > 0) {
- if (strtolower($user_device_arr[0]->devicetype) == 'ios') {
- $usertokenarr['ios'][] = $user_device_arr[0]->token;
- } else if (strtolower($user_device_arr[0]->devicetype) == 'android') {
- $usertokenarr['android'][] = $user_device_arr[0]->token;
- }
- // globalfunc::sendUserNotification($data, $usertokenarr);
- }
- $smpin_quotes = array_map("quotes_array", $all_smpin_arr);
- $check_userstr = "SELECT * FROM " . TABLE_USER . " WHERE smpin IN (" . @implode(',', $smpin_quotes) . ") AND role>7 AND role<14 AND is_deleted=0 AND status=1";
- $user_data_arr = $parent->getQueryValue($check_userstr);
- $userdata = (count($user_data_arr) > 0) ? $user_data_arr[0]->fname . " " . $user_data_arr[0]->lname . " smpin: " . $user_data_arr[0]->smpin : '';
- foreach ($check_user_arr as $res_user) {
- $subject = 'Sales target has been submitted by Dealer';
- $message = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
- <tr>
- <td><table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
- <tr>
- <td bgcolor="#4d90fe" height="36" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#070000; text-align:left; font-weight:bold; padding-left:14px; color:#fff">' . $mail_obj->subject . '</td>
- </tr>
- <tr>
- <td bgcolor="#333333" style="line-height:3px;"> </td>
- </tr>
- <tr><td style="font-size:12px; font-family:Arial, Helvetica, sans-serif;color:#3f3f3f;text-align:left; padding-left:20px;padding-right:20px;padding-bottom:20px; line-height:1.5"><br>SET SALES TARGET UPDATED BY DEALER (' . $res_user->dealer_name . ' ' . $res_user->dealer_code . ') FOR USER - (' . $userdata . ')</td></tr>
- <tr>
- <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#3f3f3f; background:#fafafa; line-height:30px; text-align:center;"><div class="footer-con">
- <p>Thanks & Regards, <strong style="color:#070000;">HYPER-M Support Team</strong></p>
- </div></td>
- </tr>
- <tr>
- <td bgcolor="#4d90fe" style="line-height:1px;"> </td>
- </tr>
- </table></td>
- </tr>
- </table>';
- $obj = array();
- $obj['from'] = SUPPORT_EMAIL;
- $obj['to'] = $res_user->emailid;
- $obj['subject'] = $subject;
- $obj['message'] = $message;
- // globalfunc::sendMai($parent, $obj);
- }
- }
- }
- }
- }
- //LOG
- $logstr = 'SALES TARGET UPDATE';
- globalfunc::insertUserLog($parent, $logstr);
- $user_arr = array();
- // $user_cond=" and u.smpin='".$smpin."'";
- // $get_user_str="SELECT e.`smpin`, e.`emp_code`,e. `fname`,e.`lname`,e.emp_code,u.userid,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM ".DMS_EMPLOYEE." e LEFT JOIN ".TABLE_USER." u ON u.smpin=e.smpin LEFT JOIN ".DMS_DEALER." d ON e.dealer_code=d.dealer_code WHERE e.status='1' AND e.smpin!='' ".$user_cond." LIMIT 1";
- // $user_arr=$parent->getQueryValue($get_user_str);
- // if(count($user_arr)>0)
- // {
- // foreach($user_arr as $ukey=>$res)
- // {
- // $user_target= projectfunc::userSmpinSalesTarget($parent,$res->smpin,'',$year,$month);
- // $user_arr[$ukey]->salestarget= $user_target;
- // $user_arr[$ukey]->model=array();
- //
- // //GET MODEL
- // $query_modelarr=$parent->selectQuery(TABLE_MODEL,"model_id, model_name,model_image ","model_is_target=1 ORDER BY model_id","");
- // if($query_modelarr['nr'])
- // {
- //
- // foreach($query_modelarr['result'] as $res_model)
- // {
- //
- // $user_target= projectfunc::userSmpinSalesTarget($parent,$res->smpin,$res_model->model_name,$year,$month);
- // if($user_target>0)
- // {
- // $mobj = new stdClass();
- // $mobj->model_id=$res_model->model_id;
- // $mobj->model_name=$res_model->model_name;
- // $mobj->target=$user_target;
- // $mobj->achieved= projectfunc::userSmpinSalesAchieved($parent,$res->smpin,$res_model->model_name,$year,$month);
- //
- // $mobj->model_image_url=($res_model->model_image!='')?SITE_URL."hypermupload/model/".$res_model->model_image:NOIMAGE_URL;
- // $user_arr[$ukey]->model[]=$mobj;
- // }else{
- //
- // $mobj = new stdClass();
- // $mobj->model_id=$res_model->model_id;
- // $mobj->model_name=$res_model->model_name;
- // $mobj->target='0';
- // $mobj->achieved= projectfunc::userSmpinSalesAchieved($parent,$res->smpin,$res_model->model_name,$year,$month);
- //
- // $mobj->model_image_url=($res_model->model_image!='')?SITE_URL."hypermupload/model/".$res_model->model_image:NOIMAGE_URL;
- // $user_arr[$ukey]->model[]=$mobj;
- //
- // }
- // }
- // }
- //
- // }
- // }else
- // {
- // $user_arr=array();
- // }
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// SURVEY REPORT LIST //////////////////////////////////////////////// */
- private function surveylist($parent)
- {
- globalfunc::checkMethodType($parent, array('GET'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- $query_cond = "";
- switch ($role) {
- case '3': //HO Manager
- $query_cond .= "";
- break;
- case '4': //Zonal Manager
- $get_zone_str = "SELECT zone FROM " . DMS_DEALER . " WHERE zm_email='" . $userdata->emailid . "' AND status='1' AND is_deleted='0' GROUP BY zone ";
- $zone_arr = $parent->getQueryValue($get_zone_str);
- if (count($zone_arr) > 0) {
- foreach ($zone_arr as $res_zone) {
- $zone_cond_arr[] = " filter_zone LIKE '%" . $res_zone->zone . "%'";
- }
- $query_cond .= " AND (filter_zone='' OR " . @implode(" OR ", $zone_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_zone='') ";
- }
- break;
- case '5': //Trainer
- $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $res_user->userid . "' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $query_cond = " AND (filter_zone='' OR filter_zone LIKE '%" . $trainer_arr[0]->zone . "%') ";
- break;
- case '6': //Regional Manager
- $get_city_str = "SELECT city,zone FROM " . DMS_DEALER . " WHERE rm_email='" . $userdata->emailid . "' AND status='1' AND is_deleted='0' GROUP BY city ";
- $city_arr = $parent->getQueryValue($get_city_str);
- if (count($city_arr) > 0) {
- $zone_arr = array();
- foreach ($city_arr as $res_city) {
- if (!in_array($res_city->zone, $zone_arr)) {
- $zone_arr[] = $res_city->zone;
- }
- $city_cond_arr[] = " filter_region LIKE '%" . $res_city->city . "%'";
- }
- $query_cond .= " AND ( filter_region='' OR " . @implode(" OR ", $city_cond_arr) . " ) ";
- if (count($zone_arr) > 0) {
- foreach ($zone_arr as $zone) {
- $zone_cond_arr[] = " filter_zone LIKE '%" . $zone . "%'";
- }
- $query_cond .= " AND (filter_zone='' OR " . @implode(" OR ", $zone_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_zone='') ";
- }
- } else {
- $query_cond .= " AND (filter_region='' AND filter_zone='') ";
- }
- break;
- case '7': //Area Manager
- $get_dealer_str = "SELECT dealer_code,city,zone FROM " . DMS_DEALER . " WHERE am_email='" . $userdata->emailid . "' AND status='1' AND is_deleted='0' GROUP BY dealer_code ";
- $dealer_arr = $parent->getQueryValue($get_dealer_str);
- if (count($dealer_arr) > 0) {
- $zone_arr = array();
- $city_arr = array();
- foreach ($dealer_arr as $res_dealer) {
- if (!in_array($res_dealer->zone, $zone_arr)) {
- $zone_arr[] = $res_dealer->zone;
- }
- if (!in_array($res_dealer->city, $city_arr)) {
- $city_arr[] = $res_dealer->city;
- }
- $dealer_cond_arr[] = " filter_dealer LIKE '%" . $res_dealer->dealer_code . "%'";
- }
- $query_cond .= " AND ( filter_dealer='' OR " . @implode(" OR ", $dealer_cond_arr) . " ) ";
- if (count($zone_arr) > 0) {
- foreach ($zone_arr as $zone) {
- $zone_cond_arr[] = " filter_zone LIKE '%" . $zone . "%'";
- }
- $query_cond .= " AND (filter_zone='' OR " . @implode(" OR ", $zone_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_zone='') ";
- }
- if (count($city_arr) > 0) {
- foreach ($city_arr as $city) {
- $city_cond_arr[] = " filter_region LIKE '%" . $city . "%'";
- }
- $query_cond .= " AND (filter_region='' OR " . @implode(" OR ", $city_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_region='') ";
- }
- } else {
- $query_cond .= " AND (filter_dealer='' AND filter_region='' AND filter_zone='') ";
- }
- break;
- case '14': //Dealer
- $get_dealer_str = "SELECT dealer_code,city,zone FROM " . DMS_DEALER . " WHERE dealer_code='" . $userdata->dealer_code . "' GROUP BY dealer_code LIMIT 1 ";
- $dealer_arr = $parent->getQueryValue($get_dealer_str);
- if (count($dealer_arr) > 0) {
- $zone_arr = array();
- $city_arr = array();
- foreach ($dealer_arr as $res_dealer) {
- if (!in_array($res_dealer->zone, $zone_arr)) {
- $zone_arr[] = $res_dealer->zone;
- }
- if (!in_array($res_dealer->city, $city_arr)) {
- $city_arr[] = $res_dealer->city;
- }
- $dealer_cond_arr[] = " filter_dealer LIKE '%" . $res_dealer->dealer_code . "%'";
- }
- $query_cond .= " AND ( filter_dealer='' OR " . @implode(" OR ", $dealer_cond_arr) . " ) ";
- if (count($zone_arr) > 0) {
- foreach ($zone_arr as $zone) {
- $zone_cond_arr[] = " filter_zone LIKE '%" . $zone . "%'";
- }
- $query_cond .= " AND (filter_zone='' OR " . @implode(" OR ", $zone_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_zone='') ";
- }
- if (count($city_arr) > 0) {
- foreach ($city_arr as $city) {
- $city_cond_arr[] = " filter_region LIKE '%" . $city . "%'";
- }
- $query_cond .= " AND (filter_region='' OR " . @implode(" OR ", $city_cond_arr) . " ) ";
- } else {
- $query_cond .= " AND (filter_region='') ";
- }
- } else {
- $query_cond .= " AND (filter_dealer='' AND filter_region='' AND filter_zone='') ";
- }
- break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $data_arr = array();
- //GET COUNT
- $assessment_str = "SELECT assessmentid,assessmentname FROM " . TABLE_ASSESSMENT . " WHERE status='1' AND assettypeid='2' AND publisheddate<='" . NOW . "' " . $user_cond . $query_cond . " ORDER BY assessmentid ASC";
- $get_assessment_arr = $parent->getQueryValue($assessment_str);
- if (count($get_assessment_arr) > 0) {
- $data_arr = $get_assessment_arr;
- }
- //LOG
- $logstr = 'SURVEY REPORT LIST';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// SURVEY REPORT //////////////////////////////////////////////// */
- private function surveyreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $dealer_code_cond = '';
- if ($parent->current_user_role == '7') {
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- $emailid = $userdata->emailid;
- } else {
- //AREA MANAGER LEVEL REPORT
- $role = '7';
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('area' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $area_manager = escape_str($parent->_request["area"]);
- $emailid = $area_manager;
- }
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('assessmentid' => 'integer');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $assessmentid = escape_str($parent->_request["assessmentid"]);
- $user_cond = "";
- switch ($role) {
- case '3': //HO Manager
- $user_cond .= "";
- break;
- case '4': //Zonal Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE zm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '5': //Trainer
- $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.emailid='" . $emailid . "' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $zone_cond .= (count($trainer_arr) > 0) ? " zone='" . $trainer_arr[0]->zone . "'" : " zone='0'";
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE " . $zone_cond . " AND status='1' AND is_deleted='0')";
- break;
- case '6': //Regional Manager
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE rm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- break;
- case '7': //Area Manager
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " AND dealer_code='" . $parent->current_user_data->dealer_code . "'";
- }
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE am_email='" . $emailid . "' " . $dealer_code_cond . " AND status='1' AND is_deleted='0')";
- break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.smpin,u.emp_code,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name,au.modified_on as assessment_date FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.status='1' AND u.is_deleted='0' AND u.role>7 AND u.role<14 AND au.assessmentid='" . $assessmentid . "' AND au.highscorearid!='0' " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- /*
- foreach($user_arr as $mkey=>$res_user)
- {
- //$exam_highscore_str = "SELECT * FROM ".TABLE_ASSESSMENT_USER." WHERE assessmentid='".$assessmentid."' AND userid='".$res_user->userid."' LIMIT 1";
- //$exam_highscore_arr=$parent->getQueryValue($exam_highscore_str);
- //$user_arr[$mkey]->highscore=(count($exam_highscore_arr)>0)?$exam_highscore_arr[0]->highscore:'0';
- }
- */
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.status='1' AND u.is_deleted='0' AND u.role>7 AND u.role<14 AND au.assessmentid='" . $assessmentid . "' AND au.highscorearid!='0' " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'SURVEY REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// SURVEY USER REPORT //////////////////////////////////////////////// */
- private function surveyuserreport($parent)
- {
- globalfunc::checkMethodType($parent, array('GET'));
- globalfunc::checkParamCount($parent, 3);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $assessmentid = escape_str($parent->params[1]);
- $userid = escape_str($parent->params[2]);
- $query_str = "SELECT assessmentid,assessmentname FROM " . TABLE_ASSESSMENT . " WHERE status='1' AND assettypeid='2' AND assessmentid='" . $assessmentid . "' AND publisheddate<='" . NOW . "' LIMIT 1";
- $query_arr = $parent->getQueryValue($query_str);
- if (!count($query_arr) > 0) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error9"]), 406);
- }
- //GET USER ATTENTED
- $query_assess_str = "SELECT * FROM " . TABLE_ASSESSMENT_USER . " WHERE userid='" . $userid . "' AND assessmentid='" . $assessmentid . "' AND highscorearid!='0' LIMIT 1";
- $query_assess_arr = $parent->getQueryValue($query_assess_str);
- if (!count($query_assess_arr) > 0) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error10"]), 406);
- }
- //GET USER RESULT
- $query_res_str = "SELECT au.* FROM " . TABLE_ASSESSMENT_USERRESULT . " as au JOIN " . TABLE_ASSESSMENTRESULT . " as ar ON au.arid=ar.arid WHERE au.userid='" . $userid . "' AND au.assessmentid='" . $assessmentid . "' AND au.arid='" . $query_assess_arr[0]->highscorearid . "' ";
- $query_assess_res_arr = $parent->getQueryValue($query_res_str);
- if (!count($query_assess_arr) > 0) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error10"]), 406);
- }
- if (count($query_assess_res_arr) > 0) {
- //CONNECT S3
- $s3 = awsfileserver::connectS3();
- //RATING
- $survey_str = "SELECT * FROM " . TABLE_SURVEY_RATING . " ORDER BY id ASC";
- $survey_arr = $parent->getQueryValue($survey_str);
- if (count($survey_arr) > 0) {
- foreach ($survey_arr as $skey => $res_survey) {
- $rating_arr[$res_survey->id] = $res_survey->rating_text;
- }
- }
- foreach ($query_assess_res_arr as $res) {
- $ques_str = "SELECT q.id as qid, q.`questiontypeid`, q.`questiontext`, q.`qimage`, q.`qvideo` FROM " . TABLE_QUESTION . " as q WHERE id='" . $res->qid . "' LIMIT 1";
- $ques_arr = $parent->getQueryValue($ques_str);
- if (count($ques_arr) > 0) {
- //QUESTION IMAGE
- // $ques_arr[0]->qimage_url='';
- // if($ques_arr[0]->qimage!='')
- // {
- // $ques_arr[0]->qimage_url=awsfileserver::getS3FileUrl($s3,S3_BUCKET,S3_QUESTION_URL.$ques_arr[0]->qimage);
- // }
- //QUESTION VIDEO
- // $ques_arr[0]->qvideo_url='';
- // if($ques_arr[0]->qvideo!='')
- // {
- // $ques_arr[0]->qvideo_url=awsfileserver::getS3FileUrl($s3,S3_BUCKET,S3_QUESTION_URL.$ques_arr[0]->qvideo);
- // }
- //GET USER ANSWERED OPTIONS
- $user_answer_str = "SELECT * FROM " . TABLE_ASSESSMENT_USERRESULT . " WHERE userid='" . $userid . "' AND arid='" . $res->arid . "' AND aqid='" . $res->aqid . "'";
- $user_answer_arr = $parent->getQueryValue($user_answer_str);
- //GET RATING
- //$ques_arr[0]->rating_options=array();
- $ques_arr[0]->survey_text = '';
- //$ques_arr[0]->options=array();
- //print_r($ques_arr);
- $ques_arr[0]->answer = '';
- if ($ques_arr[0]->questiontypeid == '3') {
- $rating = $user_answer_arr[0]->survey_rating;
- $ques_arr[0]->answer = $rating_arr[$rating];
- } elseif ($ques_arr[0]->questiontypeid == '5' || $ques_arr[0]->questiontypeid == '6') {
- //GET ALL QUESTION OPTIONS
- if ($user_answer_arr[0]->choiseid) {
- $ques_option_str = "SELECT op.optid,op.opttext,'0' as selected FROM " . TABLE_QUESTIONOPTION . " as op WHERE op.qid='" . $res->qid . "' AND optid='" . $user_answer_arr[0]->choiseid . "' LIMIT 1";
- $ques_option_arr = $parent->getQueryValue($ques_option_str);
- if (count($ques_option_arr) > 0) {
- $ques_arr[0]->answer = $ques_option_arr[0]->opttext;
- }
- }
- } else {
- $ques_arr[0]->answer = (count($user_answer_arr) > 0 && $user_answer_arr[0]->survey_text != '') ? $user_answer_arr[0]->survey_text : '';
- }
- $result_arr[] = $ques_arr[0];
- }
- }
- }
- //LOG
- $logstr = 'SURVEY USER REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'data' => $result_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* /////////////////////////////// ASSESSMENT //////////////////////////////////////// */
- private function assessmentleaderboardreportnew($parent)
- {
- //assessment/sales/{{year}}/{{month}}
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('email' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $email = escape_str($parent->_request["email"]);
- if (count($parent->params) == 1) {
- $get_dealer_str = "SELECT dealer_code,city,zone FROM " . DMS_DEALER . " WHERE am_email='" . $email . "' AND status='1' AND is_deleted='0' GROUP BY dealer_code ";
- $dealer_arr = $parent->getQueryValue($get_dealer_str);
- //AREA LEADERBOARD COND
- //$dealer_code=$parent->current_user_data->dealer_code;
- // $query_allareadealerarr=$parent->selectQuery(DMS_DEALER,"`dealer_code`,am_email "," dealer_code='".$dealer_code."' AND status='1' AND is_deleted='0'","1");
- /*
- $dealer_arr=array();
- if($query_allareadealerarr['nr'])
- {
- $join_cond="JOIN ".DMS_DEALER." as d ON d.dealer_code=u.dealer_code ";
- $area_cond=" and d.am_email ='".$query_allareadealerarr['result'][0]->am_email."'";
- }else
- {
- $area_cond=" and u.dealer_code IN ('')";
- }
- */
- $join_cond = 'JOIN ' . DMS_DEALER . ' as d ON d.dealer_code=u.dealer_code ';
- $start_date = date('Y-m', strtotime(CUR_DATE)) . "-01";
- $end_date = date('Y-m-t', strtotime(CUR_DATE));
- $date_cond = " AND a.publisheddate>='" . $start_date . " 00:00:00' AND a.publisheddate<='" . $end_date . " 23:59:59'";
- } else if (count($parent->params) == 2) {
- //FOR PANINDIA,ZONE,REGION WISE LEADER BOARD
- $dealer_code = $parent->current_user_data->dealer_code;
- $type_data = explode('?', strtolower(escape_str($parent->params[1])));
- switch ($type_data[0]) {
- case "panindia":
- /*$start_date=date('Y', strtotime(CUR_DATE))."-01-01";
- $end_date=date('Y',strtotime(CUR_DATE))."-12-31";
- *
- */
- $start_date = date('Y-m', strtotime(CUR_DATE)) . "-01";
- $end_date = date('Y-m-t', strtotime(CUR_DATE));
- //COND
- $join_cond = 'JOIN ' . DMS_DEALER . ' as d ON d.dealer_code=u.dealer_code ';
- $area_cond = '';
- $date_cond = " AND a.publisheddate>='" . $start_date . " 00:00:00' AND a.publisheddate<='" . $end_date . " 23:59:59'";
- break;
- case "zone":
- $cur_month = date('m', strtotime(CUR_DATE));
- /*
- if(in_array($cur_month,array('01','02','03','04','05','06')))
- {
- $start_date=date('Y', strtotime(CUR_DATE))."-01-01";
- $end_date=date('Y',strtotime(CUR_DATE))."-06-30";
- }else if(in_array($cur_month,array('07','08','09','10','11','12')))
- {
- $start_date=date('Y', strtotime(CUR_DATE))."-07-01";
- $end_date=date('Y', strtotime(CUR_DATE))."-12-31";
- }
- */
- $start_date = date('Y-m', strtotime(CUR_DATE)) . "-01";
- $end_date = date('Y-m-t', strtotime(CUR_DATE));
- $date_cond = " AND a.publisheddate>='" . $start_date . " 00:00:00' AND a.publisheddate<='" . $end_date . " 23:59:59'";
- //COND
- /*
- $query_allareadealerarr=$parent->selectQuery(DMS_DEALER,"`dealer_code`,zm_email "," dealer_code='".$dealer_code."' AND status='1' AND is_deleted='0'","1");
- $dealer_arr=array();
- if($query_allareadealerarr['nr'])
- {
- $join_cond="JOIN ".DMS_DEALER." as d ON d.dealer_code=u.dealer_code ";
- $area_cond=" and d.zm_email ='".$query_allareadealerarr['result'][0]->zm_email."'";
- }else
- {
- $area_cond=" and u.dealer_code IN ('')";
- }
- */
- $get_dealer_str = "SELECT dealer_code,city,zone FROM " . DMS_DEALER . " WHERE zm_email='" . $email . "' AND status='1' AND is_deleted='0' GROUP BY dealer_code ";
- $dealer_arr = $parent->getQueryValue($get_dealer_str);
- if (count($dealer_arr) > 0) {
- $join_cond = "JOIN " . DMS_DEALER . " as d ON d.dealer_code=u.dealer_code ";
- $area_cond = " and d.zm_email ='" . $email . "'";
- } else {
- $join_cond = "JOIN " . DMS_DEALER . " as d ON d.dealer_code=u.dealer_code ";
- $area_cond = " and u.dealer_code IN ('')";
- }
- break;
- case "region":
- $cur_month = date('m', strtotime(CUR_DATE));
- /*
- if(in_array($cur_month,array('01','02','03')))
- {
- $start_date=date('Y', strtotime(CUR_DATE))."-01-01";
- $end_date=date('Y',strtotime(CUR_DATE))."-03-31";
- }else if(in_array($cur_month,array('04','05','06')))
- {
- $start_date=date('Y', strtotime(CUR_DATE))."-04-01";
- $end_date=date('Y',strtotime(CUR_DATE))."-06-30";
- }else if(in_array($cur_month,array('07','08','09')))
- {
- $start_date=date('Y', strtotime(CUR_DATE))."-07-01";
- $end_date=date('Y',strtotime(CUR_DATE))."-09-30";
- }else if(in_array($cur_month,array('10','11','12')))
- {
- $start_date=date('Y', strtotime(CUR_DATE))."-10-01";
- $end_date=date('Y', strtotime(CUR_DATE))."-12-31";
- }
- */
- $start_date = date('Y-m', strtotime(CUR_DATE)) . "-01";
- $end_date = date('Y-m-t', strtotime(CUR_DATE));
- $date_cond = " AND a.publisheddate>='" . $start_date . " 00:00:00' AND a.publisheddate<='" . $end_date . " 23:59:59'";
- $get_dealer_str = "SELECT dealer_code,city,zone FROM " . DMS_DEALER . " WHERE rm_email='" . $email . "' AND status='1' AND is_deleted='0' GROUP BY dealer_code ";
- $dealer_arr = $parent->getQueryValue($get_dealer_str);
- if (count($dealer_arr) > 0) {
- $join_cond = "JOIN " . DMS_DEALER . " as d ON d.dealer_code=u.dealer_code ";
- $area_cond = " and d.rm_email ='" . $email . "'";
- } else {
- $join_cond = "JOIN " . DMS_DEALER . " as d ON d.dealer_code=u.dealer_code ";
- $area_cond = " and u.dealer_code IN ('')";
- }
- //COND
- /*
- $query_allareadealerarr=$parent->selectQuery(DMS_DEALER,"`dealer_code`,rm_email "," dealer_code='".$dealer_code."' AND status='1' AND is_deleted='0'","1");
- $dealer_arr=array();
- if($query_allareadealerarr['nr'])
- {
- $join_cond="JOIN ".DMS_DEALER." as d ON d.dealer_code=u.dealer_code ";
- $area_cond=" and d.rm_email ='".$query_allareadealerarr['result'][0]->rm_email."'";
- }else
- {
- $area_cond=" and u.dealer_code IN ('')";
- }
- */
- break;
- default:
- $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
- break;
- }
- } else {
- $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
- }
- if ($parent->current_user_role == '14') {
- $area_cond .= " AND u.dealer_code='" . $dealer_code . "'";
- }
- $new_cond = 'AND a.user_type=0 ';
- //GET ALL ASSESSMENT LIST WHICH PUBLISHED
- $assessment_str = "SELECT a.* FROM `" . TABLE_ASSESSMENT . "` as a WHERE a.status='1' AND a.atype='0' AND a.assettypeid='1' " . $date_cond . $new_cond;
- $assessment_arr = $parent->getQueryValue($assessment_str);
- //ASSESSMENT COUNT
- $assessment_count = (count($assessment_arr) > 0) ? count($assessment_arr) : '0';
- $data_arr = array();
- if (count($assessment_arr) > 0) {
- foreach ($assessment_arr as $res_assess) {
- $assessmentid_arr[] = $res_assess->assessmentid;
- }
- //GET ALL 20 USER RANK
- //$parent->executeQuery("SET @rownum := 0");
- $get_user_rank_str = "SELECT SUM(highscore)as user_score,u.userid,COALESCE(ar.total_time,'0')as total_time,MAX(au.modified_on) as last_modified,u.dealer_code,u.role,d.* FROM " . TABLE_USER . " as u JOIN (SELECT * FROM " . TABLE_ASSESSMENT_USER . " WHERE assessmentid IN (" . @implode(',', $assessmentid_arr) . ") AND highscorearid!=0 ) as au ON u.userid=au.userid LEFT JOIN (SELECT SUM(time_taken)as total_time,assessmentid,userid FROM " . TABLE_ASSESSMENTRESULT . " WHERE assessmentid IN (" . @implode(',', $assessmentid_arr) . ") GROUP BY userid )as ar ON u.userid=ar.userid " . $join_cond . " WHERE u.role>'7' AND u.role<14 AND u.is_deleted=0 " . $area_cond . " GROUP BY u.userid ORDER BY user_score DESC,ar.total_time ASC,last_modified ASC,u.userid ASC ";
- $get_user_rank_arr = $parent->getQueryValue($get_user_rank_str);
- if ($get_user_rank_arr) {
- foreach ($get_user_rank_arr as $res_user) {
- $user_data_arr = new stdClass();
- $get_time_str = "SELECT * FROM " . TABLE_ASSESSMENTRESULT . " WHERE assessmentid IN (" . @implode(',', $assessmentid_arr) . ") AND userid='" . $res_user->userid . "'";
- $get_time_arr = $parent->getQueryValue($get_time_str);
- $user_data_arr->user = projectfunc::getuserdata($parent, $res_user->userid);
- $user_data_arr->rank = '0';
- $user_data_arr->tot_user_score = (count($get_time_arr) > 0) ? $res_user->user_score : '-';
- $user_data_arr->percentage_score = (count($get_time_arr) > 0) ? '0' : '-';
- $user_data_arr->total_time = $res_user->total_time;
- $user_data_arr->last_time = (count($get_time_arr) > 0) ? $res_user->last_modified : '-';
- $user_cond = array();
- //GET EACH USER COND
- $getuser_data = projectfunc::getuserdata($parent, $res_user->userid);
- if ($getuser_data->role) {
- $user_cond[] = " (a.filter_role LIKE '%" . $getuser_data->role . "%' OR a.filter_role='')";
- }
- if ($getuser_data->zone) {
- $user_cond[] = " (a.filter_zone LIKE '%" . $getuser_data->zone . "%' OR a.filter_zone='')";
- }
- if ($getuser_data->city) {
- $user_cond[] = " (a.filter_region LIKE '%" . $getuser_data->city . "%' OR a.filter_region='')";
- }
- if ($getuser_data->dealer_code) {
- $user_cond[] = " (a.filter_dealer LIKE '%" . $getuser_data->dealer_code . "%' OR a.filter_dealer='')";
- }
- $assess_user_cond = " AND " . @implode(' AND ', $user_cond);
- $count_assessment_str = "SELECT COUNT(a.assessmentid) as acount FROM `" . TABLE_ASSESSMENT . "` as a WHERE a.status='1' AND a.atype='0' AND a.assettypeid='1' AND a.publisheddate>='" . $start_date . " 00:00:00' AND a.publisheddate<='" . $end_date . " 23:59:59' AND a.enddate>='" . $user_data_arr->user->user_created_on . "' AND assessmentid IN (" . @implode(',', $assessmentid_arr) . ") " . $assess_user_cond . $new_cond . " LIMIT 1";
- $count_assessment_arr = $parent->getQueryValue($count_assessment_str);
- $user_data_arr->percentage_score = (count($assessment_arr) > 0) ? round($res_user->user_score / $count_assessment_arr[0]->acount) : '0';
- $user_data_arr->percentage = $user_data_arr->percentage_score;
- if ((($assessment_count / $count_assessment_arr[0]->acount) * 100) >= MIN_ASSESSMENT_PERCENT) {
- $data_arr[] = $user_data_arr;
- }
- }
- }
- if (count($data_arr) > 0) {
- $outof = count($data_arr);
- array_multisort(array_column($data_arr, 'percentage_score'), SORT_DESC, array_column($rank_arr, 'total_time'), SORT_ASC, $rank_arr);
- $rank = 1;
- foreach ($data_arr as $key => $res) {
- $data_arr[$key]->rank = $rank;
- $data_arr[$key]->outof = $outof;
- $rank++;
- }
- }
- } else {
- /*
- $cur_data_arr=new stdClass();
- $udata=projectfunc::getuserdata($parent,$parent->current_user_id);
- $cur_data_arr->user=$udata;
- foreach($udata as $key=>$res)
- {
- $cur_data_arr->$key=$res;
- }
- $cur_data_arr->rank='-';
- $cur_data_arr->tot_user_score='-';
- $cur_data_arr->percentage_score='-';
- $cur_data_arr->percentage=$cur_data_arr->percentage_score;
- $cur_data_arr->total_time='0';
- $cur_data_arr->last_time='-';
- */
- $get_count_arr = array();
- }
- $total_count = count($data_arr);
- /*if(count($data_arr)>0)
- {
- $temp=array_chunk($data_arr,20);
- $data_arr=$temp[0];
- }
- */
- //LOG
- $logstr = 'LEADERBOARD ASSESSMENT';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// UPLOAD TARGET SALE //////////////////////////////////////// */
- private function uploadtargetsale($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- //CHECK FILE
- if (!isset($_FILES['file'])) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data['error11']), 406);
- }
- switch ($parent->current_user_role) {
- case "14": //Dealer
- case "7": //Area Manager
- case "6": //Regional Manager
- case "5": //Trainer
- case "4": //Zonal Manager
- case "3": //HO Manager
- break;
- default:
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error2"]), 406);
- break;
- }
- //AREA
- $REQUEST_KEYS = array('area' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $area_manager = escape_str($parent->_request["area"]);
- //CONNECT S3
- $s3 = awsfileserver::connectS3();
- //IMAGE UPLOAD
- $obj = new stdClass();
- $obj->filekey = 'file';
- $obj->size = '100'; //IN MB
- $obj->type = array('xlsx');
- globalfunc::validateFile($parent, $obj);
- $obj->path = "../../" . S3_REPORT_URL;
- $obj->filename = 'import_sales_target_' . date('Ymd') . "_" . uniqid();
- //if(isset($parent->_request['width']))$obj->width=$parent->_request['width'];
- //if(isset($parent->_request['height']))$obj->height=$parent->_request['height'];
- //$obj->cord=(isset($parent->_request['cord']))?$parent->_request['cord']:NULL;
- $fileName = globalfunc::uploadFile($parent, $obj);
- awsfileserver::checkupload($parent, $s3, S3_BUCKET, S3_REPORT_URL . $fileName, dirname(__FILE__) . "/../../../" . S3_REPORT_URL . $fileName);
- //UNLINK
- require dirname(__FILE__) . '/../../excelreader/excel_reader2.php';
- require dirname(__FILE__) . '/../../excelreader/SpreadsheetReader.php';
- $Spreadsheet = @new SpreadsheetReader("../../" . S3_REPORT_URL . $fileName);
- $Spreadsheet->ChangeSheet(0);
- //print_r($Spreadsheet);
- $excelhead = "TARGET SALES";
- $query_user_str = "SELECT * FROM `" . DMS_DEALER . "` WHERE am_email='" . $area_manager . "' AND status='1' AND is_deleted='0' LIMIT 1";
- $query_user_arr = $parent->getQueryValue($query_user_str);
- $logstr = 'UPLOAD TARGET SALE';
- globalfunc::insertUserLog($parent, $logstr);
- $insert_row = 0;
- $ins_qryarr = array();
- $smpin_arr = array();
- $model_arr = array();
- $ins_arr = array();
- $delete_arr = array();
- $ins_log_arr = array();
- if (count($query_user_arr) > 0) {
- if (count($Spreadsheet) > 0) {
- foreach ($Spreadsheet as $Key => $Row) {
- if ($Key <= 1) {
- } else {
- $i = 0;
- if ($Key == '2') {
- for ($i = 4; $i < count($Row); $i++) {
- $model_arr[$i] = $Row[$i];
- }
- $model_quotes = array_map("quotes_array", $model_arr);
- $query_model_str = "SELECT * FROM `" . TABLE_MODEL . "` WHERE model_name IN (" . @implode(',', $model_quotes) . ")";
- $query_model_arr = $parent->getQueryValue($query_model_str);
- if (count($query_model_arr) != count($model_arr)) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error12"]), 406);
- }
- } else {
- //print_r($Row);
- $smpin = $Row[0];
- $name = $Row[1];
- $mobile = $Row[2];
- $dealer_details = $Row[3];
- $delete_arr[] = "DELETE FROM " . TABLE_USER_SALETARGET . " WHERE smpin='" . $smpin . "' AND sale_month>='" . date("Y-m", strtotime(NOW)) . "-01' AND sale_month<'" . date('Y-m', strtotime('+1 month', strtotime(NOW))) . "-01'";
- foreach ($model_arr as $mkey => $name) {
- $ins_arr[] = "('" . $smpin . "', '" . $name . "', '" . $parent->current_user_id . "', '" . date("Y-m", strtotime(NOW)) . "-01', '" . $Row[$mkey] . "','" . NOW . "', '" . NOW . "')";
- $ins_log_arr[] = "('" . $smpin . "','" . $name . "','" . $parent->current_user_role . "','" . $parent->current_user_id . "','" . date("Y-m", strtotime(NOW)) . "-01','" . $Row[$mkey] . "','" . NOW . "')";
- }
- $smpin_arr[] = $smpin;
- $insert_row++;
- //EXCEL UPLOAD CHECK
- $is_edit = projectfunc::setSaleEditpermisson($parent, $smpin, date("Y-m", strtotime(NOW)) . "-01");
- if ($is_edit != 1) {
- $manager_error = ($parent->manager_error) ? $parent->manager_error : $this->page_data["error6"];
- $parent->response(array('response' => 'failed', 'message' => $manager_error), 406);
- }
- }
- }
- }
- if (count($smpin_arr) > 0) {
- $smpin__quote_arr = array_map("quotes_array", $smpin_arr);
- $query_emp_str = "SELECT * FROM `" . DMS_EMPLOYEE . "` WHERE smpin IN (" . @implode(',', $smpin__quote_arr) . ")";
- $query_emp_arr = $parent->getQueryValue($query_emp_str);
- $unique_ids = array_unique($smpin_arr);
- if (count($unique_ids) != $insert_row) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error13"]), 406);
- }
- if (count($query_emp_arr) != count($smpin_arr)) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error14"]), 406);
- }
- if (count($ins_arr) > 0) {
- if (count($delete_arr) > 0) {
- foreach ($delete_arr as $res_query) {
- $parent->executeQuery($res_query);
- }
- $parent->executeQuery("INSERT INTO " . TABLE_USER_SALETARGET . " (`smpin`, `model`, `am_id`, `sale_month`, `target`, `created_on`, `modified_on`) VALUES " . @implode(',', $ins_arr));
- $parent->executeQuery("INSERT INTO " . TABLE_USER_SALETARGET . " (`smpin`, `model`, `roleid`, `userid`, `sale_month`, `target`, `created_on`) VALUES " . @implode(',', $ins_log_arr));
- }
- }
- if (count($smpin_arr) > 0) {
- $dealer_notification_type = 0;
- foreach ($smpin_arr as $smpin) {
- $status_str = ($parent->current_user_role == '14') ? '1' : '3';
- $parent->executeQuery("INSERT INTO " . TABLE_USER_SALESTARGET_STATUS . " (`smpin`, `roleid`, `userid`, `status`, `sale_month`, `created_on`) VALUES ('" . $smpin . "','" . $parent->current_user_role . "','" . $parent->current_user_id . "','" . $status_str . "','" . date("Y-m", strtotime(NOW)) . "-01','" . NOW . "')");
- }
- //DSE TRIGGER NOTIFICATION
- $notificationtitle = 'Sales target has been updated';
- $notificationtext = 'Sales target has been updated';
- $notificationtype = '5';
- $obj = new stdClass();
- $notificationdata = json_encode($obj);
- $parent->executeQuery("INSERT INTO `" . TABLE_NOTIFICATION . "` ( `notificationtitle`, `notificationtext`, `notificationdata`, `notificationtype`, `status`, `publisheddate`, `created_on`, `modified_on`) VALUES ('" . $notificationtitle . "','" . escape_str($notificationtext) . "','" . $notificationdata . "','" . $notificationtype . "' ,'1','" . NOW . "','" . NOW . "','" . NOW . "')");
- $notificationid = $parent->lastInsertId();
- $data = array('notification_id' => $notificationid, 'title' => $notificationtitle, 'message' => $notificationtext, 'notificationtype' => $notificationtype, 'notificationdata' => $notificationdata, 'created_date' => NOW);
- //TO SMPIN
- $smpin_quotes = array_map("quotes_array", $smpin_arr);
- $check_str = "SELECT userid FROM " . TABLE_USER . " WHERE smpin IN (" . @implode(',', $smpin_quotes) . ") AND role>7 AND role<14 AND is_deleted=0 AND status=1";
- $check_user_arr = $parent->getQueryValue($check_str);
- if (count($check_user_arr)) {
- $ins_arr = array();
- foreach ($check_user_arr as $res_user) {
- $ins_arr[] = " ('" . $notificationid . "', '" . $res_user->userid . "', '0', '" . NOW . "')";
- }
- $insert_chunk = array_chunk($ins_arr, 1000);
- foreach ($insert_chunk as $chunk_ins) {
- $parent->executeQuery("INSERT INTO " . TABLE_NOTIFICATION_USER . "(`notificationid`, `userid`, `status`, `created_on`) VALUES " . @implode(',', $chunk_ins) . " ON DUPLICATE KEY UPDATE `status` =0");
- }
- $usertokenarr = array('ios' => array(), 'android' => array());
- $user_device_str = "SELECT ud.devicetype,ud.token FROM `" . TABLE_USER_DEVICES . "` as ud JOIN (SELECT userid FROM " . TABLE_NOTIFICATION_USER . " WHERE notificationid='" . $notificationid . "') as u ON ud.userid=u.userid WHERE ud.is_deleted='0' AND (devicetype='ios' OR devicetype='android') AND token!=''";
- $user_device_arr = $parent->getQueryValue($user_device_str);
- if (count($user_device_arr) > 0) {
- if (strtolower($user_device_arr[0]->devicetype) == 'ios') {
- $usertokenarr['ios'][] = $user_device_arr[0]->token;
- } else if (strtolower($user_device_arr[0]->devicetype) == 'android') {
- $usertokenarr['android'][] = $user_device_arr[0]->token;
- }
- // globalfunc::sendUserNotification($data, $usertokenarr);
- }
- }
- //DEALER TRIGGER NOTIFICATION
- if ($parent->current_user_role != '14') {
- $notificationtitle = 'Sales target has been modified';
- $notificationtext = 'Sales target has been modified';
- $notificationtype = '5';
- $obj = new stdClass();
- $notificationdata = json_encode($obj);
- $parent->executeQuery("INSERT INTO `" . TABLE_NOTIFICATION . "` ( `notificationtitle`, `notificationtext`, `notificationdata`, `notificationtype`, `status`, `publisheddate`, `created_on`, `modified_on`) VALUES ('" . $notificationtitle . "','" . escape_str($notificationtext) . "','" . $notificationdata . "','" . $notificationtype . "' ,'1','" . NOW . "','" . NOW . "','" . NOW . "')");
- $notificationid = $parent->lastInsertId();
- $data = array('notification_id' => $notificationid, 'title' => $notificationtitle, 'message' => $notificationtext, 'notificationtype' => $notificationtype, 'notificationdata' => $notificationdata, 'created_date' => NOW);
- $smpin_quotes = array_map("quotes_array", $all_smpin_arr);
- $check_str = "SELECT * FROM " . TABLE_USER . " u JOIN (SELECT dealer_code FROM " . DMS_EMPLOYEE . " WHERE smpin IN (" . @implode(',', $smpin_quotes) . ") GROUP BY dealer_code) as e ON e.dealer_code=u.dealer_code WHERE u.role=14";
- $check_user_arr = $parent->getQueryValue($check_str);
- if (count($check_user_arr)) {
- $ins_arr = array();
- foreach ($check_user_arr as $res_user) {
- $ins_arr[] = " ('" . $notificationid . "', '" . $res_user->userid . "', '0', '" . NOW . "')";
- }
- $insert_chunk = array_chunk($ins_arr, 1000);
- foreach ($insert_chunk as $chunk_ins) {
- $parent->executeQuery("INSERT INTO " . TABLE_NOTIFICATION_USER . "(`notificationid`, `userid`, `status`, `created_on`) VALUES " . @implode(',', $chunk_ins) . " ON DUPLICATE KEY UPDATE `status` =0");
- }
- $usertokenarr = array('ios' => array(), 'android' => array());
- $user_device_str = "SELECT ud.devicetype,ud.token FROM `" . TABLE_USER_DEVICES . "` as ud JOIN (SELECT userid FROM " . TABLE_NOTIFICATION_USER . " WHERE notificationid='" . $notificationid . "') as u ON ud.userid=u.userid WHERE ud.is_deleted='0' AND (devicetype='ios' OR devicetype='android') AND token!=''";
- $user_device_arr = $parent->getQueryValue($user_device_str);
- if (count($user_device_arr) > 0) {
- if (strtolower($user_device_arr[0]->devicetype) == 'ios') {
- $usertokenarr['ios'][] = $user_device_arr[0]->token;
- } else if (strtolower($user_device_arr[0]->devicetype) == 'android') {
- $usertokenarr['android'][] = $user_device_arr[0]->token;
- }
- // globalfunc::sendUserNotification($data, $usertokenarr);
- }
- }
- }
- }
- @unlink(dirname(__FILE__) . "/../../../" . S3_REPORT_URL . $fileName);
- $parent->response(array('response' => 'success', 'message' => $this->page_data['success1']), 200);
- } else {
- @unlink(dirname(__FILE__) . "/../../../" . S3_REPORT_URL . $fileName);
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error14"]), 406);
- }
- }
- } else {
- @unlink(dirname(__FILE__) . "/../../../" . S3_REPORT_URL . $fileName);
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error12"]), 406);
- }
- }
- /* /////////////////////////////// NEW REGISTRATION REPORT //////////////////////////////////////////////// */
- private function newregistrationreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 2);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[1]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[1]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- //MANAGER WISE DEALER CONDITION
- $dealer_cond_arr = $this->getmanagerconditon_arr($parent);
- if (count($dealer_cond_arr) > 0) {
- //APPEND prefix
- array_walk($dealer_cond_arr, function (&$value, $key) {$value = 'd.' . $value;});
- $user_cond .= " AND d.status='1' AND d.is_deleted='0' AND " . @implode(" AND ", $dealer_cond_arr);
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[1]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,e.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,e.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,e.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,e.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,e.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,e.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,e.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (e.fname LIKE '%" . $search_txt . "%' OR e.lname LIKE '%" . $search_txt . "%' OR e.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- $user_cond .= " AND e.is_current='1' ";
- //$get_user_str="SELECT e.`smpin`, e.`emp_code`,e. `fname`,e.`lname`,e.emp_code,u.userid,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name,l.created_on as register_date FROM ".DMS_EMPLOYEE." e LEFT JOIN ".TABLE_USER." u ON u.smpin=e.smpin LEFT JOIN ".DMS_DEALER." d ON e.dealer_code=d.dealer_code LEFT JOIN (SELECT userid,created_on FROM ".TABLE_USER_LOG." WHERE module='REGISTER' )as l ON u.userid=l.userid WHERE e.status='1' AND u.is_deleted=0 AND e.smpin!='' ".$user_cond.$order_by_cond.$limit_cond;
- $get_user_str = "SELECT e.`smpin`, e.`emp_code`,e. `fname`,e.`lname`,e.emp_code,u.userid,d.city,d.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name,u.created_on as register_date,u.status FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON e.dealer_code=d.dealer_code WHERE e.status='1' AND e.smpin!='' AND u.is_deleted=0 " . $user_cond . $order_by_cond . $limit_cond;
- //$get_user_str="SELECT e.`smpin`, e.`emp_code`,e. `fname`,e.`lname`,e.emp_code,u.userid,d.city,d.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name,u.created_on as register_date,u.status FROM ".DMS_EMPLOYEE." e LEFT JOIN ".TABLE_USER." u ON u.smpin=e.smpin AND u.is_deleted=0 LEFT JOIN ".DMS_DEALER." d ON e.dealer_code=d.dealer_code WHERE e.status='1' AND e.smpin!='' ".$user_cond.$order_by_cond.$limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (!count($user_arr) > 0) {
- $user_arr = array();
- } else {
- foreach ($user_arr as $mkey => $res_val) {
- if ($res_user->userid > 0) {
- $status = ($res_user->status == '1') ? 'Active' : 'Inactive';
- } else {
- $status = "Not registered";
- }
- $user_arr[$mkey]->status_str = $status;
- $user_arr[$mkey]->is_active = ($res_val->status == '1') ? "1" : "0";
- }
- }
- //GET COUNT
- //$get_count_str="SELECT COUNT(e.`smpin`) as ucount FROM ".DMS_EMPLOYEE." e LEFT JOIN ".TABLE_USER." u ON u.smpin=e.smpin LEFT JOIN ".DMS_DEALER." d ON e.dealer_code=d.dealer_code LEFT JOIN (SELECT * FROM ".TABLE_USER_LOG." WHERE module='REGISTER' )as l ON u.userid=l.userid WHERE e.status='1' AND e.smpin!='' ".$user_cond." LIMIT 1";
- $get_count_str = "SELECT COUNT(e.`smpin`) as ucount FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON e.dealer_code=d.dealer_code WHERE e.status='1' AND e.smpin!='' AND u.is_deleted=0 " . $user_cond . " LIMIT 1";
- //$get_count_str="SELECT COUNT(e.`smpin`) as ucount FROM ".DMS_EMPLOYEE." e LEFT JOIN ".TABLE_USER." u ON u.smpin=e.smpin AND u.is_deleted=0 LEFT JOIN ".DMS_DEALER." d ON e.dealer_code=d.dealer_code WHERE e.status='1' AND e.smpin!='' ".$user_cond." LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'REGISTRATION REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- // New Course Report
- private function newcoursereport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 2);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[1]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[1]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- //MANAGER WISE DEALER CONDITION
- $dealer_cond_arr = $this->getmanagerconditon_arr($parent);
- if (count($dealer_cond_arr) > 0) {
- //APPEND prefix
- array_walk($dealer_cond_arr, function (&$value, $key) {$value = 'd.' . $value;});
- $user_cond .= " AND d.status='1' AND d.is_deleted='0' AND " . @implode(" AND ", $dealer_cond_arr);
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[1]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (e.fname LIKE '%" . $search_txt . "%' OR e.lname LIKE '%" . $search_txt . "%' OR e.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- $user_cond .= " AND e.is_current='1' ";
- // u.status='1' AND
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.smpin,u.emp_code,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name,e.segment FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.is_deleted='0' AND u.role>7 AND u.role<14 " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $ukey => $res) {
- $content_arr = projectfunc::userSegmentCourseCompleteStatus($parent, $res->userid, $res->segment);
- $user_arr[$ukey]->total_content = $content_arr['total'];
- $user_arr[$ukey]->completed_content = $content_arr['completed'];
- $user_arr[$ukey]->percentage = ($content_arr['total'] > 0) ? round(($content_arr['completed'] / $content_arr['total']) * 100) : '0';
- }
- } else {
- $user_arr = array();
- }
- //GET COUNT
- // u.status='1' AND
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.is_deleted='0' AND u.role>7 AND u.role<14 " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'COURSE REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// NEW SURVEY REPORT //////////////////////////////////////////////// */
- private function newsurveyreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 2);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[1]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $dealer_code_cond = '';
- // if($parent->current_user_role=='7')
- // {
- // $role=$parent->current_user_role;
- // $userdata=projectfunc::getuserdata($parent,$parent->current_user_id);
- // $emailid=$userdata->emailid;
- // }else
- // {
- // //AREA MANAGER LEVEL REPORT
- // $role='7';
- // //FIELDS VALIDATION
- // $REQUEST_KEYS=array('area'=>'string');
- // globalfunc::mandatoryKey($parent,$REQUEST_KEYS);
- // $area_manager = $parent->_request["area"];
- // $emailid=$area_manager;
- //
- //
- // }
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('assessmentid' => 'integer');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $assessmentid = escape_str($parent->_request["assessmentid"]);
- $qry_params = explode("?", $parent->params[1]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- switch ($type) {
- case "zm":
- if ($parent->current_user_role == '3') {
- $REQUEST_KEYS = array('zmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["zmemail"]);
- if ($emailid != 'all') {
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE zm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- } else {
- $user_cond .= "";
- }
- } else {
- $parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- }
- break;
- case "rm":
- if ($parent->current_user_role < '7') {
- if ($parent->current_user_role == '5') {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["rmemail"]);
- $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $zone_cond .= (count($trainer_arr) > 0) ? " zone='" . $trainer_arr[0]->zone . "'" : " zone='0'";
- if ($emailid == 'all') {
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE " . $zone_cond . " AND status='1' AND is_deleted='0')";
- } else {
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE rm_email='" . $emailid . "' AND " . $zone_cond . " AND status='1' AND is_deleted='0' )";
- }
- } else {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["rmemail"]);
- if ($emailid == 'all') {
- $REQUEST_KEYS = array('zmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["zmemail"]);
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE zm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- } else {
- //ZM EMAIL
- $zmemail = escape_str($parent->_request["zmemail"]);
- $zmcond = ($zmemail != 'all' && $zmemail != '') ? " AND zm_email='" . $zmemail . "'" : '';
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE rm_email='" . $emailid . "' " . $zmcond . " AND status='1' AND is_deleted='0')";
- }
- }
- } else {
- $parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- }
- break;
- case "am":
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " dealer_code='" . $parent->current_user_data->dealer_code . "'";
- } else {
- $REQUEST_KEYS = array('amemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["amemail"]);
- if ($emailid == 'all') {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["rmemail"]);
- $dealer_code_cond = " rm_email='" . $emailid . "'";
- } else {
- $dealer_code_cond = " am_email='" . $emailid . "'";
- }
- if ($parent->current_user_role != '5') {
- //ZM EMAIL
- $zmemail = escape_str($parent->_request["zmemail"]);
- $zmcond = ($zmemail != 'all' && $zmemail != '') ? " AND zm_email='" . $zmemail . "'" : '';
- $dealer_code_cond .= $zmcond;
- }
- //RM EMAIL
- $rmemail = escape_str($parent->_request["rmemail"]);
- $rmcond = ($rmemail != 'all' && $rmemail != '') ? " AND rm_email='" . $rmemail . "'" : '';
- $dealer_code_cond .= $rmcond;
- //TRAINER
- if ($parent->current_user_role == '5') {
- $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $dealer_code_cond .= (count($trainer_arr) > 0) ? "AND zone='" . $trainer_arr[0]->zone . "'" : "AND zone='0'";
- }
- }
- $user_cond .= " AND u.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE " . $dealer_code_cond . " AND status='1' AND is_deleted='0')";
- break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[1]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- //u.status='1' AND
- $user_cond .= " AND e.is_current='1' ";
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.smpin,u.emp_code,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name,au.modified_on as assessment_date FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.is_deleted='0' AND u.role>7 AND u.role<14 AND au.assessmentid='" . $assessmentid . "' AND au.highscorearid!='0' " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- /*
- foreach($user_arr as $mkey=>$res_user)
- {
- //$exam_highscore_str = "SELECT * FROM ".TABLE_ASSESSMENT_USER." WHERE assessmentid='".$assessmentid."' AND userid='".$res_user->userid."' LIMIT 1";
- //$exam_highscore_arr=$parent->getQueryValue($exam_highscore_str);
- //$user_arr[$mkey]->highscore=(count($exam_highscore_arr)>0)?$exam_highscore_arr[0]->highscore:'0';
- }
- */
- }
- //GET COUNT
- //u.status='1' AND
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.is_deleted='0' AND u.role>7 AND u.role<14 AND au.assessmentid='" . $assessmentid . "' AND au.highscorearid!='0' " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'SURVEY REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// NEW SALES REPORT //////////////////////////////////////////////// */
- private function newsalesreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 4);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $year_data = escape_str($parent->params[1]);
- $last_data = escape_str($parent->params[2]);
- $last_data_arr = explode('?', $last_data);
- $month_data = escape_str(trim($last_data_arr[0]));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[3]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $qry_params = explode("?", $parent->params[3]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- //MANAGER WISE DEALER CONDITION
- $dealer_cond_arr = $this->getmanagerconditon_arr($parent);
- if (count($dealer_cond_arr) > 0) {
- //APPEND prefix
- array_walk($dealer_cond_arr, function (&$value, $key) {$value = 'd.' . $value;});
- $user_cond .= " AND d.status='1' AND d.is_deleted='0' AND " . @implode(" AND ", $dealer_cond_arr);
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[3]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,e.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,e.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,e.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,e.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,e.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,e.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,e.fname ASC ";
- break;
- }
- }
- //GET ROLE
- $role_data = array();
- $role_arr = $parent->getQueryValue("SELECT rolename FROM " . TABLE_ROLE . " WHERE status=1 AND id>7 AND id<14 ");
- if (count($role_arr) > 0) {
- foreach ($role_arr as $res) {
- $role_data[] = "'" . $res->rolename . "'";
- }
- } else {
- $role_data[] = '';
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (e.fname LIKE '%" . $search_txt . "%' OR e.lname LIKE '%" . $search_txt . "%' OR e.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- //u.status='1' AND
- $is_history = (isset($parent->_request["is_history"]) && $parent->_request["is_history"] == 1) ? "1" : "0";
- if ($is_history == 0) {
- $user_cond .= " AND e.is_current='1' AND e.status=1 ";
- } else {
- $user_cond .= " AND e.status=1 ";
- }
- //$get_user_str="SELECT u.userid,u.fname,u.lname,u.smpin,u.emp_code,d.city,u.dealer_code,u.segment,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM ".TABLE_USER." u LEFT JOIN ".DMS_EMPLOYEE." e ON u.smpin=e.smpin LEFT JOIN ".DMS_DEALER." d ON u.dealer_code=d.dealer_code WHERE u.is_deleted='0' AND u.role>7 AND u.role<14 ".$user_cond.$order_by_cond.$limit_cond;
- //$get_user_str="SELECT SQL_CALC_FOUND_ROWS u.userid,e.fname,e.lname,e.smpin,e.emp_code,d.city,e.dealer_code,e.segment,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM ".DMS_EMPLOYEE." e LEFT JOIN ".TABLE_USER." u ON e.smpin=u.smpin LEFT JOIN ".DMS_DEALER." d ON e.dealer_code=d.dealer_code WHERE e.role IN (".@implode(',',$role_data).") ".$user_cond.$order_by_cond.$limit_cond;
- $get_user_str = "SELECT SQL_CALC_FOUND_ROWS e.id,e.fname,e.lname,e.smpin,e.emp_code,d.city,e.dealer_code,e.segment,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM " . DMS_EMPLOYEE . " e LEFT JOIN " . DMS_DEALER . " d ON e.dealer_code=d.dealer_code WHERE e.role IN (" . @implode(',', $role_data) . ") " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- $total_arr = $parent->getQueryValue("SELECT FOUND_ROWS() as total_record");
- $query_modelarr = $parent->selectQuery(TABLE_MODEL, " model_name,model_image,segment ", "model_is_target=1 AND user_type=0 ORDER BY model_id", "");
- if (count($user_arr) > 0) {
- foreach ($user_arr as $mkey => $res_user) {
- //TARGET
- $user_target = projectfunc::userSmpinSalesTarget($parent, $res_user->smpin, '', $year_data, $month_data);
- //ACHIEVED
- $user_achieved = projectfunc::userSmpinSalesAchieved($parent, $res_user->smpin, '', $year_data, $month_data);
- $sales = array('target' => $user_target, 'achieved' => $user_achieved);
- $user_arr[$mkey]->sales = $sales;
- $model_data_arr = array();
- //GET MODEL
- $salemodel_arr = array();
- $query_salesmodelarr = $parent->selectQuery(DMS_EMPLOYEE_SALES, " model ", "smpin='" . $res_user->smpin . "' AND sale_date>='" . date('Y-m-d', strtotime($year_data . "-" . $month_data . "-01")) . "' AND sale_date<='" . date('Y-m-t', strtotime($year_data . "-" . $month_data . "-01")) . "' GROUP BY model ", "");
- if ($query_salesmodelarr['nr']) {
- foreach ($query_salesmodelarr['result'] as $res) {
- $salemodel_arr[] = strtolower($res->model);
- }
- }
- if ($query_modelarr['nr']) {
- foreach ($query_modelarr['result'] as $key => $res) {
- if ($res->segment == 0 || ($res->segment == $res_user->segment) || in_array(strtolower($res->model_name), $salemodel_arr)) {
- $res->model_image_url = ($res->model_image != '') ? SITE_URL . "hypermupload/model/" . $res->model_image : NOIMAGE_URL;
- $user_target = projectfunc::userSmpinSalesTarget($parent, $res_user->smpin, $res->model_name, $year_data, $month_data);
- $res->target = $user_target;
- $res->achieved = projectfunc::userSmpinSalesAchieved($parent, $res_user->smpin, $res->model_name, $year_data, $month_data);
- $model_data_arr[] = (array) $res;
- // if($user_target>0)
- // {
- // $res->target=$user_target;
- // $res->achieved= projectfunc::userSalesAchieved($parent,$res_user->userid,$res->model_name,$year_data,$month_data);
- // $model_data_arr[]=(array)$res;
- // }
- }
- }
- }
- $user_arr[$mkey]->model_data = $model_data_arr;
- }
- }
- //GET COUNT
- //u.status='1' AND
- // $get_count_str="SELECT COUNT(u.userid)as ucount FROM ".TABLE_USER." u LEFT JOIN ".DMS_EMPLOYEE." e ON u.smpin=e.smpin LEFT JOIN ".DMS_DEALER." d ON u.dealer_code=d.dealer_code WHERE u.is_deleted='0' AND u.role>7 AND u.role<14 ".$user_cond." LIMIT 1 ";
- // $get_count_arr=$parent->getQueryValue($get_count_str);
- $total = (count($total_arr) > 0) ? $total_arr[0]->total_record : 0;
- //LOG
- $logstr = 'MANAGER SALES REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'month' => date('M', strtotime('2018-' . $month_data . "-01")), 'year' => $year_data, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// NEW CERTIFIED DSE REPORT //////////////////////////////////////////////// */
- private function newcertifieddsereport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 2);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- projectfunc::authorizedRole($parent, array('3', '4', '5', '6', '7', '14'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[1]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $qry_params = explode("?", $parent->params[1]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- //MANAGER WISE DEALER CONDITION
- $dealer_cond_arr = $this->getmanagerconditon_arr($parent);
- if (count($dealer_cond_arr) > 0) {
- //APPEND prefix
- array_walk($dealer_cond_arr, function (&$value, $key) {$value = 'd.' . $value;});
- $user_cond .= " AND d.status='1' AND d.is_deleted='0' AND " . @implode(" AND ", $dealer_cond_arr);
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[1]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- //u.status='1' AND
- $user_cond .= " AND e.is_current='1' ";
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.smpin,u.emp_code,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.is_deleted='0' AND u.role>7 AND u.role<14 " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $mkey => $res_user) {
- $user_arr[$mkey]->learning = projectfunc::userLearningLevel($parent, $res_user->userid);
- }
- }
- //GET COUNT
- //u.status='1' AND
- $get_count_str = "SELECT COUNT(u.userid) as ucount FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.is_deleted='0' AND u.role>7 AND u.role<14 " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'MANAGER CERTIFIED DSE REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// NEW ASSESSMENT REPORT //////////////////////////////////////////////// */
- private function newassessmentreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 2);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- projectfunc::authorizedRole($parent, array('3', '4', '5', '6', '7', '14'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[1]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('assessmentid' => 'integer');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $assessmentid = escape_str($parent->_request["assessmentid"]);
- $assess_str = "SELECT assessmentid,pass_score FROM " . TABLE_ASSESSMENT . " WHERE assessmentid='" . $assessmentid . "' LIMIT 1";
- $assess_arr = $parent->getQueryValue($assess_str);
- if (!(count($assess_arr) > 0)) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error1"]), 406);
- }
- $pass_score = $assess_arr[0]->pass_score;
- $user_cond = "";
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[1]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- //MANAGER WISE DEALER CONDITION
- $dealer_cond_arr = $this->getmanagerconditon_arr($parent);
- if (count($dealer_cond_arr) > 0) {
- //APPEND prefix
- array_walk($dealer_cond_arr, function (&$value, $key) {$value = 'd.' . $value;});
- $user_cond .= " AND d.status='1' AND d.is_deleted='0' AND " . @implode(" AND ", $dealer_cond_arr);
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[1]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY au.highscore DESC,au.modified_on ASC, d.dealer_name,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- $dse_cond = (isset($parent->_request["is_idse"]) && $parent->_request["is_idse"] !== '1') ? " AND u.role='15'" : "AND u.role>7 AND u.role<14";
- $user_cond .= " AND e.is_current='1' ";
- //u.status='1' AND
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.smpin,u.emp_code,d.city,u.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.is_deleted='0' " . $dse_cond . " AND au.assessmentid='" . $assessmentid . "' " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $mkey => $res_user) {
- $exam_highscore_str = "SELECT * FROM " . TABLE_ASSESSMENT_USER . " WHERE assessmentid='" . $assessmentid . "' AND userid='" . $res_user->userid . "' LIMIT 1";
- $exam_highscore_arr = $parent->getQueryValue($exam_highscore_str);
- $user_arr[$mkey]->highscore = (count($exam_highscore_arr) > 0) ? $exam_highscore_arr[0]->highscore : '0';
- $user_arr[$mkey]->is_pass = ($user_arr[$mkey]->highscore >= $pass_score) ? '1' : '0';
- }
- }
- //GET COUNT
- //u.status='1' AND
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE u.is_deleted='0' " . $dse_cond . " AND au.assessmentid='" . $assessmentid . "' " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'ASSESSMENT REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'pass_score' => $pass_score, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// NEW SALES TARGET REPORT //////////////////////////////////////////////// */
- private function newsalestarget($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- globalfunc::checkParamCount($parent, 4);
- $year_data = escape_str($parent->params[1]);
- $last_data = escape_str($parent->params[2]);
- $last_data_arr = explode('?', $last_data);
- $month_data = escape_str(trim($last_data_arr[0]));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[3]);
- //$limit_cond=($limit_str)?" LIMIT ".$limit_str:'';
- $limit_cond = '';
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[3]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- switch ($type) {
- case "zm":
- if ($parent->current_user_role == '3') {
- $REQUEST_KEYS = array('zmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["zmemail"]);
- if ($emailid != 'all') {
- $user_cond .= " AND d.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE zm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- } else {
- $user_cond .= "";
- }
- } else {
- $parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- }
- break;
- case "rm":
- if ($parent->current_user_role < '7') {
- if ($parent->current_user_role == '5') {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["rmemail"]);
- $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $zone_cond .= (count($trainer_arr) > 0) ? " zone='" . $trainer_arr[0]->zone . "'" : " zone='0'";
- if ($emailid == 'all') {
- $user_cond .= " AND d.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE " . $zone_cond . " AND status='1' AND is_deleted='0')";
- } else {
- $user_cond .= " AND d.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE rm_email='" . $emailid . "' AND " . $zone_cond . " AND status='1' AND is_deleted='0' )";
- }
- } else {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["rmemail"]);
- if ($emailid == 'all') {
- $REQUEST_KEYS = array('zmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["zmemail"]);
- $user_cond .= " AND d.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE zm_email='" . $emailid . "' AND status='1' AND is_deleted='0')";
- } else {
- //ZM EMAIL
- $zmemail = escape_str($parent->_request["zmemail"]);
- $zmcond = ($zmemail != 'all' && $zmemail != '') ? " AND zm_email='" . $zmemail . "'" : '';
- $user_cond .= " AND d.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE rm_email='" . $emailid . "' " . $zmcond . " AND status='1' AND is_deleted='0')";
- }
- }
- } else {
- $parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- }
- break;
- case "am":
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " dealer_code='" . $parent->current_user_data->dealer_code . "'";
- } else {
- $REQUEST_KEYS = array('amemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["amemail"]);
- if ($emailid == 'all') {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["rmemail"]);
- $dealer_code_cond = " rm_email='" . $emailid . "'";
- } else {
- $dealer_code_cond = " am_email='" . $emailid . "'";
- }
- if ($parent->current_user_role != '5') {
- //ZM EMAIL
- $zmemail = escape_str($parent->_request["zmemail"]);
- $zmcond = ($zmemail != 'all' && $zmemail != '') ? " AND zm_email='" . $zmemail . "'" : '';
- $dealer_code_cond .= $zmcond;
- }
- //RM EMAIL
- $rmemail = escape_str($parent->_request["rmemail"]);
- $rmcond = ($rmemail != 'all' && $rmemail != '') ? " AND rm_email='" . $rmemail . "'" : '';
- $dealer_code_cond .= $rmcond;
- //TRAINER
- if ($parent->current_user_role == '5') {
- $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $dealer_code_cond .= (count($trainer_arr) > 0) ? "AND zone='" . $trainer_arr[0]->zone . "'" : "AND zone='0'";
- }
- }
- $user_cond .= " AND d.dealer_code IN (SELECT dealer_code FROM " . DMS_DEALER . " WHERE " . $dealer_code_cond . " AND status='1' AND is_deleted='0')";
- break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[3]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname,u.userid ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Location
- //3-AM
- //4-RM
- //5-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY d.dealer_name,u.fname,u.userid ASC ";
- break;
- case '2':$order_by_cond = "ORDER BY d.city,u.fname,u.userid ASC ";
- break;
- case '3':$order_by_cond = "ORDER BY d.am_email,u.fname,u.userid ASC ";
- break;
- case '4':$order_by_cond = "ORDER BY d.rm_email,u.fname,u.userid ASC ";
- break;
- case '5':$order_by_cond = "ORDER BY d.zm_email,u.fname,u.userid ASC ";
- break;
- default:$order_by_cond = "ORDER BY d.dealer_name,u.fname,u.userid ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (e.fname LIKE '%" . $search_txt . "%' OR e.lname LIKE '%" . $search_txt . "%' OR e.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- if (isset($parent->_request["dealer"]) && $parent->_request["dealer"] != '') {
- $user_cond .= " AND d.dealer_code='" . escape_str($parent->_request["dealer"]) . "'";
- }
- $user_cond .= " AND e.is_current='1' ";
- $segment_result = array();
- $query_modelarr = $parent->selectQuery(TABLE_MODEL, "model_id, model_name,model_image,segment,min_target ", "model_is_target=1 AND user_type=0 " . $model_cond . " ORDER BY model_id", "");
- //$user_cond.=" AND u.role>7 AND u.role<14 ";
- $get_user_str = "SELECT e.`smpin`, e.`emp_code`,e. `fname`,e.`lname`,e.emp_code,e.segment,u.userid,d.city,e.dealer_code,d.dealer_name,d.zm_name,d.rm_name,d.am_name FROM " . DMS_EMPLOYEE . " e LEFT JOIN " . TABLE_USER . " u ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON e.dealer_code=d.dealer_code WHERE e.status='1' AND e.smpin!='' " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $ukey => $res) {
- $user_target = projectfunc::userSmpinSalesTarget($parent, $res->smpin, '', $year_data, $month_data);
- $user_arr[$ukey]->salestarget = $user_target;
- $user_arr[$ukey]->model = array();
- //$user_arr[$ukey]->is_edit=(strtotime(CUR_DATE)>strtotime(date('Y-m-d',strtotime($year_data."-".$month_data."-".TRAINER_BUFFER_DATE))))?"0":"1";
- $user_arr[$ukey]->is_edit = projectfunc::setSaleEditpermisson($parent, $res->smpin, date('Y-m-d', strtotime($year_data . "-" . $month_data . "-01")));
- $query_get_statusarr = $parent->selectQuery(TABLE_USER_SALESTARGET_STATUS, "* ", "smpin='" . $res->smpin . "' AND sale_month='" . date('Y-m-d', strtotime($year_data . "-" . $month_data . "-01")) . "' ORDER BY id DESC", "1");
- if ($query_get_statusarr['nr']) {
- switch ($query_get_statusarr['result'][0]->status) {
- case '1':
- $user_arr[$ukey]->sale_status = '1';
- $user_arr[$ukey]->sale_status_str = 'Waiting';
- break;
- case '2':
- $user_arr[$ukey]->sale_status = '2';
- $user_arr[$ukey]->sale_status_str = 'Approval';
- break;
- case '3':
- $user_arr[$ukey]->sale_status = '3';
- $user_arr[$ukey]->sale_status_str = 'Modification';
- break;
- }
- } else {
- $user_arr[$ukey]->sale_status = '0';
- $user_arr[$ukey]->sale_status_str = 'No Action';
- }
- switch ($res->segment) {
- case '1':$user_arr[$ukey]->segment_min_target = SEGMENT_MIN_TARGET_PARENTS;
- break;
- case '2':$user_arr[$ukey]->segment_min_target = SEGMENT_MIN_TARGET_INSTRUCTOR;
- break;
- default:$user_arr[$ukey]->segment_min_target = SEGMENT_MIN_TARGET_STUDENT_LEANER;
- break;
- }
- //GET SEGMENT
- //$segment= projectfunc::userSegment($parent,$res->smpin);
- $segment = $res->segment;
- //$model_cond=" AND (segment='".$segment."' OR segment='0' )";
- // if(!isset($segment_result[$segment]))
- // {
- // //GET MODEL
- // $query_modelarr=$parent->selectQuery(TABLE_MODEL,"model_id, model_name,model_image ","model_is_target=1 AND user_type=0 ".$model_cond." ORDER BY model_id","");
- // $segment_result[$segment]=$query_modelarr;
- // }else
- // {
- // $query_modelarr=$segment_result[$segment];
- // }
- if ($query_modelarr['nr']) {
- foreach ($query_modelarr['result'] as $res_model) {
- //|| in_array(strtolower($res_model->model_name),$salemodel_arr)
- if ($res_model->segment == 0 || ($res_model->segment == $segment)) {
- $user_target = projectfunc::userSmpinSalesTarget($parent, $res->smpin, $res_model->model_name, $year_data, $month_data);
- if ($user_target > 0) {
- $mobj = new stdClass();
- $mobj->model_id = $res_model->model_id;
- $mobj->model_name = $res_model->model_name;
- $mobj->target = $user_target;
- $mobj->achieved = projectfunc::userSmpinSalesAchieved($parent, $res->smpin, $res_model->model_name, $year_data, $month_data);
- $mobj->min_target = $res_model->min_target;
- $mobj->model_image_url = ($res_model->model_image != '') ? SITE_URL . "hypermupload/model/" . $res_model->model_image : NOIMAGE_URL;
- $user_arr[$ukey]->model[] = $mobj;
- } else {
- $mobj = new stdClass();
- $mobj->model_id = $res_model->model_id;
- $mobj->model_name = $res_model->model_name;
- $mobj->target = '0';
- $mobj->achieved = projectfunc::userSmpinSalesAchieved($parent, $res->smpin, $res_model->model_name, $year_data, $month_data);
- $mobj->min_target = $res_model->min_target;
- $mobj->model_image_url = ($res_model->model_image != '') ? SITE_URL . "hypermupload/model/" . $res_model->model_image : NOIMAGE_URL;
- $user_arr[$ukey]->model[] = $mobj;
- }
- }
- }
- }
- }
- } else {
- $user_arr = array();
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(e.`smpin`)as ucount FROM " . DMS_EMPLOYEE . " e LEFT JOIN " . TABLE_USER . " u ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON e.dealer_code=d.dealer_code WHERE e.status='1' AND e.smpin!='' " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'SALES TARGET REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $is_edit = 0;
- if (date('Y-m', strtotime(CUR_DATE)) == date('Y-m', strtotime($year_data . "-" . $month_data . "-01"))) {
- if ($parent->current_user_role == '14') {
- $def_edit_date = date('Y-m', strtotime(CUR_DATE)) . "-" . DEALER_SETSALE_DATE;
- } else {
- $def_edit_date = date('Y-m', strtotime(CUR_DATE)) . "-" . AM_SETSALE_DATE;
- }
- if (strtotime(CUR_DATE) <= strtotime($def_edit_date)) {
- $is_edit = 1;
- }
- }
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1'], 'is_edit' => $is_edit), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// NEW SALES LEADERBOARD REPORT //////////////////////////////////////////////// */
- private function newsalesleaderboardreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 4);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $year_data = escape_str($parent->params[1]);
- $last_data = escape_str($parent->params[2]);
- $last_data_arr = explode('?', $last_data);
- $month_data = escape_str(trim($last_data_arr[0]));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[3]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- //FIELDS VALIDATION
- /*
- $REQUEST_KEYS=array('email'=>'string');
- globalfunc::mandatoryKey($parent,$REQUEST_KEYS);
- $email = escape_str($parent->_request["email"]);
- */
- $qry_params = explode("?", $parent->params[3]);
- $type = strtolower($qry_params[0]);
- $dealer_cond = "";
- switch ($type) {
- case "zm":
- if ($parent->current_user_role == '3') {
- $REQUEST_KEYS = array('zmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["zmemail"]);
- if ($emailid != 'all') {
- //$dealer_cond.=" AND u.dealer_code IN (SELECT dealer_code FROM ".DMS_DEALER." WHERE zm_email='". $emailid."')";
- $dealer_cond .= " AND d.zm_email='" . $emailid . "'";
- } else {
- $dealer_cond .= "";
- }
- } else {
- $parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- }
- break;
- case "rm":
- if ($parent->current_user_role < '7') {
- if ($parent->current_user_role == '5') {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $zone_cond .= (count($trainer_arr) > 0) ? " d.zone='" . $trainer_arr[0]->zone . "'" : " d.zone='0'";
- $emailid = escape_str($parent->_request["rmemail"]);
- if ($emailid == 'all') {
- //$user_cond.=" AND u.dealer_code IN (SELECT dealer_code FROM ".DMS_DEALER." WHERE ".$zone_cond.")";
- $dealer_cond .= " AND " . $zone_cond;
- } else {
- //$user_cond.=" AND u.dealer_code IN (SELECT dealer_code FROM ".DMS_DEALER." WHERE rm_email='".$emailid."')";
- $dealer_cond .= "AND d.rm_email='" . $emailid . "' AND " . $zone_cond;
- }
- } else {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["rmemail"]);
- if ($emailid == 'all') {
- $REQUEST_KEYS = array('zmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["zmemail"]);
- //$user_cond.=" AND u.dealer_code IN (SELECT dealer_code FROM ".DMS_DEALER." WHERE zm_email='". $emailid."')";
- $dealer_cond .= " AND d.zm_email='" . $emailid . "'";
- } else {
- //ZM EMAIL
- $zmemail = escape_str($parent->_request["zmemail"]);
- $zmcond = ($zmemail != 'all' && $zmemail != '') ? " AND d.zm_email='" . $zmemail . "'" : '';
- //$user_cond.=" AND u.dealer_code IN (SELECT dealer_code FROM ".DMS_DEALER." WHERE rm_email='".$emailid."')";
- $dealer_cond .= " AND d.rm_email='" . $emailid . "' " . $zmcond;
- }
- }
- } else {
- $parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- }
- break;
- case "am":
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " d.dealer_code='" . $parent->current_user_data->dealer_code . "'";
- } else {
- $REQUEST_KEYS = array('amemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["amemail"]);
- if ($emailid == 'all') {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["rmemail"]);
- $dealer_code_cond = " d.rm_email='" . $emailid . "'";
- } else {
- $dealer_code_cond = " d.am_email='" . $emailid . "'";
- }
- if ($parent->current_user_role != '5') {
- //ZM EMAIL
- $zmemail = escape_str($parent->_request["zmemail"]);
- $zmcond = ($zmemail != 'all' && $zmemail != '') ? " AND d.zm_email='" . $zmemail . "'" : '';
- $dealer_code_cond .= $zmcond;
- }
- //RM EMAIL
- $rmemail = escape_str($parent->_request["rmemail"]);
- $rmcond = ($rmemail != 'all' && $rmemail != '') ? " AND d.rm_email='" . $rmemail . "'" : '';
- $dealer_code_cond .= $rmcond;
- //TRAINER
- if ($parent->current_user_role == '5') {
- $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $dealer_code_cond .= (count($trainer_arr) > 0) ? "AND d.zone='" . $trainer_arr[0]->zone . "'" : "AND d.zone='0'";
- }
- }
- //$user_cond.=" AND u.dealer_code IN (SELECT dealer_code FROM ".DMS_DEALER." WHERE ".$dealer_code_cond.")";
- $dealer_cond .= " AND " . $dealer_code_cond;
- break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $user_cond = "";
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[3]);
- //SORT
- $order_by_cond = "ORDER BY d.dealer_name,u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Dealer
- //2-Rank
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = " ORDER BY d.dealer_name,f.rank ASC ";
- break;
- case '2':$order_by_cond = " ORDER BY f.rank,d.dealer_name ASC ";
- break;
- default:$order_by_cond = " ORDER BY f.rank,d.dealer_name ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.smpin LIKE '%" . $search_txt . "%' OR d.dealer_name LIKE '%" . $search_txt . "%' OR d.zm_name LIKE '%" . $search_txt . "%' OR d.rm_name LIKE '%" . $search_txt . "%' OR d.am_name LIKE '%" . $search_txt . "%' OR d.city LIKE '%" . $search_txt . "%' )";
- }
- if ($parent->current_user_role == '14') {
- $user_cond .= " AND u.dealer_code='" . $dealer_code . "'";
- }
- //GET ALL 20 USER RANK
- $start_date = date('Y-m-d', strtotime($year_data . "-" . $month_data . "-01"));
- $end_date = date('Y-m-t', strtotime($year_data . "-" . $month_data . "-01"));
- $parent->executeQuery("SET @rownum := 0");
- $get_user_str = "SELECT f.*,u.userid,u.fname,u.lname,d.* FROM (SELECT @rownum := @rownum + 1 AS rank, salecount,targetcount,smpin,userid,last_sale,first_sale,sale_per FROM (SELECT c.*, CASE WHEN targetcount=0 THEN 0 ELSE (salecount/targetcount)*100 END as 'sale_per' FROM ( SELECT a.userid,a.smpin,a.salecount,b.targetcount,a.last_sale,a.first_sale FROM (SELECT COALESCE(COUNT(s.id),'0') as scount, COALESCE(SUM(s.sales_count),'0') as salecount, u.smpin,u.userid,MAX(s.sale_date) last_sale,MIN(s.sale_date) first_sale FROM " . TABLE_USER . " as u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code LEFT JOIN (SELECT id,smpin,sale_date,sales_count FROM " . DMS_EMPLOYEE_SALES . " WHERE sale_date>='" . $start_date . "' AND sale_date<='" . $end_date . "') as s ON s.smpin=u.smpin WHERE u.is_deleted=0 AND u.role>7 AND u.role<14 AND e.is_current='1' " . $dealer_cond . " GROUP BY u.smpin ) as a JOIN (SELECT COALESCE(SUM(t.target),'0') as targetcount,u.smpin,u.userid FROM " . TABLE_USER . " as u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code LEFT JOIN (SELECT id,smpin,target FROM " . TABLE_USER_SALETARGET . " WHERE sale_month>='" . $start_date . "' AND sale_month<='" . $end_date . "')as t ON t.smpin=u.smpin WHERE u.is_deleted=0 AND u.role>7 AND u.role<14 AND e.is_current='1' " . $dealer_cond . " GROUP BY u.smpin ) as b ON a.userid=b.userid )c ORDER BY cast(sale_per as SIGNED) DESC,cast(salecount as SIGNED) DESC,cast(targetcount as SIGNED) DESC,last_sale ASC,first_sale ASC,userid ASC)as a )as f JOIN " . TABLE_USER . " as u ON f.userid=u.userid LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE 1=1 " . $user_cond . $order_by_cond . " " . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- //GET COUNT
- $get_user_count_str = "SELECT COUNT(u.userid)as user_count FROM (SELECT salecount,targetcount,smpin,userid,last_sale,first_sale,sale_per FROM (SELECT c.*, CASE WHEN targetcount=0 THEN 0 ELSE (salecount/targetcount)*100 END as 'sale_per' FROM ( SELECT a.userid,a.smpin,a.salecount,b.targetcount,a.last_sale,a.first_sale FROM (SELECT COALESCE(COUNT(s.id),'0') as scount, COALESCE(SUM(s.sales_count),'0') as salecount, u.smpin,u.userid,MAX(s.sale_date) last_sale,MIN(s.sale_date) first_sale FROM " . TABLE_USER . " as u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code LEFT JOIN (SELECT id,smpin,sale_date,sales_count FROM " . DMS_EMPLOYEE_SALES . " WHERE sale_date>='" . $start_date . "' AND sale_date<='" . $end_date . "') as s ON s.smpin=u.smpin WHERE u.is_deleted=0 AND u.role>7 AND u.role<14 AND e.is_current='1' " . $dealer_cond . " GROUP BY u.smpin ) as a JOIN (SELECT COALESCE(SUM(t.target),'0') as targetcount,u.smpin,u.userid FROM " . TABLE_USER . " as u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code LEFT JOIN (SELECT id,smpin,target FROM " . TABLE_USER_SALETARGET . " WHERE sale_month>='" . $start_date . "' AND sale_month<='" . $end_date . "')as t ON t.smpin=u.smpin WHERE u.is_deleted=0 AND u.role>7 AND u.role<14 AND e.is_current='1' " . $dealer_cond . " GROUP BY u.smpin ) as b ON a.userid=b.userid )c ORDER BY cast(sale_per as SIGNED) DESC,cast(salecount as SIGNED) DESC,cast(targetcount as SIGNED) DESC,last_sale ASC,first_sale ASC,userid ASC)as a )as f JOIN " . TABLE_USER . " as u ON f.userid=u.userid LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE 1=1 " . $user_cond . " LIMIT 1";
- $outof = 0;
- if (count($user_arr) > 0) {
- $user_count_arr = $parent->getQueryValue($get_user_count_str);
- $outof = (count($user_count_arr) > 0) ? $user_count_arr[0]->user_count : '0';
- foreach ($user_arr as $mkey => $res_user) {
- $user_arr[$mkey]->outof = $outof;
- }
- } else {
- $user_arr = array();
- }
- //GET COUNT
- $total = $outof;
- //LOG
- $logstr = 'SALES LEADERBOARD REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'qry' => $get_user_str, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// ASSESSMENT //////////////////////////////////////// */
- private function newassessmentleaderboardreport($parent)
- {
- //assessment/sales/{{year}}/{{month}}
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- globalfunc::checkParamCount($parent, 2);
- //DATE CONDITION
- //$start_date="2018-".date('m',strtotime(CUR_DATE))."-01";
- $start_date = date('Y-m', strtotime(CUR_DATE)) . "-01";
- $end_date = date('Y-m-t', strtotime(CUR_DATE));
- $date_cond = " AND a.publisheddate>='" . $start_date . " 00:00:00' AND a.publisheddate<='" . $end_date . " 23:59:59'";
- $qry_params = explode("?", $parent->params[1]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- switch ($type) {
- case "zm":
- if ($parent->current_user_role == '3') {
- $REQUEST_KEYS = array('zmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["zmemail"]);
- if ($emailid != 'all') {
- $user_cond .= " AND d.zm_email='" . $emailid . "'";
- } else {
- $user_cond .= "";
- }
- } else {
- $parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- }
- break;
- case "rm":
- if ($parent->current_user_role < '7') {
- if ($parent->current_user_role == '5') {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $get_trainer_str = "SELECT h.* FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $zone_cond .= (count($trainer_arr) > 0) ? " d.zone='" . $trainer_arr[0]->zone . "'" : " d.zone='0'";
- $emailid = escape_str($parent->_request["rmemail"]);
- if ($emailid == 'all') {
- $user_cond .= " AND " . $zone_cond;
- } else {
- $user_cond .= " AND d.rm_email='" . $emailid . "' AND " . $zone_cond . "";
- }
- } else {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["rmemail"]);
- if ($emailid == 'all') {
- $REQUEST_KEYS = array('zmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["zmemail"]);
- $user_cond .= " AND d.zm_email='" . $emailid . "'";
- } else {
- //ZM EMAIL
- $zmemail = escape_str($parent->_request["zmemail"]);
- $zmcond = ($zmemail != 'all' && $zmemail != '') ? " AND d.zm_email='" . $zmemail . "'" : '';
- $user_cond .= " AND d.rm_email='" . $emailid . "' " . $zmcond;
- }
- }
- } else {
- $parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- }
- break;
- case "am":
- if ($parent->current_user_role == '14') {
- $dealer_code_cond = " d.dealer_code='" . $parent->current_user_data->dealer_code . "'";
- } else {
- $REQUEST_KEYS = array('amemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["amemail"]);
- if ($emailid == 'all') {
- $REQUEST_KEYS = array('rmemail' => 'string');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $emailid = escape_str($parent->_request["rmemail"]);
- $dealer_code_cond = " d.rm_email='" . $emailid . "'";
- } else {
- $dealer_code_cond = " d.am_email='" . $emailid . "'";
- }
- if ($parent->current_user_role != '5') {
- //ZM EMAIL
- $zmemail = escape_str($parent->_request["zmemail"]);
- $zmcond = ($zmemail != 'all' && $zmemail != '') ? " AND d.zm_email='" . $zmemail . "'" : '';
- $dealer_code_cond .= $zmcond;
- }
- //RM EMAIL
- $rmemail = escape_str($parent->_request["rmemail"]);
- $rmcond = ($rmemail != 'all' && $rmemail != '') ? " AND d.rm_email='" . $rmemail . "'" : '';
- $dealer_code_cond .= $rmcond;
- //TRAINER
- if ($parent->current_user_role == '5') {
- $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $dealer_code_cond .= (count($trainer_arr) > 0) ? "AND d.zone='" . $trainer_arr[0]->zone . "'" : "AND d.zone='0'";
- }
- }
- $user_cond .= "AND " . $dealer_code_cond . "";
- break;
- default:$parent->response(array('response' => 'failed', 'message' => 'Sorry No access'), 401);
- break;
- }
- $join_cond = 'JOIN ' . DMS_DEALER . ' as d ON d.dealer_code=u.dealer_code ';
- $new_cond = 'AND a.user_type=0 ';
- //GET ALL ASSESSMENT LIST WHICH PUBLISHED
- $assessment_str = "SELECT a.* FROM `" . TABLE_ASSESSMENT . "` as a WHERE a.status='1' AND a.atype='0' AND a.assettypeid='1' " . $date_cond . $new_cond;
- $assessment_arr = $parent->getQueryValue($assessment_str);
- //ASSESSMENT COUNT
- $assessment_count = (count($assessment_arr) > 0) ? count($assessment_arr) : '0';
- $data_arr = array();
- if (count($assessment_arr) > 0) {
- foreach ($assessment_arr as $res_assess) {
- $assessmentid_arr[] = $res_assess->assessmentid;
- }
- //GET ALL 20 USER RANK
- //$parent->executeQuery("SET @rownum := 0");
- $get_user_rank_str = "SELECT SUM(highscore)as user_score,u.userid,COALESCE(ar.total_time,'0')as total_time,MAX(au.modified_on) as last_modified,u.dealer_code,u.role,d.* FROM " . TABLE_USER . " as u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin JOIN (SELECT * FROM " . TABLE_ASSESSMENT_USER . " WHERE assessmentid IN (" . @implode(',', $assessmentid_arr) . ") AND highscorearid!=0 ) as au ON u.userid=au.userid LEFT JOIN (SELECT SUM(time_taken)as total_time,assessmentid,userid FROM " . TABLE_ASSESSMENTRESULT . " WHERE assessmentid IN (" . @implode(',', $assessmentid_arr) . ") GROUP BY userid )as ar ON u.userid=ar.userid " . $join_cond . " WHERE u.role>'7' AND u.role<14 AND u.is_deleted=0 AND e.is_current='1' " . $user_cond . " GROUP BY u.userid ORDER BY user_score DESC,ar.total_time ASC,last_modified ASC,u.userid ASC ";
- $get_user_rank_arr = $parent->getQueryValue($get_user_rank_str);
- if ($get_user_rank_arr) {
- foreach ($get_user_rank_arr as $res_user) {
- $user_data_arr = new stdClass();
- $get_time_str = "SELECT * FROM " . TABLE_ASSESSMENTRESULT . " WHERE assessmentid IN (" . @implode(',', $assessmentid_arr) . ") AND userid='" . $res_user->userid . "'";
- $get_time_arr = $parent->getQueryValue($get_time_str);
- $user_data_arr->user = projectfunc::getuserdata($parent, $res_user->userid);
- $user_data_arr->rank = '0';
- $user_data_arr->tot_user_score = (count($get_time_arr) > 0) ? $res_user->user_score : '-';
- $user_data_arr->percentage_score = (count($get_time_arr) > 0) ? '0' : '-';
- $user_data_arr->total_time = $res_user->total_time;
- $user_data_arr->last_time = (count($get_time_arr) > 0) ? $res_user->last_modified : '-';
- $user_cond = array();
- //GET EACH USER COND
- $getuser_data = projectfunc::getuserdata($parent, $res_user->userid);
- // if($getuser_data->role)
- // {
- // $user_cond[]=" (a.filter_role LIKE '%".$getuser_data->role."%' OR a.filter_role='')";
- // }
- if ($getuser_data->zone) {
- $user_cond[] = " (a.filter_zone LIKE '%" . $getuser_data->zone . "%' OR a.filter_zone='')";
- }
- if ($getuser_data->city) {
- $user_cond[] = " (a.filter_region LIKE '%" . $getuser_data->city . "%' OR a.filter_region='')";
- }
- if ($getuser_data->dealer_code) {
- $user_cond[] = " (a.filter_dealer LIKE '%" . $getuser_data->dealer_code . "%' OR a.filter_dealer='')";
- }
- $assess_user_cond = " AND " . @implode(' AND ', $user_cond);
- $count_assessment_str = "SELECT COUNT(a.assessmentid) as acount FROM `" . TABLE_ASSESSMENT . "` as a WHERE a.status='1' AND a.atype='0' AND a.assettypeid='1' AND a.publisheddate>='" . $start_date . " 00:00:00' AND a.publisheddate<='" . $end_date . " 23:59:59' AND a.enddate>='" . $user_data_arr->user->user_created_on . "' AND assessmentid IN (" . @implode(',', $assessmentid_arr) . ") " . $assess_user_cond . $new_cond . " LIMIT 1";
- $count_assessment_arr = $parent->getQueryValue($count_assessment_str);
- $user_data_arr->percentage_score = (count($assessment_arr) > 0) ? round($res_user->user_score / $count_assessment_arr[0]->acount) : '0';
- $user_data_arr->percentage = $user_data_arr->percentage_score;
- if ((($assessment_count / $count_assessment_arr[0]->acount) * 100) >= MIN_ASSESSMENT_PERCENT) {
- $data_arr[] = $user_data_arr;
- }
- }
- }
- if (count($data_arr) > 0) {
- $outof = count($data_arr);
- array_multisort(array_column($data_arr, 'percentage_score'), SORT_DESC, array_column($rank_arr, 'total_time'), SORT_ASC, $rank_arr);
- $rank = 1;
- foreach ($data_arr as $key => $res) {
- $data_arr[$key]->rank = $rank;
- $data_arr[$key]->outof = $outof;
- $rank++;
- }
- }
- } else {
- /*
- $cur_data_arr=new stdClass();
- $udata=projectfunc::getuserdata($parent,$parent->current_user_id);
- $cur_data_arr->user=$udata;
- foreach($udata as $key=>$res)
- {
- $cur_data_arr->$key=$res;
- }
- $cur_data_arr->rank='-';
- $cur_data_arr->tot_user_score='-';
- $cur_data_arr->percentage_score='-';
- $cur_data_arr->percentage=$cur_data_arr->percentage_score;
- $cur_data_arr->total_time='0';
- $cur_data_arr->last_time='-';
- */
- $get_count_arr = array();
- }
- $total_count = count($data_arr);
- /*if(count($data_arr)>0)
- {
- $temp=array_chunk($data_arr,20);
- $data_arr=$temp[0];
- }
- */
- //LOG
- $logstr = 'LEADERBOARD ASSESSMENT';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// ASV ASSESSMENT REPORT //////////////////////////////////////////////// */
- private function asmassessmentreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 2);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- projectfunc::authorizedRole($parent, array('3', '4', '5', '6'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[1]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('assessmentid' => 'integer');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $assessmentid = escape_str($parent->_request["assessmentid"]);
- $assess_str = "SELECT assessmentid,pass_score FROM " . TABLE_ASSESSMENT . " WHERE assessmentid='" . $assessmentid . "' LIMIT 1";
- $assess_arr = $parent->getQueryValue($assess_str);
- if (!(count($assess_arr) > 0)) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error1"]), 406);
- }
- $pass_score = $assess_arr[0]->pass_score;
- $user_cond = "";
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[1]);
- $type = strtolower($qry_params[0]);
- $zm_email = escape_str($parent->_request["zmemail"]);
- $rm_email = escape_str($parent->_request["rmemail"]);
- //$am_email = escape_str($parent->_request["amemail"]);
- if (($rm_email != 'all' && $rm_email != '') || ($zm_email != 'all' && $zm_email != '')) {
- $mcond = '';
- //$mcond=($am_email!='all' && $am_email!='')?" AND am_email='".$am_email."'":'';
- $mcond .= ($rm_email != 'all' && $rm_email != '') ? " AND rm_email='" . $rm_email . "'" : '';
- if ($parent->current_user_role != '5') {
- $mcond .= ($zm_email != 'all' && $zm_email != '') ? " AND zm_email='" . $zm_email . "'" : '';
- }
- if ($parent->current_user_role == '5') {
- $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $mcond .= (count($trainer_arr) > 0) ? "AND zone='" . $trainer_arr[0]->zone . "'" : "AND zone='0'";
- }
- //MANAGER
- $query_all_amarr = $parent->selectQuery(DMS_DEALER, "`dealer_code`,am_email ", " status='1' AND is_deleted='0' " . $mcond . " GROUP BY am_email", "");
- $emailid_arr = array();
- if ($query_all_amarr['nr'] > 0) {
- foreach ($query_all_amarr['result'] as $res) {
- $emailid_arr[] = "'" . $res->am_email . "'";
- }
- $user_cond .= " AND u.emailid IN (" . implode(',', $emailid_arr) . ")";
- } else {
- $user_cond .= " AND u.emailid IN ('')";
- }
- } else {
- //PAN
- $user_cond = '';
- if ($parent->current_user_role == '5') {
- $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $mcond .= (count($trainer_arr) > 0) ? "AND zone='" . $trainer_arr[0]->zone . "'" : "AND zone='0'";
- //$user_cond=" AND u.dealer_code IN (SELECT dealer_code FROM ".DMS_DEALER." WHERE is_deleted='0' ".$mcond.")";
- $query_all_amarr = $parent->selectQuery(DMS_DEALER, "`dealer_code`,am_email ", " status='1' AND is_deleted='0' " . $mcond . " GROUP BY am_email", "");
- $emailid_arr = array();
- if ($query_all_amarr['nr'] > 0) {
- foreach ($query_all_amarr['result'] as $res) {
- $emailid_arr[] = "'" . $res->am_email . "'";
- }
- $user_cond .= " AND u.emailid IN (" . implode(',', $emailid_arr) . ")";
- } else {
- $user_cond .= " AND u.emailid IN ('')";
- }
- }
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[1]);
- //SORT
- $order_by_cond = "ORDER BY u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //0-Score
- //1-Name
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY au.highscore DESC,au.modified_on ASC,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.emp_code LIKE '%" . $search_txt . "%' OR u.emailid LIKE '%" . $search_txt . "%' )";
- }
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.emp_code,u.emailid FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid WHERE u.status='1' AND u.is_deleted='0' AND u.role=7 AND au.assessmentid='" . $assessmentid . "' " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $mkey => $res_user) {
- $exam_highscore_str = "SELECT * FROM " . TABLE_ASSESSMENT_USER . " WHERE assessmentid='" . $assessmentid . "' AND userid='" . $res_user->userid . "' LIMIT 1";
- $exam_highscore_arr = $parent->getQueryValue($exam_highscore_str);
- $user_arr[$mkey]->highscore = (count($exam_highscore_arr) > 0) ? $exam_highscore_arr[0]->highscore : '0';
- $user_arr[$mkey]->is_pass = ($user_arr[$mkey]->highscore >= $pass_score) ? '1' : '0';
- }
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid WHERE u.status='1' AND u.is_deleted='0' AND u.role=7 AND au.assessmentid='" . $assessmentid . "' " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'AM ASSESSMENT REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'pass_score' => $pass_score, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// RM ASSESSMENT REPORT //////////////////////////////////////////////// */
- private function rmassessmentreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 2);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- projectfunc::authorizedRole($parent, array('3', '4', '5'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[1]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('assessmentid' => 'integer');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $assessmentid = escape_str($parent->_request["assessmentid"]);
- $assess_str = "SELECT assessmentid,pass_score FROM " . TABLE_ASSESSMENT . " WHERE assessmentid='" . $assessmentid . "' LIMIT 1";
- $assess_arr = $parent->getQueryValue($assess_str);
- if (!(count($assess_arr) > 0)) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error1"]), 406);
- }
- $pass_score = $assess_arr[0]->pass_score;
- $user_cond = "";
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[1]);
- $type = strtolower($qry_params[0]);
- $zm_email = escape_str($parent->_request["zmemail"]);
- //$rm_email = escape_str($parent->_request["rmemail"]);
- //$am_email = escape_str($parent->_request["amemail"]);
- if ($zm_email != 'all' && $zm_email != '') {
- $mcond = '';
- //$mcond=($am_email!='all' && $am_email!='')?" AND am_email='".$am_email."'":'';
- //$mcond.=($rm_email!='all' && $rm_email!='')?" AND rm_email='".$rm_email."'":'';
- if ($parent->current_user_role != '5') {
- $mcond .= ($zm_email != 'all' && $zm_email != '') ? " AND zm_email='" . $zm_email . "'" : '';
- }
- if ($parent->current_user_role == '5') {
- $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $mcond .= (count($trainer_arr) > 0) ? "AND zone='" . $trainer_arr[0]->zone . "'" : "AND zone='0'";
- }
- //MANAGER
- $query_all_amarr = $parent->selectQuery(DMS_DEALER, "`dealer_code`,rm_email ", " status='1' AND is_deleted='0' " . $mcond . " GROUP BY rm_email", "");
- $emailid_arr = array();
- if ($query_all_amarr['nr'] > 0) {
- foreach ($query_all_amarr['result'] as $res) {
- $emailid_arr[] = "'" . $res->rm_email . "'";
- }
- $user_cond .= " AND u.emailid IN (" . implode(',', $emailid_arr) . ")";
- } else {
- $user_cond .= " AND u.emailid IN ('')";
- }
- } else {
- //PAN
- $user_cond = '';
- if ($parent->current_user_role == '5') {
- $get_trainer_str = "SELECT h.zone FROM " . DMS_HOUSER . " h JOIN " . TABLE_USER . " u ON u.emp_code=h.emp_code WHERE u.userid='" . $parent->current_user_id . "' AND u.role='5' LIMIT 1";
- $trainer_arr = $parent->getQueryValue($get_trainer_str);
- $mcond .= (count($trainer_arr) > 0) ? "AND zone='" . $trainer_arr[0]->zone . "'" : "AND zone='0'";
- //$user_cond=" AND u.dealer_code IN (SELECT dealer_code FROM ".DMS_DEALER." WHERE is_deleted='0' ".$mcond.")";
- $query_all_amarr = $parent->selectQuery(DMS_DEALER, "`dealer_code`,rm_email ", " status='1' AND is_deleted='0' " . $mcond . " GROUP BY rm_email", "");
- $emailid_arr = array();
- if ($query_all_amarr['nr'] > 0) {
- foreach ($query_all_amarr['result'] as $res) {
- $emailid_arr[] = "'" . $res->rm_email . "'";
- }
- $user_cond .= " AND u.emailid IN (" . implode(',', $emailid_arr) . ")";
- } else {
- $user_cond .= " AND u.emailid IN ('')";
- }
- }
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[1]);
- //SORT
- $order_by_cond = "ORDER BY u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Name
- //2-RM
- //3-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY au.highscore DESC,au.modified_on ASC,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.emp_code LIKE '%" . $search_txt . "%' )";
- }
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.emp_code,u.emailid FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid WHERE u.status='1' AND u.is_deleted='0' AND u.role=6 AND au.assessmentid='" . $assessmentid . "' " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $mkey => $res_user) {
- $exam_highscore_str = "SELECT * FROM " . TABLE_ASSESSMENT_USER . " WHERE assessmentid='" . $assessmentid . "' AND userid='" . $res_user->userid . "' LIMIT 1";
- $exam_highscore_arr = $parent->getQueryValue($exam_highscore_str);
- $user_arr[$mkey]->highscore = (count($exam_highscore_arr) > 0) ? $exam_highscore_arr[0]->highscore : '0';
- $user_arr[$mkey]->is_pass = ($user_arr[$mkey]->highscore >= $pass_score) ? '1' : '0';
- }
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid WHERE u.status='1' AND u.is_deleted='0' AND u.role=6 AND au.assessmentid='" . $assessmentid . "' " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'RM ASSESSMENT REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'pass_score' => $pass_score, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// ZM ASSESSMENT REPORT //////////////////////////////////////////////// */
- private function zmassessmentreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- projectfunc::authorizedRole($parent, array('3'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('assessmentid' => 'integer');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $assessmentid = escape_str($parent->_request["assessmentid"]);
- $assess_str = "SELECT assessmentid,pass_score FROM " . TABLE_ASSESSMENT . " WHERE assessmentid='" . $assessmentid . "' LIMIT 1";
- $assess_arr = $parent->getQueryValue($assess_str);
- if (!(count($assess_arr) > 0)) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error1"]), 406);
- }
- $pass_score = $assess_arr[0]->pass_score;
- $user_cond = "";
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[0]);
- $type = strtolower($qry_params[0]);
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Name
- //2-RM
- //3-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY au.highscore DESC,au.modified_on ASC,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.emp_code LIKE '%" . $search_txt . "%' )";
- }
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.emp_code,u.emailid FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid WHERE u.status='1' AND u.is_deleted='0' AND u.role=4 AND au.assessmentid='" . $assessmentid . "' " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $mkey => $res_user) {
- $exam_highscore_str = "SELECT * FROM " . TABLE_ASSESSMENT_USER . " WHERE assessmentid='" . $assessmentid . "' AND userid='" . $res_user->userid . "' LIMIT 1";
- $exam_highscore_arr = $parent->getQueryValue($exam_highscore_str);
- $user_arr[$mkey]->highscore = (count($exam_highscore_arr) > 0) ? $exam_highscore_arr[0]->highscore : '0';
- $user_arr[$mkey]->is_pass = ($user_arr[$mkey]->highscore >= $pass_score) ? '1' : '0';
- }
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid WHERE u.status='1' AND u.is_deleted='0' AND u.role=4 AND au.assessmentid='" . $assessmentid . "' " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'ZM ASSESSMENT REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'pass_score' => $pass_score, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// TRAINER ASSESSMENT REPORT //////////////////////////////////////////////// */
- private function trainerassessmentreport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- projectfunc::authorizedRole($parent, array('3'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $role = $parent->current_user_role;
- $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
- //FIELDS VALIDATION
- $REQUEST_KEYS = array('assessmentid' => 'integer');
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $assessmentid = escape_str($parent->_request["assessmentid"]);
- $assess_str = "SELECT assessmentid,pass_score FROM " . TABLE_ASSESSMENT . " WHERE assessmentid='" . $assessmentid . "' LIMIT 1";
- $assess_arr = $parent->getQueryValue($assess_str);
- if (!(count($assess_arr) > 0)) {
- $parent->response(array('response' => 'failed', 'message' => $this->page_data["error1"]), 406);
- }
- $pass_score = $assess_arr[0]->pass_score;
- $user_cond = "";
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[0]);
- $type = strtolower($qry_params[0]);
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY u.fname ASC ";
- if (isset($filter_arr) && isset($filter_arr['sort'])) {
- //1-Name
- //2-RM
- //3-ZM
- switch ($filter_arr['sort']) {
- case '1':$order_by_cond = "ORDER BY u.fname ASC ";
- break;
- default:$order_by_cond = "ORDER BY au.highscore DESC,au.modified_on ASC,u.fname ASC ";
- break;
- }
- }
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' OR u.emp_code LIKE '%" . $search_txt . "%' )";
- }
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.emp_code,u.emailid FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid WHERE u.status='1' AND u.is_deleted='0' AND u.role=5 AND au.assessmentid='" . $assessmentid . "' " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $mkey => $res_user) {
- $exam_highscore_str = "SELECT * FROM " . TABLE_ASSESSMENT_USER . " WHERE assessmentid='" . $assessmentid . "' AND userid='" . $res_user->userid . "' LIMIT 1";
- $exam_highscore_arr = $parent->getQueryValue($exam_highscore_str);
- $user_arr[$mkey]->highscore = (count($exam_highscore_arr) > 0) ? $exam_highscore_arr[0]->highscore : '0';
- $user_arr[$mkey]->is_pass = ($user_arr[$mkey]->highscore >= $pass_score) ? '1' : '0';
- }
- }
- //GET COUNT
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u JOIN " . TABLE_ASSESSMENT_USER . " as au ON u.userid=au.userid WHERE u.status='1' AND u.is_deleted='0' AND u.role=4 AND au.assessmentid='" . $assessmentid . "' " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'ZM ASSESSMENT REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'pass_score' => $pass_score, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// NEW SALES TAREGT REPORT //////////////////////////////////////////////// */
- private function newsalestargetreport($parent)
- {
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// managersalestargetreport //////////////////////////////////////////////// */
- private function managersalestargetreport($parent)
- {
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// DEALER LIST //////////////////////////////////////////////// */
- private function dealerlist($parent)
- {
- globalfunc::checkMethodType($parent, array('GET'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- projectfunc::authorizedRole($parent, array('7'));
- $am_email = $parent->current_user_data->emailid;
- $query_str = "SELECT dealer_code,dealer_name FROM " . DMS_DEALER . " WHERE status='1' AND is_deleted='0' and am_email='" . $am_email . "'";
- $data_arr = $parent->getQueryValue($query_str);
- $data_arr = (count($data_arr) > 0) ? $data_arr : array();
- //LOG
- $logstr = 'AM DEALER LIST';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// USER LIST //////////////////////////////////////////////// */
- private function userlist($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- projectfunc::authorizedRole($parent, array('7', '14'));
- $userid = $parent->current_user_id;
- $role = $parent->current_user_role;
- $usercond = '';
- if ($role == 7) //AM
- {
- $dealer_code = escape_str($parent->_request["dealer_code"]);
- if ($dealer_code != '') {
- $usercond = " and u.dealer_code='" . $dealer_code . "'";
- } else {
- $am_email = $parent->current_user_data->emailid;
- $usercond = " and d.am_email='" . $am_email . "'";
- }
- } else //DEALER
- {
- $dealer_code = $parent->current_user_data->dealer_code;
- $usercond = "and u.dealer_code='" . $dealer_code . "'";
- }
- $query_str = "SELECT u.status,u.userid,u.fname,u.lname,u.smpin,u.dealer_code,d.dealer_name,u.segment,CASE WHEN u.segment=0 THEN 'Student Learner' WHEN u.segment=1 THEN 'Parents/Guardian' WHEN u.segment=2 THEN 'Instructor' END as segment_str,CASE WHEN u.status=1 THEN '1' ELSE '0' END as is_active FROM " . TABLE_USER . " u LEFT JOIN " . DMS_EMPLOYEE . " e ON u.smpin=e.smpin LEFT JOIN " . DMS_DEALER . " d ON u.dealer_code=d.dealer_code WHERE e.is_current='1' AND u.is_deleted='0' and u.role>7 AND u.role<14 " . $usercond . " ORDER BY u.dealer_code ASC,u.fname ASC,u.userid ASC";
- $data_arr = $parent->getQueryValue($query_str);
- $data_arr = (count($data_arr) > 0) ? $data_arr : array();
- //LOG
- $logstr = 'MANAGER DSE LIST';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// USER STATUS UPDATE //////////////////////////////////////////////// */
- private function userstatusupdate($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- projectfunc::authorizedRole($parent, array('7', '14'));
- $REQUEST_KEYS = array('userid' => 'number', 'status' => "number");
- globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
- $userid = escape_str($parent->_request["userid"]);
- $status = (escape_str($parent->_request["status"]) == 1) ? 1 : 2;
- $remark = escape_str($parent->_request["remark"]);
- $cond_str = ($status == 2) ? ",inactivated_on='" . NOW . "'" : "";
- $update_qry = "UPDATE " . TABLE_USER . " SET status='" . $status . "' " . $cond_str . " , modified_on='" . NOW . "' WHERE userid='" . $userid . "'";
- $parent->executeQuery($update_qry);
- $insert_qry = "INSERT INTO " . TABLE_USER_STATUS_HISTORY . " ( `userid`, `action_user`,status, `remarks`, `created_on`) VALUES ('" . $userid . "', '" . $parent->current_user_id . "','" . $status . "', '" . $remark . "','" . NOW . "')";
- $parent->executeQuery($insert_qry);
- //LOG
- $logstr = 'USER STATUS UPDATE';
- globalfunc::insertUserLog($parent, $logstr);
- $parent->response(array('response' => 'success', 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- // ZM Course Report
- private function zmcoursereport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[0]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY u.fname ASC,u.lname ASC,u.userid ASC ";
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' )";
- }
- //$user_cond.=" AND e.is_current='1' ";
- // u.status='1' AND
- $get_user_str = "SELECT SQL_CALC_FOUND_ROWS u.userid,u.fname,u.lname,u.emp_code,u.mobileno,u.emailid FROM " . TABLE_USER . " u JOIN " . DMS_DEALER . " d ON u.emailid=d.zm_email WHERE u.is_deleted='0' AND u.role=4 " . $user_cond . " GROUP BY u.userid " . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- $get_count_str = "SELECT FOUND_ROWS() as ucount";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $ukey => $res) {
- $content_arr = projectfunc::managerCourseCompleteStatus($parent, $res->userid, 4);
- $user_arr[$ukey]->total_content = $content_arr['total'];
- $user_arr[$ukey]->completed_content = $content_arr['completed'];
- $user_arr[$ukey]->percentage = ($content_arr['total'] > 0) ? round(($content_arr['completed'] / $content_arr['total']) * 100) : '0';
- }
- } else {
- $user_arr = array();
- }
- //GET COUNT
- // u.status='1' AND
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'ZM COURSE REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- // TRAINER Course Report
- private function trainercoursereport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[0]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY u.fname ASC,u.lname ASC,u.userid ASC ";
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' )";
- }
- //$user_cond.=" AND e.is_current='1' ";
- // u.status='1' AND
- $get_user_str = "SELECT u.userid,u.fname,u.lname,u.emp_code,u.mobileno,u.emailid FROM " . TABLE_USER . " u WHERE u.is_deleted='0' AND u.role=5 " . $user_cond . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $ukey => $res) {
- $content_arr = projectfunc::managerCourseCompleteStatus($parent, $res->userid, 5);
- $user_arr[$ukey]->total_content = $content_arr['total'];
- $user_arr[$ukey]->completed_content = $content_arr['completed'];
- $user_arr[$ukey]->percentage = ($content_arr['total'] > 0) ? round(($content_arr['completed'] / $content_arr['total']) * 100) : '0';
- }
- } else {
- $user_arr = array();
- }
- //GET COUNT
- // u.status='1' AND
- $get_count_str = "SELECT COUNT(u.userid)as ucount FROM " . TABLE_USER . " u WHERE u.is_deleted='0' AND u.role=5 " . $user_cond . " LIMIT 1";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'TRAINER COURSE REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- // RM Course Report
- private function rmcoursereport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[0]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- //MANAGER WISE DEALER CONDITION
- $dealer_cond_arr = $this->getmanagerconditon_arr($parent);
- if (count($dealer_cond_arr) > 0) {
- //APPEND prefix
- array_walk($dealer_cond_arr, function (&$value, $key) {$value = 'd.' . $value;});
- $user_cond .= " AND " . @implode(" AND ", $dealer_cond_arr);
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY u.fname ASC,u.lname ASC,u.userid ASC ";
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' )";
- }
- //$user_cond.=" AND e.is_current='1' ";
- // u.status='1' AND
- $get_user_str = "SELECT SQL_CALC_FOUND_ROWS u.userid,u.fname,u.lname,u.emp_code,u.emailid FROM " . TABLE_USER . " u JOIN " . DMS_DEALER . " d ON u.emailid=d.rm_email WHERE u.is_deleted='0' AND u.role=6 " . $user_cond . " GROUP BY u.userid " . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- $get_count_str = "SELECT FOUND_ROWS() as ucount";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $ukey => $res) {
- $content_arr = projectfunc::managerCourseCompleteStatus($parent, $res->userid, 6);
- $user_arr[$ukey]->total_content = $content_arr['total'];
- $user_arr[$ukey]->completed_content = $content_arr['completed'];
- $user_arr[$ukey]->percentage = ($content_arr['total'] > 0) ? round(($content_arr['completed'] / $content_arr['total']) * 100) : '0';
- }
- } else {
- $user_arr = array();
- }
- //GET COUNT
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'RM COURSE REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- // AM Course Report
- private function amcoursereport($parent)
- {
- globalfunc::checkMethodType($parent, array('POST'));
- globalfunc::checkParamCount($parent, 1);
- globalfunc::checkAuthrozation($parent, array('type' => 'user'));
- $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
- $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
- $dealer_code_cond = '';
- $qry_params = explode("?", $parent->params[0]);
- $type = strtolower($qry_params[0]);
- $user_cond = "";
- //MANAGER WISE DEALER CONDITION
- $dealer_cond_arr = $this->getmanagerconditon_arr($parent);
- if (count($dealer_cond_arr) > 0) {
- //APPEND prefix
- array_walk($dealer_cond_arr, function (&$value, $key) {$value = 'd.' . $value;});
- $user_cond .= " AND " . @implode(" AND ", $dealer_cond_arr);
- }
- $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
- //SORT
- $order_by_cond = "ORDER BY u.fname ASC,u.lname ASC,u.userid ASC ";
- if (isset($parent->_request["search"]) && $parent->_request["search"] != '') {
- $search_txt = escape_str($parent->_request["search"]);
- $user_cond .= " AND (u.fname LIKE '%" . $search_txt . "%' OR u.lname LIKE '%" . $search_txt . "%' )";
- }
- //$user_cond.=" AND e.is_current='1' ";
- // u.status='1' AND
- $get_user_str = "SELECT SQL_CALC_FOUND_ROWS u.userid,u.fname,u.lname,u.emp_code,u.emailid FROM " . TABLE_USER . " u JOIN " . DMS_DEALER . " d ON u.emailid=d.am_email WHERE u.is_deleted='0' AND u.role=7 " . $user_cond . " GROUP BY u.userid " . $order_by_cond . $limit_cond;
- $user_arr = $parent->getQueryValue($get_user_str);
- $get_count_str = "SELECT FOUND_ROWS() as ucount";
- $get_count_arr = $parent->getQueryValue($get_count_str);
- if (count($user_arr) > 0) {
- foreach ($user_arr as $ukey => $res) {
- $content_arr = projectfunc::managerCourseCompleteStatus($parent, $res->userid, 7);
- $user_arr[$ukey]->total_content = $content_arr['total'];
- $user_arr[$ukey]->completed_content = $content_arr['completed'];
- $user_arr[$ukey]->percentage = ($content_arr['total'] > 0) ? round(($content_arr['completed'] / $content_arr['total']) * 100) : '0';
- }
- } else {
- $user_arr = array();
- }
- //GET COUNT
- $total = (count($get_count_arr) > 0) ? $get_count_arr[0]->ucount : 0;
- //LOG
- $logstr = 'AM COURSE REPORT';
- globalfunc::insertUserLog($parent, $logstr);
- $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
- $parent->response(array('response' => 'success', 'data' => $user_arr, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- }
|