enquiry.php 158 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749
  1. <?php
  2. /****************************
  3. * File : enquiry.php
  4. * Author : Cygnusa
  5. * @2020
  6. ****************************/
  7. //SECURITY
  8. if (!defined('APPLICATION_PATH')) {
  9. exit('No direct script access allowed');
  10. }
  11. /* cSpell:disable */
  12. //FUNCTION LISTS
  13. function comparator($object1, $object2)
  14. {
  15. return $object1->order > $object2->order;
  16. }
  17. class enquiry
  18. {
  19. public function __construct($parent)
  20. {
  21. //GET PAGE MESSAGE
  22. $this->page_data = globalfunc::getMessage($parent, $parent->lang, 'enquiry');
  23. if (count($parent->params) == 0) {
  24. $this->enquirysubmit($parent);
  25. } else {
  26. $qry_params = explode("?", $parent->params[0]);
  27. $parameter_val = strtolower($qry_params[0]);
  28. switch ($parameter_val) {
  29. case "common":
  30. case "checkunsave":
  31. case "deleteunsave":
  32. case "otp":
  33. case "otpvalidate":
  34. case "dashboard":
  35. case "enquirysales":
  36. case "listdata":
  37. case "details":
  38. case "followup":
  39. case "stockavailability":
  40. case "sharebrochure": //NOT COMPLETED
  41. //case "followuphistory":
  42. case "quotation":
  43. case "sharequotation":
  44. // case "getquotation":
  45. case "pricelist":
  46. case "testride":
  47. case 'plannerlist':
  48. case 'plannersave':
  49. case 'plannerupdate':
  50. case 'plannerdelete':
  51. case "plannertimer":
  52. case "smpindealer":
  53. case "dealer":
  54. case "followupcommon":
  55. case "testrideupdate":
  56. case "testrideotp":
  57. $this->$parameter_val($parent);
  58. break;
  59. default:
  60. $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
  61. break;
  62. }
  63. }
  64. $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
  65. }
  66. /* /////////////////////////////// COMMON //////////////////////////////////////////////// */
  67. private function common($parent)
  68. {
  69. globalfunc::checkMethodType($parent, array('GET'));
  70. //globalfunc::checkParamCount($parent,1);
  71. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  72. //CHECK SMPIN OTP EXIST
  73. $buyertype_data = $parent->selectQuery(DMS_ENQUIRY_BUYERTYPE, "id,title,title_code", " status='1'", "");
  74. $title_data = $parent->selectQuery(DMS_ENQUIRY_TITLE, "id,title,title_code", " status='1'", "");
  75. $company_data = $parent->selectQuery(DMS_ENQUIRY_ORGANISATION, "id,title,title_code", " status='1'", "");
  76. $communicate_data = $parent->selectQuery(DMS_ENQUIRY_COMMUNICATE, "id,title,title_code", " status='1'", "");
  77. $action_data = $parent->selectQuery(DMS_ENQUIRY_ACTIONPLAN, "id,title,title_code", " status='1'", "");
  78. $purpose_data = $parent->selectQuery(DMS_ENQUIRY_PURPOSE, "id,title,title_code", " status='1'", ""); //STAGE SAME ONLY
  79. switch ($parent->current_user_data->segment) {
  80. case '0':$segmentcond = "";
  81. break;
  82. case '1':$segmentcond = " AND segment='1'";
  83. break;
  84. case '2':$segmentcond = " AND segment='2'";
  85. break;
  86. }
  87. $model_data = $parent->selectQuery(DMS_ENQUIRY_MODEL, "title,title_code", " status='1' AND enq_yn='Y' " . $segmentcond . " GROUP BY title_code", "");
  88. $profession_data = $parent->selectQuery(DMS_ENQUIRY_PROFESSION, "title,title_code", " status='1' ", "");
  89. $sdata = array();
  90. $dealer_code = $parent->current_user_data->dealer_code;
  91. $dealer_data = $parent->selectQuery(DMS_DEALER, "dealer_map_cd", "dealer_code='" . $dealer_code . "' AND status='1' AND is_deleted=0 AND dealer_map_cd!=''", "1");
  92. //dealer_map_cd
  93. if ($dealer_data['nr'] > 0) {
  94. $p_dealer = $dealer_data['result'][0]->dealer_map_cd;
  95. //GET SOURCE
  96. $url = SUZ_DMS_URL;
  97. $post = array("query" => "BEGIN pkg_smipl_star_app.sp_enquiry_source(:p_dealer, :list_cursor, :p_err_cd, :p_err_msg); END;", "params" => '[{"title":"p_dealer","value":"' . $p_dealer . '","type":""},{"title":"list_cursor","value":"","type":"cursor"},{"title":"p_err_cd","value":"0","type":""},{"title":"p_err_msg","value":"","type":""}]');
  98. $header = array('Authorization:Bearer ' . SUZ_TOKEN);
  99. //LOG
  100. $obj = new stdClass();
  101. $obj->type = 'callsource';
  102. $obj->apirequest = $post['params'];
  103. $log_id = projectfunc::cronLog($parent, $obj);
  104. // $ch = curl_init();
  105. // curl_setopt($ch, CURLOPT_URL, $url);
  106. // curl_setopt($ch, CURLOPT_POST, 1);
  107. // curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //Post Fields
  108. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  109. // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  110. // $response = curl_exec($ch);
  111. // $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  112. // curl_close($ch);
  113. $httpcode = '200';
  114. $response="";
  115. $error = 1;
  116. $count = 0;
  117. //REPSONSE SAVE
  118. $obj = new stdClass();
  119. $obj->id = $log_id;
  120. $obj->apiresponse = $response;
  121. projectfunc::updateCronLog($parent, $obj);
  122. if ($httpcode == '200' && $response != '') {
  123. $json = json_decode($response);
  124. if (isset($json->response) && $json->response == 'success' && isset($json->data) && count($json->data) > 0) {
  125. foreach ($json->data as $res) {
  126. $new = new stdClass();
  127. $new->title = $res->ETYPE_DESC;
  128. $new->title_code = $res->ETYPE_CD;
  129. $sdata[] = $new;
  130. }
  131. $source_data['nr'] = count($sdata);
  132. $source_data['result'] = $sdata;
  133. //LOG UPDATE
  134. $obj = new stdClass();
  135. $obj->id = $log_id;
  136. $obj->insert_count = $source_data['nr'];
  137. $obj->status = 1;
  138. projectfunc::updateCronLog($parent, $obj);
  139. }
  140. }
  141. }
  142. if (count($sdata) == 0) {
  143. $source_data = $parent->selectQuery(DMS_ENQUIRY_SOURCE, "title,title_code", " status='1' ", "");
  144. }
  145. $custtype_data = $parent->selectQuery(DMS_ENQUIRY_CUSTTYPE, "title,title_code", " status='1' ", "");
  146. $custage_data = $parent->selectQuery(DMS_ENQUIRY_CUSTAGE, "title,title_code", " status='1' ", "");
  147. $modeofcontact_data = $parent->selectQuery(DMS_ENQUIRY_MODE, "title,title_code", " status='1' ", "");
  148. $brochure_arr = array();
  149. $brochure_url = SITE_URL . "explore_assets/model/";
  150. $expmodel_data = $parent->selectQuery(TABLE_COMPARE_MODEL, "model_id,CASE WHEN model_brochure!='' THEN CONCAT('" . $brochure_url . "',model_brochure) ELSE '' END AS 'model_brochure', CASE WHEN model_image!='' THEN CONCAT('" . SITE_URL . "hypermupload/model/',model_image) ELSE '" . NOIMAGE_URL . "' END as model_image ", "is_deleted=0 AND is_other=0 AND `model_type` = '0'", "");
  151. if ($expmodel_data['nr'] > 0) {
  152. $arr_id = array_column($expmodel_data['result'], 'model_id');
  153. $arr_name = array_column($expmodel_data['result'], 'model_brochure');
  154. $brochure_arr = array_combine($arr_id, $arr_name);
  155. $arr_image = array_column($expmodel_data['result'], 'model_image');
  156. $img_arr = array_combine($arr_id, $arr_image);
  157. }
  158. //MODEL DATA BUILD
  159. if ($model_data['nr'] > 0) {
  160. foreach ($model_data['result'] as $key => $res) {
  161. $variant_data = $parent->selectQuery(DMS_ENQUIRY_MODEL, "variant title,variant_code title_code", " status='1' AND title_code='" . $res->title_code . "' AND enq_yn='Y' " . $segmentcond . " GROUP BY variant_code", "");
  162. if ($variant_data['nr'] > 0) {
  163. foreach ($variant_data['result'] as $nkey => $resm) {
  164. $color_data = $parent->selectQuery(DMS_ENQUIRY_MODEL, "color title,color_code title_code", " status='1' AND title_code='" . $res->title_code . "' AND variant_code='" . $resm->title_code . "' AND enq_yn='Y' " . $segmentcond . " GROUP BY color_code", "");
  165. $variant_data['result'][$nkey]->color = ($color_data['nr'] > 0) ? $color_data['result'] : array();
  166. $variant_data['result'][$nkey]->model_image = NOIMAGE_URL;
  167. $brochure_url = '';
  168. $model_image = NOIMAGE_URL;
  169. switch ($res->title_code) {
  170. case 'GSX': //GIXXER
  171. $id = (strpos($resm->title_code, 'GSX250') !== false || strpos($resm->title, 'GIXXER 250') !== false) ? GIXXER_250_ID : GIXXER_ID;
  172. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  173. $model_image = isset($img_arr[$id]) ? $img_arr[$id] : NOIMAGE_URL;
  174. break;
  175. case 'GSXSF': //GIXXER SF
  176. $id = (strpos($resm->title_code, 'GSXF250') !== false || strpos($resm->title, 'GIXXER SF 250') !== false) ? GIXXER_SF_250_ID : GIXXER_SF_ID;
  177. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  178. $model_image = isset($img_arr[$id]) ? $img_arr[$id] : NOIMAGE_URL;
  179. break;
  180. case 'GL': //INTRUDER
  181. $id = INTRUDER_ID;
  182. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  183. $model_image = isset($img_arr[$id]) ? $img_arr[$id] : NOIMAGE_URL;
  184. break;
  185. case 'UB125': //BURGMAN
  186. $id = BURGMAN_ID;
  187. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  188. $model_image = isset($img_arr[$id]) ? $img_arr[$id] : NOIMAGE_URL;
  189. break;
  190. case 'AC':
  191. case 'ACZ':
  192. $id = ACCESS_ID;
  193. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  194. $model_image = isset($img_arr[$id]) ? $img_arr[$id] : NOIMAGE_URL;
  195. break;
  196. default:
  197. $brochure_url = '';
  198. break;
  199. }
  200. $variant_data['result'][$nkey]->brochure = $brochure_url;
  201. $variant_data['result'][$nkey]->model_image = $model_image;
  202. }
  203. }
  204. $model_data['result'][$key]->variant = ($variant_data['nr'] > 0) ? $variant_data['result'] : array();
  205. }
  206. }
  207. $buyertype_arr = ($buyertype_data['nr'] > 0) ? $buyertype_data['result'] : array();
  208. $title_arr = ($title_data['nr'] > 0) ? $title_data['result'] : array();
  209. $company_arr = ($company_data['nr'] > 0) ? $company_data['result'] : array();
  210. $communicate_arr = ($communicate_data['nr'] > 0) ? $communicate_data['result'] : array();
  211. $action_arr = ($action_data['nr'] > 0) ? $action_data['result'] : array();
  212. $purpose_arr = ($purpose_data['nr'] > 0) ? $purpose_data['result'] : array();
  213. $model_arr = ($model_data['nr'] > 0) ? $model_data['result'] : array();
  214. $profession_arr = ($profession_data['nr'] > 0) ? $profession_data['result'] : array();
  215. $source_arr = ($source_data['nr'] > 0) ? $source_data['result'] : array();
  216. $custtype_arr = ($custtype_data['nr'] > 0) ? $custtype_data['result'] : array();
  217. $custage_arr = ($custage_data['nr'] > 0) ? $custage_data['result'] : array();
  218. $modeofcontact_arr = ($modeofcontact_data['nr'] > 0) ? $modeofcontact_data['result'] : array();
  219. $t_arr = array("00", "30");
  220. for ($i = 9; $i < 19; $i++) {
  221. $m = ($i < 10) ? "0" . $i : $i;
  222. foreach ($t_arr as $tstr) {
  223. //$t=($tstr<10)?"0".$tstr:$tstr;
  224. $tvalue = $m . ":" . $tstr;
  225. $time_arr[] = array('title' => $tvalue, 'title_code' => $tvalue);
  226. }
  227. }
  228. $gender = array(0 => array('title' => "Male", "title_code" => "M"), 1 => array('title' => "Female", "title_code" => "F"), 2 => array('title' => "Transgender", "title_code" => "T"));
  229. $data = array('gender' => $gender, 'buyertype' => $buyertype_arr, 'title' => $title_arr, 'company' => $company_arr, 'communicate' => $communicate_arr, 'actionplan' => $action_arr, 'purpose' => $purpose_arr, 'model' => $model_arr, 'profession' => $profession_arr, 'source' => $source_arr, 'custtype' => $custtype_arr, 'custage' => $custage_arr, 'time' => $time_arr, 'modeofcontact' => $modeofcontact_arr);
  230. //LOG
  231. $logstr = 'ENQUIRY COMMON';
  232. globalfunc::insertUserLog($parent, $logstr);
  233. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success1']), 200);
  234. }
  235. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  236. /* /////////////////////////////// CHECKUNSAVE //////////////////////////////////////////////// */
  237. private function checkunsave($parent)
  238. {
  239. globalfunc::checkMethodType($parent, array('GET'));
  240. globalfunc::checkParamCount($parent, 1);
  241. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  242. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  243. //PAGINATION SETTINGS
  244. // $limit_cond='';
  245. // $data_arr=array();
  246. // $limit_str=globalfunc::setPageLimit($parent,$parent->params[0]);
  247. // $limit_cond=($limit_str)?" LIMIT ".$limit_str:'';
  248. $smpin = $parent->current_user_data->smpin;
  249. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id", "save_level!=0 AND smpin='" . $smpin . "' AND is_starapp=1 AND is_dms=0 AND is_deleted=0 ", "1");
  250. $total = ($check_arr['nr'] > 0) ? 1 : 0;
  251. // $total_arr=$parent->getQueryValue("SELECT FOUND_ROWS() as total_record");
  252. // $total=(count($total_arr)>0)?$total_arr[0]->total_record:0;
  253. //EXIST CHECK
  254. $is_exist = ($check_arr['nr'] > 0) ? 1 : 0;
  255. $data = new stdClass();
  256. $data->details = array();
  257. if ($is_exist == 1) {
  258. foreach ($check_arr['result'] as $res) {
  259. $data->details[] = $this->getEnquirydata($parent, $res->id);
  260. }
  261. }
  262. $data->is_exist = $is_exist;
  263. //LOG
  264. $logstr = 'ENQUIRY CHECKUNSAVE';
  265. globalfunc::insertUserLog($parent, $logstr);
  266. $last_page = 0;
  267. //$last_page=($total)?ceil($total/$parent->current_limit)-1:0;
  268. $parent->response(array('response' => 'success', 'data' => $data, 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1']), 200);
  269. }
  270. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  271. /* /////////////////////////////// DELETE UNSAVE //////////////////////////////////////////////// */
  272. private function deleteunsave($parent)
  273. {
  274. globalfunc::checkMethodType($parent, array('DELETE'));
  275. globalfunc::checkParamCount($parent, 2);
  276. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  277. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  278. $smpin = $parent->current_user_data->smpin;
  279. $id = escape_str($parent->params[1]);
  280. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id,is_deleted", " smpin='" . $smpin . "' AND is_dms=0 AND id='" . $id . "' ", "1");
  281. if ($check_arr['nr'] == 1) {
  282. $update_str = "UPDATE " . DMS_ENQUIRY_MASTER . " SET is_deleted=1 ,`modified_on`='" . NOW . "' WHERE id='" . $id . "'";
  283. $parent->executeQuery($update_str);
  284. //LOG
  285. $logstr = 'ENQUIRY UNSAVE DELETE';
  286. globalfunc::insertUserLog($parent, $logstr);
  287. $parent->response(array('response' => 'success', 'message' => $this->page_data['success1']), 200);
  288. } else {
  289. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  290. }
  291. }
  292. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  293. /* /////////////////////////////// OTP //////////////////////////////////////////////// */
  294. private function otp($parent)
  295. {
  296. globalfunc::checkMethodType($parent, array('POST'));
  297. globalfunc::checkParamCount($parent, 1);
  298. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  299. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  300. $REQUEST_KEYS = array('mobile' => 'string');
  301. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  302. $mobile = escape_str($parent->_request['mobile']);
  303. $smpin = $parent->current_user_data->smpin;
  304. $otp_expiry = globalfunc::generateExpiryTime($parent, ENQUIRY_OTP_EXPIRY_MIN);
  305. $otp = globalfunc::generateOTP();
  306. //CHECK SMPIN OTP EXIST
  307. $query_arr = $parent->selectQuery(TABLE_ENQUIRY_OTP, "id", " smpin='" . $smpin . "' AND is_checked=0 AND mobile='" . $mobile . "'", "1");
  308. if ($query_arr['nr'] > 0) {
  309. $update_str = "UPDATE " . TABLE_ENQUIRY_OTP . " SET `otp`='" . $otp . "', otp_expiry='" . $otp_expiry . "', `modified_on`='" . NOW . "' WHERE id='" . $query_arr['result'][0]->id . "'";
  310. $parent->executeQuery($update_str);
  311. } else {
  312. $insert_str = "INSERT INTO " . TABLE_ENQUIRY_OTP . " ( `smpin`, `mobile`, `otp`, `otp_expiry`, `created_on`, `modified_on`) VALUES ('" . $smpin . "', '" . $mobile . "', '" . $otp . "', '" . $otp_expiry . "', '" . NOW . "', '" . NOW . "')";
  313. $parent->executeQuery($insert_str);
  314. }
  315. $sms_message = "Your one time password is " . $otp;
  316. // globalfunc::sendSMS($parent, $mobile, $sms_message);
  317. $mobile_exist = 0;
  318. $enq_data = new stdClass();
  319. //AND dealer_code='".$parent->current_user_data->dealer_code."'
  320. $mobile_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER . " e JOIN " . DMS_EMPLOYEE . " p ON e.smpin=p.smpin JOIN " . DMS_ENQUIRY_MODEL . " m ON e.model1=m.title_code", "m.title as model,m.variant,m.color,e.newvechicledate", "e.mobile='" . $mobile . "' AND p.dealer_code='" . $parent->current_user_data->dealer_code . "' AND e.is_dms=1 AND e.is_deleted=0 ORDER BY e.newvechicledatatime DESC", "1");
  321. if ($mobile_arr['nr'] > 0) {
  322. $mobile_exist = 1;
  323. $enq_data = $mobile_arr['result'][0];
  324. }
  325. //LOG
  326. $logstr = 'ENQUIRY OTP';
  327. globalfunc::insertUserLog($parent, $logstr);
  328. $parent->response(array('response' => 'success', 'data' => array('otp_expiry' => ENQUIRY_OTP_EXPIRY_MIN, 'mobile_exist' => $mobile_exist, 'enq_data' => $enq_data), 'message' => $this->page_data['success1']), 200);
  329. }
  330. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  331. /* /////////////////////////////// OTP VALIDATE //////////////////////////////////////////////// */
  332. private function otpvalidate($parent)
  333. {
  334. globalfunc::checkMethodType($parent, array('POST'));
  335. globalfunc::checkParamCount($parent, 1);
  336. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  337. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  338. $REQUEST_KEYS = array('mobile' => 'string', 'otp' => 'string');
  339. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  340. $mobile = escape_str($parent->_request['mobile']);
  341. $otp = escape_str($parent->_request['otp']);
  342. $smpin = $parent->current_user_data->smpin;
  343. //CHECK SMPIN OTP EXIST
  344. $query_arr = $parent->selectQuery(TABLE_ENQUIRY_OTP, "*", " smpin='" . $smpin . "' AND mobile='" . $mobile . "' AND is_checked=0 ORDER BY id DESC", "1");
  345. if (!$query_arr['nr'] > 0) {
  346. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error2']), 406);
  347. }
  348. if ($query_arr['result'][0]->otp != $otp) {
  349. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error3']), 406);
  350. }
  351. if (strtotime($query_arr['result'][0]->otp_expiry) < strtotime(NOW)) {
  352. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error4']), 406);
  353. }
  354. $parent->executeQuery("UPDATE " . TABLE_ENQUIRY_OTP . " SET is_checked=1 WHERE id='" . $query_arr['result'][0]->id . "'");
  355. /*
  356. $data_check=array();
  357. $check_arr=$parent->selectQuery(DMS_ENQUIRY_MASTER,"*"," mobile='".$mobile."' ORDER BY id DESC","1");
  358. $enquiry_avaliable=0;
  359. if($check_arr['nr']>0)
  360. {
  361. $enquiry_avaliable=(strtolower($check_arr['result'][0]->status)=='lost' || strtolower($check_arr['result'][0]->enquiry_stage)=='invoiced')?"0":"1";
  362. $data=($enquiry_avaliable=='1')?$check_arr['result'][0]:new stdClass();
  363. }
  364. */
  365. $data = new stdClass();
  366. $data_check = array("enquiry_avaliable" => $enquiry_avaliable, 'data' => $data);
  367. //LOG
  368. $logstr = 'ENQUIRY VALIDATE';
  369. globalfunc::insertUserLog($parent, $logstr);
  370. $parent->response(array('response' => 'success', 'data' => $data_check, 'message' => $this->page_data['success1']), 200);
  371. }
  372. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  373. /* /////////////////////////////// ENQUIRY SUBMIT //////////////////////////////////////////////// */
  374. private function getEnquirydata($parent, $id)
  375. {
  376. $data_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, " `id`, `enq_num`, `transaction_id`, `enq_salesman_cd`, `smpin`, `mobile`, `email`, `buyer_type`, `title`, `first_name`, `middle_name`, `last_name`, `ind_sex`, `address1`, `address2`, `address3`, `city`, `state`, `ofc_address1`, `ofc_address2`, `ofc_address3`, `ofc_city`, `ofc_state`, `workplace_id`, `company`, `work_place_name`, `communicate`, `newvechicledatatime`, `newvechicletactionplan`, `oldvechicledate`, `oldvechicletime`, `oldvechicletactionplan`, `model1`, `variant1`, `color1`, `model2`, `variant2`, `color2`, `oldvechiclemaker`, `oldvechiclemodel`, `profession`, `source`, `custtype`, `custage`, `modeofcontact`, `enquiry_stage`, `lik_pur_days`, `followup_remark`, `status`, `save_level`, `is_dms`, `is_starapp`, `created_on`, `modified_on`,ind_sex as gender,DATE_FORMAT(newvechicledatatime, '%d-%m-%Y') newvechicledate,newvechicletime,enquiry_stage as newvechicletpurpose,is_starapp,license,license_expiry,is_testride ", "id='" . $id . "'", "1");
  377. $data_arr['result'][0]->model_image_url = NOIMAGE_URL;
  378. if ($data_arr['result'][0]->model1 != '' && $data_arr['result'][0]->variant1 != '') {
  379. $data_arr['result'][0]->license_expiry = ($data_arr['result'][0]->is_testride == 1 && $data_arr['result'][0]->license_expiry != '0000-00-00') ? date('d-m-Y', strtotime($data_arr['result'][0]->license_expiry)) : '';
  380. $res = $data_arr['result'][0];
  381. $model_arr = $parent->selectQuery(DMS_ENQUIRY_MODEL, "title as model_name,variant as variant_name,color as color_name", "title_code='" . $res->model1 . "' AND variant_code='" . $res->variant1 . "' AND color_code='" . $res->color1 . "'", "");
  382. $data_arr['result'][0]->model_name = ($model_arr['nr'] > 0) ? $model_arr['result'][0]->model_name : $res->model1;
  383. $data_arr['result'][0]->variant_name = ($model_arr['nr'] > 0) ? $model_arr['result'][0]->variant_name : $res->variant1;
  384. $data_arr['result'][0]->color_name = ($model_arr['nr'] > 0) ? $model_arr['result'][0]->color_name : $res->color1;
  385. $data_arr['result'][0]->enq_through = ($res->is_starapp == 1) ? "HYPER-M App" : "DMS";
  386. $data_arr['result'][0]->newvechicledatatime_str = projectfunc::enqdatediff($parent, NOW, $res->newvechicledatatime);
  387. $obj = new stdClass();
  388. $obj->model = $data_arr['result'][0]->model1;
  389. $obj->variant = $data_arr['result'][0]->variant1;
  390. $obj->variantname = $data_arr['result'][0]->variant_name;
  391. $data_arr['result'][0]->model_image_url = projectfunc::modelimage($parent, $obj);
  392. //enquiry type, source,profession,age group
  393. $enquiry_arr = $parent->selectQuery(DMS_ENQUIRY_STAGETYPE, "title", "title_code='" . $res->enquiry_stage . "'", "1");
  394. $data_arr['result'][0]->enquiry_str = ($enquiry_arr['nr'] > 0) ? $enquiry_arr['result'][0]->title : '';
  395. $profession_arr = $parent->selectQuery(DMS_ENQUIRY_PROFESSION, "title", "title_code='" . $res->profession . "'", "1");
  396. $data_arr['result'][0]->profession_str = ($profession_arr['nr'] > 0) ? $profession_arr['result'][0]->title : '';
  397. $age_arr = $parent->selectQuery(DMS_ENQUIRY_CUSTAGE, "title", "title_code='" . $res->custage . "'", "1");
  398. $data_arr['result'][0]->agegroup_str = ($age_arr['nr'] > 0) ? $age_arr['result'][0]->title : '';
  399. $title_arr = $parent->selectQuery(DMS_ENQUIRY_TITLE, "title", "title_code='" . $res->title . "'", "1");
  400. $data_arr['result'][0]->title_str = ($title_arr['nr'] > 0) ? $title_arr['result'][0]->title : '';
  401. $source_arr = $parent->selectQuery(DMS_ENQUIRY_SOURCE, "title", "title_code='" . $res->source . "'", "1");
  402. $data_arr['result'][0]->source_str = ($source_arr['nr'] > 0) ? $source_arr['result'][0]->title : '';
  403. $status_arr = $parent->selectQuery(DMS_ENQUIRY_STATUS, "title", "title_code='" . $res->status . "'", "1");
  404. $data_arr['result'][0]->status_str = ($status_arr['nr'] > 0) ? $status_arr['result'][0]->title : '';
  405. $action_arr = $parent->selectQuery(DMS_ENQUIRY_ACTIONPLAN, "title", "title_code='" . $res->newvechicletactionplan . "'", "1");
  406. $data_arr['result'][0]->action_str = ($action_arr['nr'] > 0) ? $action_arr['result'][0]->title : '';
  407. $checkdate = date('Y-m-d', strtotime($res->newvechicledatatime));
  408. //0-overdue,1-current day,2-future
  409. switch (true) {
  410. case (strtotime($checkdate) < strtotime(CUR_DATE)): $data_arr['result'][0]->enq_date_type = 0;
  411. break;
  412. case (strtotime($checkdate) == strtotime(CUR_DATE)): $data_arr['result'][0]->enq_date_type = 1;
  413. break;
  414. case (strtotime($checkdate) > strtotime(CUR_DATE)): $data_arr['result'][0]->enq_date_type = 2;
  415. break;
  416. }
  417. ///PENDING ENQUIRY MASTER
  418. if (strtoupper($res->enquiry_stage) == 'T') {
  419. $data_arr['result'][0]->icon_type = 1;
  420. } else if (strtoupper($res->modeofcontact) == 'S' || strtoupper($res->modeofcontact) == 'V') {
  421. $data_arr['result'][0]->icon_type = 2;
  422. } else if (in_array(strtoupper($res->modeofcontact), array('E', 'F', 'O', 'T'))) {
  423. $data_arr['result'][0]->icon_type = 3;
  424. } else {
  425. $data_arr['result'][0]->icon_type = 0;
  426. }
  427. //visit,call,testdrive
  428. }
  429. return ($data_arr['nr'] > 0) ? $data_arr['result'][0] : new stdClass();
  430. }
  431. /* /////////////////////////////// ENQUIRY SUBMIT //////////////////////////////////////////////// */
  432. private function enquirysave($parent, $save_level)
  433. {
  434. $smpin = $parent->current_user_data->smpin; //p_mspin
  435. $dealer_code = $parent->current_user_data->dealer_code; //p_mspin
  436. switch ($save_level) {
  437. case '1':
  438. $REQUEST_KEYS = array('buyer_type' => 'string', 'title' => 'string', 'first_name' => 'string', 'company' => 'string');
  439. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  440. $id = escape_str($parent->_request['id']);
  441. $edit = 0;
  442. $econd = '';
  443. //CHECK EXITS
  444. if ($id != '') {
  445. $edit = 1;
  446. }
  447. if ($edit == 1) {
  448. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id", " smpin='" . $smpin . "' AND id='" . $id . "' AND is_starapp=1 AND is_dms=0 AND is_deleted=0 ", "1");
  449. if ($check_arr['nr'] == 0) {
  450. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  451. }
  452. $econd = " AND id!='" . $id . "'";
  453. }
  454. //CHECK ALREDY EXIST
  455. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id", "smpin='" . $smpin . "' " . $econd . " AND is_starapp=1 AND is_dms=0 AND is_deleted=0 ", "1");
  456. if ($check_arr['nr'] > 0) {
  457. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error7']), 406);
  458. }
  459. $buyer_type = escape_str($parent->_request['buyer_type']); //buyer_type
  460. $title = escape_str($parent->_request['title']); //p_title
  461. $first_name = escape_str($parent->_request['first_name']); //fname
  462. $middle_name = escape_str($parent->_request['middle_name']); //mid_name
  463. $last_name = escape_str($parent->_request['last_name']); //l_name
  464. $gender = ($parent->_request['gender']) ? escape_str($parent->_request['gender']) : ""; //gender
  465. $email = escape_str($parent->_request['email']); //p_email
  466. if ($email != '') {
  467. if (!globalfunc::isValidEmail($email)) {
  468. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error12']), 406);
  469. }
  470. }
  471. $address1 = escape_str($parent->_request['address1']); //address1
  472. $address1 = str_replace(array("\n", "\r"), ' ', $address1);
  473. $address2 = escape_str($parent->_request['address2']); //address2
  474. $address3 = escape_str($parent->_request['address3']); //address3
  475. $city = escape_str($parent->_request['city']); //city
  476. $state = escape_str($parent->_request['state']); //state
  477. //GET DEALER
  478. $getdealerarr = $parent->selectQuery(DMS_DEALER, "city_cd,state_cd", "dealer_code='" . $parent->current_user_data->dealer_code . "' ", "1");
  479. if ($getdealerarr['nr'] > 0) {
  480. $city = ($getdealerarr['result'][0]->city_cd != '') ? $getdealerarr['result'][0]->city_cd : '';
  481. $state = ($getdealerarr['result'][0]->state_cd != '') ? $getdealerarr['result'][0]->state_cd : '';
  482. }
  483. $company = escape_str($parent->_request['company']); //p_work_place_id
  484. $work_place_name = escape_str($parent->_request['work_place_name']); //p_work_place_name
  485. if ($edit == 0) {
  486. $parent->executeQuery("INSERT INTO `" . DMS_ENQUIRY_MASTER . "` ( smpin, dealer_code, `buyer_type`, `title`, `first_name`, `middle_name`, `last_name`, `ind_sex`, `email`, `address1`, `address2`, `address3`, `city`, `state`, `company`, `work_place_name`,save_level,is_dms,is_starapp ,`created_on`, `modified_on`) VALUES ('" . $smpin . "','" . $dealer_code . "','" . $buyer_type . "','" . $title . "','" . $first_name . "','" . $middle_name . "','" . $last_name . "','" . $gender . "','" . $email . "','" . $address1 . "','" . $address2 . "','" . $address3 . "','" . $city . "', '" . $state . "','" . $company . "','" . $work_place_name . "',1,0,1,'" . NOW . "', '" . NOW . "')");
  487. $id = $parent->lastInsertId();
  488. } else {
  489. $parent->executeQuery("UPDATE `" . DMS_ENQUIRY_MASTER . "` SET dealer_code='" . $dealer_code . "', `buyer_type`='" . $buyer_type . "', `title`='" . $title . "', `first_name`='" . $first_name . "', `middle_name`='" . $middle_name . "', `last_name`='" . $last_name . "', `ind_sex`='" . $gender . "', `email`='" . $email . "', `address1`='" . $address1 . "', `address2`='" . $address2 . "', `address3`='" . $address3 . "', `city`='" . $city . "', `state`='" . $state . "', `company`='" . $company . "', `work_place_name`='" . $work_place_name . "' WHERE id='" . $id . "'");
  490. }
  491. //GET DATA
  492. $data_arr = $this->getEnquirydata($parent, $id);
  493. //LOG
  494. $logstr = 'ENQUIRY SAVE LEVEL 1';
  495. globalfunc::insertUserLog($parent, $logstr, $id);
  496. $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
  497. break;
  498. case '2':
  499. $REQUEST_KEYS = array('id' => 'number', 'mobile' => 'number', 'communicate' => 'string', 'model1' => 'string', 'variant1' => 'string', 'color1' => 'string');
  500. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  501. $id = escape_str($parent->_request['id']);
  502. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id,save_level", " id='" . $id . "' AND save_level>=1 AND smpin='" . $smpin . "' AND is_starapp=1 AND is_dms=0 AND is_deleted=0", "1");
  503. if ($check_arr['nr'] != 1) {
  504. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error8']), 406);
  505. }
  506. $query_arr = $parent->selectQuery(TABLE_ENQUIRY_OTP, "*", " smpin='" . $smpin . "' AND mobile='" . $mobile . "' AND is_checked=0 ORDER BY id DESC", "1");
  507. if ($query_arr['nr'] > 0) {
  508. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error9']), 406);
  509. }
  510. $mobile = escape_str($parent->_request['mobile']); //mobile_no
  511. $communicate = escape_str($parent->_request['communicate']); //mod_of_com
  512. $model1 = escape_str($parent->_request['model1']); //model
  513. $variant1 = escape_str($parent->_request['variant1']); //variant
  514. $color1 = escape_str($parent->_request['color1']); //colour
  515. //IF ONLY Level one need to update
  516. if ($check_arr['result'][0]->save_level == 1) {
  517. $updcond = ",save_level='2'";
  518. }
  519. $parent->executeQuery("UPDATE `" . DMS_ENQUIRY_MASTER . "` SET mobile='" . $mobile . "',`model1`='" . $model1 . "', `variant1`='" . $variant1 . "', `color1`='" . $color1 . "',`communicate`='" . $communicate . "' " . $updcond . " WHERE id='" . $id . "'");
  520. //GET DATA
  521. $data_arr = $this->getEnquirydata($parent, $id);
  522. //LOG
  523. $logstr = 'ENQUIRY SAVE LEVEL 2';
  524. globalfunc::insertUserLog($parent, $logstr, $id);
  525. $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
  526. break;
  527. case '3':
  528. $REQUEST_KEYS = array('id' => 'number', 'source' => 'string', 'profession' => 'string', 'custtype' => 'string', 'custage' => 'string');
  529. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  530. $id = escape_str($parent->_request['id']);
  531. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id,save_level", " id='" . $id . "' AND save_level>=2 AND smpin='" . $smpin . "' AND is_starapp=1 AND is_dms=0 AND is_deleted=0", "1");
  532. if ($check_arr['nr'] != 1) {
  533. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error8']), 406);
  534. }
  535. $source = escape_str($parent->_request['source']); //enq_soruce
  536. $profession = escape_str($parent->_request['profession']); //occupation
  537. $custtype = escape_str($parent->_request['custtype']); //cust_type
  538. $custage = escape_str($parent->_request['custage']); //p_cust_age_group
  539. if ($check_arr['result'][0]->save_level == 2) {
  540. $updcond = ",save_level='3'";
  541. }
  542. $parent->executeQuery("UPDATE `" . DMS_ENQUIRY_MASTER . "` SET `source`='" . $source . "', `profession`='" . $profession . "', `custtype`='" . $custtype . "', `custage`='" . $custage . "' " . $updcond . " WHERE id='" . $id . "'");
  543. //GET DATA
  544. $data_arr = $this->getEnquirydata($parent, $id);
  545. //LOG
  546. $logstr = 'ENQUIRY SAVE LEVEL 3';
  547. globalfunc::insertUserLog($parent, $logstr, $id);
  548. $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
  549. break;
  550. default:
  551. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error10']), 406);
  552. break;
  553. }
  554. }
  555. /* /////////////////////////////// ENQUIRY SUBMIT //////////////////////////////////////////////// */
  556. private function enquirysubmit($parent)
  557. {
  558. globalfunc::checkParamCount($parent, 0);
  559. globalfunc::checkMethodType($parent, array('POST'));
  560. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  561. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  562. $id = escape_str($parent->_request['id']);
  563. $save_level = escape_str($parent->_request['save_level']);
  564. $dealer_code = $parent->current_user_data->dealer_code; //dealer
  565. $dealer_arr = $parent->selectQuery(DMS_DEALER, "*", "is_enquirymodule=1 AND dealer_code='" . $dealer_code . "'", "1");
  566. if (!$dealer_arr['nr'] > 0) {
  567. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error22']), 406);
  568. }
  569. $smpin = $parent->current_user_data->smpin; //p_mspin
  570. //$dealer_code = $parent->current_user_data->dealer_code; //p_mspin
  571. $is_edit = 0;
  572. switch ($save_level) {
  573. case '1':
  574. case '2':
  575. case '3':
  576. $is_edit = 1; //FOR SAVE
  577. $this->enquirysave($parent, $save_level);
  578. break;
  579. case '4': //final level submit
  580. $REQUEST_KEYS = array('id' => 'number', 'newvechicledate' => 'date|d-m-Y', 'newvechicletime' => 'string', 'newvechicletactionplan' => 'string', 'newvechicletpurpose' => 'string');
  581. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  582. // $check_arr=$parent->selectQuery(DMS_ENQUIRY_MASTER ,"id","save_level>=3 AND smpin='".$smpin."' AND is_starapp=1 AND is_dms=0 AND is_deleted=0","1");
  583. // if($check_arr['nr']>0) $parent->response(array('response'=>'failed','message'=>$this->page_data['error7']),406);
  584. $is_edit = 1;
  585. $is_submit = escape_str($parent->_request['is_submit']);
  586. $is_submit = ($is_submit == '1') ? 1 : 0;
  587. break;
  588. default: //do nothing //DIRECT SUBMIT
  589. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id", "save_level<=4 AND smpin='" . $smpin . "' AND is_dms=0 AND is_deleted=0", "1");
  590. $update_str = "UPDATE " . DMS_ENQUIRY_MASTER . " SET is_deleted=1 ,`modified_on`='" . NOW . "' WHERE smpin='" . $smpin . "' AND id='" . $check_arr['result'][0]->id . "'";
  591. $parent->executeQuery($update_str);
  592. $REQUEST_KEYS = array('title' => 'string', 'first_name' => 'string', 'company' => 'string', 'communicate' => 'string', 'newvechicledate' => 'date|d-m-Y', 'newvechicletime' => 'string', 'custage' => 'string');
  593. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  594. break;
  595. }
  596. $enq_salesman_cd = '';
  597. $p_enq = '';
  598. $mobile = escape_str($parent->_request['mobile']); //mobile_no
  599. if ($is_edit == 0) {
  600. $query_arr = $parent->selectQuery(TABLE_ENQUIRY_OTP, "*", " smpin='" . $smpin . "' AND mobile='" . $mobile . "' ORDER BY id DESC", "1");
  601. if ($query_arr['nr'] == 0 || (isset($query_arr['result'][0]) && $query_arr['result'][0]->is_checked == 0)) {
  602. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error9']), 406);
  603. }
  604. }
  605. $newvechicletactionplan = escape_str($parent->_request['newvechicletactionplan']); //p_action
  606. $first_name = escape_str($parent->_request['first_name']); //fname
  607. $middle_name = escape_str($parent->_request['middle_name']); //mid_name
  608. $last_name = escape_str($parent->_request['last_name']); //l_name
  609. $gender = ($parent->_request['gender']) ? escape_str($parent->_request['gender']) : ""; //gender
  610. $profession = escape_str($parent->_request['profession']); //occupation
  611. $email = escape_str($parent->_request['email']); //p_email
  612. if ($is_edit == 0 && $email != '') {
  613. if (!globalfunc::isValidEmail($email)) {
  614. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error12']), 406);
  615. }
  616. }
  617. $address1 = escape_str($parent->_request['address1']); //address1
  618. $address1 = str_replace(array("\n", "\r"), ' ', $address1);
  619. $address2 = escape_str($parent->_request['address2']); //address2
  620. $address3 = escape_str($parent->_request['address3']); //address3
  621. $city = escape_str($parent->_request['city']); //city
  622. $state = escape_str($parent->_request['state']); //state
  623. //GET DEALER
  624. $getdealerarr = $parent->selectQuery(DMS_DEALER, "city_cd,state_cd", "dealer_code='" . $parent->current_user_data->dealer_code . "' ", "1");
  625. if ($getdealerarr['nr'] > 0) {
  626. $city = ($getdealerarr['result'][0]->city_cd != '') ? $getdealerarr['result'][0]->city_cd : '';
  627. $state = ($getdealerarr['result'][0]->state_cd != '') ? $getdealerarr['result'][0]->state_cd : '';
  628. }
  629. $ofc_address1 = escape_str($parent->_request['ofc_address1']); //ofc_address1
  630. $ofc_address2 = escape_str($parent->_request['ofc_address2']); //ofc_address2
  631. $ofc_address3 = escape_str($parent->_request['ofc_address3']); //ofc_address3
  632. $ofc_city = escape_str($parent->_request['ofc_city']); //ofc_city
  633. $ofc_state = escape_str($parent->_request['ofc_state']); //ofc_state
  634. $model1 = escape_str($parent->_request['model1']); //model
  635. $variant1 = escape_str($parent->_request['variant1']); //variant
  636. $color1 = escape_str($parent->_request['color1']); //colour
  637. $communicate = escape_str($parent->_request['communicate']); //mod_of_com
  638. $modeofcontact = $newvechicletactionplan;
  639. $custtype = escape_str($parent->_request['custtype']); //cust_type
  640. $buyer_type = escape_str($parent->_request['buyer_type']); //buyer_type
  641. //$lik_pur_days=escape_str($parent->_request['lik_pur_days']); //lik_pur_days
  642. $lik_pur_days = '0';
  643. $source = escape_str($parent->_request['source']); //enq_soruce
  644. $model_cd = '';
  645. $variant_cd = '';
  646. $newvechicledate_str = escape_str($parent->_request['newvechicledate']);
  647. $newvechicletime = escape_str($parent->_request['newvechicletime']);
  648. $date_arr = @explode('-', $newvechicledate_str);
  649. $date_str = $date_arr[2] . "-" . $date_arr[1] . "-" . $date_arr[0];
  650. $newvechicledatatime = $date_str . " " . $newvechicletime;
  651. $p_pmc = '2';
  652. $title = escape_str($parent->_request['title']); //p_title
  653. $company = escape_str($parent->_request['company']); //p_work_place_id
  654. $work_place_name = escape_str($parent->_request['work_place_name']); //p_work_place_name
  655. $enquiry_stage = escape_str($parent->_request['newvechicletpurpose']); //p_stage
  656. $oldvechicledate = '';
  657. $oldvechicletime = '';
  658. $oldvechicletactionplan = '';
  659. $oldvechicletpurpose = '';
  660. // $oldvechicledate=escape_str($parent->_request['oldvechicledate']);
  661. // $oldvechicletime=escape_str($parent->_request['oldvechicletime']);
  662. // $oldvechicletactionplan=escape_str($parent->_request['oldvechicletactionplan']);
  663. // $oldvechicletpurpose=escape_str($parent->_request['oldvechicletpurpose']);
  664. $model2 = escape_str($parent->_request['model2']);
  665. $variant2 = escape_str($parent->_request['variant2']);
  666. $color2 = escape_str($parent->_request['color2']);
  667. $oldvechiclemaker = escape_str($parent->_request['oldvechiclemaker']);
  668. $oldvechiclemodel = escape_str($parent->_request['oldvechiclemodel']);
  669. $custage = escape_str($parent->_request['custage']); //p_cust_age_group
  670. $p_eval_code = escape_str($parent->_request['p_eval_code']);
  671. $p_old_car_make = escape_str($parent->_request['p_old_car_make']);
  672. $p_old_car_model = escape_str($parent->_request['p_old_car_model']);
  673. $p_old_car_submodel = escape_str($parent->_request['p_old_car_submodel']);
  674. $p_ad_cd = escape_str($parent->_request['p_ad_cd']);
  675. $p_event_cd = escape_str($parent->_request['p_event_cd']);
  676. $p_enq_ref_mode = escape_str($parent->_request['p_enq_ref_mode']);
  677. $p_referred_by = escape_str($parent->_request['p_referred_by']);
  678. $is_testride = '0';
  679. $license = escape_str($parent->_request['license']);
  680. $license_expiry = escape_str($parent->_request['license_expiry']);
  681. if ($license_expiry != '' || $license != '') {
  682. $REQUEST_KEYS = array('license' => 'string', 'license_expiry' => 'date|d-m-Y');
  683. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  684. $is_testride = '1';
  685. $ldate_arr = @explode('-', $license_expiry);
  686. $ldate_str = $ldate_arr[2] . "-" . $ldate_arr[1] . "-" . $ldate_arr[0];
  687. $license_expiry = $ldate_str;
  688. }
  689. $status = "H"; //p_statusid
  690. $date1 = new DateTime(CUR_DATE);
  691. $date2 = $date1->diff(new DateTime($date_str));
  692. $diff_days = $date2->days;
  693. if ($diff_days <= 7) {
  694. $status = "H"; //HOT
  695. } elseif ($diff_days > 7 && $diff_days <= 21) {
  696. $status = "W"; //WARM
  697. } elseif ($diff_days > 21) {
  698. $status = "P"; //COLD
  699. }
  700. $p_km_drive_month = escape_str($parent->_request['p_km_drive_month']);
  701. $p_mode_of_purchase = escape_str($parent->_request['p_mode_of_purchase']);
  702. $p_any_other_car = escape_str($parent->_request['p_any_other_car']);
  703. $p_ref_type = escape_str($parent->_request['p_ref_type']);
  704. $p_ref_no = escape_str($parent->_request['p_ref_no']);
  705. $p_ref_phone_no = escape_str($parent->_request['p_ref_phone_no']);
  706. $leadid = 'starenq' . uniqid(); //p_transaction_id
  707. //FOR SAVE
  708. if ($is_edit == 1) {
  709. if ($is_submit == 0) {
  710. $parent->executeQuery("UPDATE `" . DMS_ENQUIRY_MASTER . "` SET newvechicledate='" . $date_str . "',newvechicletime='" . $newvechicletime . "',newvechicledatatime='" . $newvechicledatatime . "',newvechicletactionplan='" . $newvechicletactionplan . "',modeofcontact='" . $modeofcontact . "',enquiry_stage='" . $enquiry_stage . "',save_level='" . $save_level . "',license='" . $license . "',license_expiry='" . $license_expiry . "',is_testride='" . $is_testride . "' WHERE id='" . $id . "'");
  711. $data_arr = $this->getEnquirydata($parent, $id);
  712. //LOG
  713. $logstr = 'ENQUIRY SAVE LEVEL 4';
  714. globalfunc::insertUserLog($parent, $logstr);
  715. $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
  716. } else {
  717. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "*", "id='" . $id . "' AND smpin='" . $smpin . "' AND is_dms=0 AND is_deleted=0", "1");
  718. if ($check_arr['nr'] != 1) {
  719. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  720. }
  721. $first_name = $check_arr['result'][0]->first_name;
  722. $middle_name = $check_arr['result'][0]->middle_name;
  723. $last_name = $check_arr['result'][0]->last_name;
  724. $gender = $check_arr['result'][0]->ind_sex;
  725. $profession = $check_arr['result'][0]->profession;
  726. $p_email = $check_arr['result'][0]->email;
  727. $mobile = $check_arr['result'][0]->mobile;
  728. $address1 = $check_arr['result'][0]->address1;
  729. $address2 = $check_arr['result'][0]->address2;
  730. $address3 = $check_arr['result'][0]->address3;
  731. $ofc_address1 = $check_arr['result'][0]->ofc_address1;
  732. $ofc_address2 = $check_arr['result'][0]->ofc_address2;
  733. $ofc_address3 = $check_arr['result'][0]->ofc_address3;
  734. $ofc_city = $check_arr['result'][0]->ofc_city;
  735. $ofc_state = $check_arr['result'][0]->ofc_state;
  736. $model1 = $check_arr['result'][0]->model1;
  737. $variant1 = $check_arr['result'][0]->variant1;
  738. $color1 = $check_arr['result'][0]->color1;
  739. $communicate = $check_arr['result'][0]->communicate;
  740. //$modeofcontact=$check_arr['result'][0]->modeofcontact;
  741. $custtype = $check_arr['result'][0]->custtype;
  742. $buyer_type = $check_arr['result'][0]->buyer_type;
  743. $source = $check_arr['result'][0]->source;
  744. $company = $check_arr['result'][0]->company;
  745. $work_place_name = $check_arr['result'][0]->work_place_name;
  746. $title = $check_arr['result'][0]->title;
  747. $custage = $check_arr['result'][0]->custage;
  748. }
  749. }
  750. //CALL DMS ORACLE
  751. $url = SUZ_DMS_URL;
  752. $enq_soruce = $source;
  753. $post = array("query" => "BEGIN pkg_smipl_star_app.sp_enq(:p_mspin, :p_enq, :p_action, :p_stage, :fname, :mid_name, :l_name, :mobile_no, :gender, :occupation, :p_email, :address1, :address2, :address3, :city, :state, :ofc_address1, :ofc_address2, :ofc_address3, :ofc_city, :ofc_state, :model, :variant, :colour, :mod_of_com, :cust_type, :buyer_type, :lik_pur_days, :enq_soruce, :model_cd, :variant_cd, :next_follwowup_date, :p_pmc, :p_work_place_id, :p_work_place_name, :p_transaction_id, :p_eval_code, :p_old_car_make, :p_old_car_model, :p_old_car_submodel, :p_ad_cd, :p_event_cd, :p_enq_ref_mode, :p_referred_by, :p_statusid, :p_km_drive_month, :p_mode_of_purchase, :p_any_other_car, :p_ref_type, :p_ref_no, :p_ref_phone_no, :p_title, :p_village, :p_tehsil, :p_district, :p_pin, :p_ofc_village, :p_ofc_tehsil, :p_ofc_district, :p_ofc_pin, :p_cust_age_group, :enq_number, :p_err_msg, :p_error); END;", "params" => '[{"title":"p_mspin","value":"' . $smpin . '","type":""},{"title":"p_enq","value":"' . $p_enq . '","type":""},{"title":"p_action","value":"' . $newvechicletactionplan . '","type":""},{"title":"p_stage","value":"' . $enquiry_stage . '","type":""},{"title":"fname","value":"' . $first_name . '","type":""},{"title":"mid_name","value":"' . $middle_name . '","type":""},{"title":"l_name","value":"' . $last_name . '","type":""},{"title":"mobile_no","value":"' . $mobile . '","type":""},{"title":"gender","value":"' . $gender . '","type":""},{"title":"occupation","value":"' . $profession . '","type":""},{"title":"p_email","value":"' . $email . '","type":""},{"title":"address1","value":"' . $address1 . '"},{"title":"address2","value":"' . $address2 . '","type":""},{"title":"address3","value":"' . $address3 . '","type":""},{"title":"city","value":"' . $city . '","type":""},{"title":"state","value":"' . $state . '","type":""},{"title":"ofc_address1","value":"' . $ofc_address1 . '","type":""},{"title":"ofc_address2","value":"' . $ofc_address2 . '","type":""},{"title":"ofc_address3","value":"' . $ofc_address3 . '","type":""},{"title":"ofc_city","value":"' . $ofc_city . '","type":""},{"title":"ofc_state","value":"' . $ofc_state . '","type":""},{"title":"model","value":"' . $model1 . '","type":""},{"title":"variant","value":"' . $variant1 . '","type":""},{"title":"colour","value":"' . $color1 . '","type":""},{"title":"mod_of_com","value":"' . $communicate . '","type":""},{"title":"cust_type","value":"' . $custtype . '","type":""},{"title":"buyer_type","value":"' . $buyer_type . '","type":""},{"title":"lik_pur_days","value":"' . $lik_pur_days . '","type":""},{"title":"enq_soruce","value":"' . $enq_soruce . '","type":""},{"title":"model_cd","value":"' . $model_cd . '","type":""},{"title":"variant_cd","value":"' . $variant_cd . '","type":""},{"title":"next_follwowup_date","value":"' . date('d-M-Y', strtotime($newvechicledatatime)) . '","type":""},{"title":"p_pmc","value":2,"type":""},{"title":"p_work_place_id","value":"' . $company . '","type":""},{"title":"p_work_place_name","value":"' . $work_place_name . '","type":""},{"title":"p_transaction_id","value":"' . $leadid . '","type":""},{"title":"p_eval_code","value":"' . $p_eval_code . '","type":""},{"title":"p_old_car_make","value":"' . $p_old_car_make . '","type":""},{"title":"p_old_car_model","value":"' . $p_old_car_model . '","type":""},{"title":"p_old_car_submodel","value":"' . $p_old_car_submodel . '","type":""},{"title":"p_ad_cd","value":"' . $p_ad_cd . '","type":""},{"title":"p_event_cd","value":"' . $p_event_cd . '","type":""},{"title":"p_enq_ref_mode","value":"' . $p_enq_ref_mode . '","type":""},{"title":"p_referred_by","value":"' . $p_referred_by . '","type":""},{"title":"p_statusid","value":"' . $status . '","type":""},{"title":"p_km_drive_month","value":"' . $p_km_drive_month . '","type":""},{"title":"p_mode_of_purchase","value":"' . $p_mode_of_purchase . '","type":""},{"title":"p_any_other_car","value":"' . $p_any_other_car . '","type":""},{"title":"p_ref_type","value":"' . $p_ref_type . '","type":""},{"title":"p_ref_no","value":"' . $p_ref_no . '","type":""},{"title":"p_ref_phone_no","value":"' . $p_ref_phone_no . '","type":""},{"title":"p_title","value":"' . $title . '","type":""},{"title":"p_village","value":"' . $p_village . '","type":""},{"title":"p_tehsil","value":"' . $p_tehsil . '","type":""},{"title":"p_district","value":"' . $p_district . '","type":""},{"title":"p_pin","value":"' . $p_pin . '","type":""},{"title":"p_ofc_village","value":"' . $p_ofc_village . '","type":""},{"title":"p_ofc_tehsil","value":"' . $p_ofc_tehsil . '","type":""},{"title":"p_ofc_district","value":"' . $p_ofc_district . '","type":""},{"title":"p_ofc_pin","value":"' . $p_ofc_pin . '","type":""},{"title":"p_cust_age_group","value":"' . $custage . '","type":""},{"title":"enq_number","value":"","type":"string","length":200},{"title":"p_err_msg","value":"","type":"string","length":1000},{"title":"p_error","value":"","type":"string","length":200}]');
  754. //print_r($post);exit();
  755. //LOG
  756. $obj = new stdClass();
  757. $obj->type = 'enqsubmit';
  758. $obj->apirequest = $post['params'];
  759. $log_id = projectfunc::cronLog($parent, $obj);
  760. $header = array('Authorization:Bearer ' . SUZ_TOKEN);
  761. // $ch = curl_init();
  762. // curl_setopt($ch, CURLOPT_URL, $url);
  763. // curl_setopt($ch, CURLOPT_POST, 1);
  764. // curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //Post Fields
  765. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  766. // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  767. // $response = curl_exec($ch);
  768. // $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  769. // curl_close($ch);
  770. $httpcode = '200';
  771. $response="";
  772. $error = 1;
  773. $count = 0;
  774. $emsg = '';
  775. //REPSONSE SAVE
  776. $obj = new stdClass();
  777. $obj->id = $log_id;
  778. $obj->apiresponse = $response;
  779. projectfunc::updateCronLog($parent, $obj);
  780. if ($httpcode == '200' && $response != '') {
  781. $json = json_decode($response);
  782. if (isset($json->response) && $json->response == 'success' && isset($json->data) && isset($json->data->enq_number) && $json->data->enq_number != '') {
  783. $error = 0;
  784. if ($is_edit == 0) {
  785. $parent->executeQuery("INSERT INTO `" . DMS_ENQUIRY_MASTER . "` ( transaction_id, `enq_salesman_cd`, `smpin`, dealer_code, `mobile`, `email`, `buyer_type`, `title`, `first_name`, `middle_name`, `last_name`, `ind_sex`, `address1`, `address2`, `address3`, `city`, `state`, `ofc_address1`, `ofc_address2`, `ofc_address3`, `ofc_city`, `ofc_state`, `company`, `work_place_name`, `communicate`, `newvechicledate`, `newvechicletime`, `newvechicledatatime`, `newvechicletactionplan`,`model1`, `variant1`, `color1`, `profession`, `source`, `custtype`, `custage`, `modeofcontact`, `enquiry_stage`, `lik_pur_days`,license,license_expiry,is_testride , `status`,save_level, is_dms, is_starapp, `created_on`, `modified_on`) VALUES ('" . $leadid . "','" . $enq_salesman_cd . "','" . $smpin . "','" . $dealer_code . "', '" . $mobile . "','" . $email . "','" . $buyer_type . "','" . $title . "','" . $first_name . "','" . $middle_name . "','" . $last_name . "','" . $gender . "','" . $address1 . "','" . $address2 . "','" . $address3 . "','" . $city . "', '" . $state . "','" . $ofc_address1 . "','" . $ofc_address2 . "', '" . $ofc_address3 . "', '" . $ofc_city . "', '" . $ofc_state . "','" . $company . "','" . $work_place_name . "','" . $communicate . "','" . $date_str . "','" . $newvechicletime . "','" . $newvechicledatatime . "','" . $newvechicletactionplan . "', '" . $model1 . "','" . $variant1 . "','" . $color1 . "','" . $profession . "','" . $source . "','" . $custtype . "','" . $custage . "','" . $modeofcontact . "','" . $enquiry_stage . "','" . $lik_pur_days . "','" . $license . "','" . $license_expiry . "','" . $is_testride . "','" . $status . "',4 ,1 ,1,'" . NOW . "', '" . NOW . "')");
  786. $id = $parent->lastInsertId();
  787. } else {
  788. //'id'=>'number','newvechicledate'=>'string','newvechicletime'=>'string','newvechicletactionplan'=>'string','newvechicletpurpose'=>'string'
  789. $parent->executeQuery("UPDATE `" . DMS_ENQUIRY_MASTER . "` SET dealer_code='" . $dealer_code . "',transaction_id='" . $leadid . "',`city`='" . $city . "', `state`='" . $state . "',newvechicledate='" . $date_str . "',newvechicletime='" . $newvechicletime . "',newvechicledatatime='" . $newvechicledatatime . "',modeofcontact='" . $modeofcontact . "',newvechicletactionplan='" . $newvechicletactionplan . "',enquiry_stage='" . $enquiry_stage . "',lik_pur_days='" . $lik_pur_days . "',license='" . $license . "',license_expiry='" . $license_expiry . "',is_testride='" . $is_testride . "', `status`='" . $status . "',save_level='" . $save_level . "',is_dms='1' WHERE id='" . $id . "'");
  790. }
  791. $parent->executeQuery("UPDATE " . DMS_ENQUIRY_MASTER . " SET enq_num='" . $json->data->enq_number . "' WHERE id='" . $id . "'");
  792. //$data_arr=$parent->selectQuery(DMS_ENQUIRY_MASTER ,"*","id='".$id."'","1");
  793. $data_arr = $this->getEnquirydata($parent, $id);
  794. //LOG UPDATE
  795. $obj = new stdClass();
  796. $obj->id = $log_id;
  797. $obj->insert_count = 1;
  798. $obj->status = 1;
  799. //$obj->apiresponse=$response;
  800. projectfunc::updateCronLog($parent, $obj);
  801. //LOG
  802. $logstr = 'ENQUIRY SUBMIT';
  803. globalfunc::insertUserLog($parent, $logstr);
  804. $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
  805. }
  806. if ($json->response == 'success' && $json->data->p_err_msg != '') {
  807. $emsg = $json->data->p_err_msg;
  808. }
  809. }
  810. if ($error == 1) {
  811. $emsg = ($emsg != '') ? $emsg : "Error to connect DMS. Please try after sometime";
  812. $parent->response(array('response' => 'failed', 'message' => $emsg), 406);
  813. }
  814. }
  815. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  816. /* /////////////////////////////// DASHBOARD //////////////////////////////////////////////// */
  817. private function dashboard($parent)
  818. {
  819. globalfunc::checkMethodType($parent, array('GET'));
  820. globalfunc::checkParamCount($parent, 1);
  821. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  822. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  823. $smpin = $parent->current_user_data->smpin;
  824. //TODAY ENQUIRY MASTER
  825. //VISIT
  826. $today_visit_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND DATE(newvechicledatatime)= '" . CUR_DATE . "' AND modeofcontact IN ('S','V') AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  827. //TESTRIDE
  828. $today_testride_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND DATE(newvechicledatatime)= '" . CUR_DATE . "' AND enquiry_stage='T' AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  829. //CALL
  830. $today_call_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND DATE(newvechicledatatime)= '" . CUR_DATE . "' AND modeofcontact IN ('E','F','O','T') AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  831. $today_visit = $today_visit_arr['result'][0]->data_count;
  832. $today_testride = $today_testride_arr['result'][0]->data_count;
  833. $today_call = $today_call_arr['result'][0]->data_count;
  834. //pending task last 10 days only
  835. $last_ten_date = date('Y-m-d', strtotime('-10 day', strtotime(NOW)));
  836. //PENDING ENQUIRY MASTER
  837. $pending_visit_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND newvechicledatatime<'" . CUR_DATE . " 00:00:00' AND newvechicledatatime>'" . $last_ten_date . " 00:00:00' AND modeofcontact IN ('S','V') AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  838. $pending_testride_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND newvechicledatatime<'" . CUR_DATE . " 00:00:00' AND newvechicledatatime>'" . $last_ten_date . " 00:00:00' AND enquiry_stage='T' AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  839. $pending_call_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND newvechicledatatime<'" . CUR_DATE . " 00:00:00' AND newvechicledatatime>'" . $last_ten_date . " 00:00:00' AND modeofcontact IN ('E','F','O','T') AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  840. $pending_visit = $pending_visit_arr['result'][0]->data_count;
  841. $pending_testride = $pending_testride_arr['result'][0]->data_count;
  842. $pending_call = $pending_call_arr['result'][0]->data_count;
  843. //TOMORROW ENQUIRY MASTER
  844. $tomorrow_date = date('Y-m-d', strtotime('+1 day', strtotime(NOW)));
  845. //VISIT
  846. $tomorrow_visit_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND DATE(newvechicledatatime)= '" . $tomorrow_date . "' AND modeofcontact IN ('S','V') AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  847. //TESTRIDE
  848. $tomorrow_testride_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND DATE(newvechicledatatime)= '" . $tomorrow_date . "' AND enquiry_stage='T' AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  849. //CALL
  850. $tomorrow_call_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND DATE(newvechicledatatime)= '" . $tomorrow_date . "' AND modeofcontact IN ('E','F','O','T') AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  851. $tomorrow_visit = $tomorrow_visit_arr['result'][0]->data_count;
  852. $tomorrow_testride = $tomorrow_testride_arr['result'][0]->data_count;
  853. $tomorrow_call = $tomorrow_call_arr['result'][0]->data_count;
  854. $today = array('visit' => $today_visit, 'testride' => $today_testride, 'call' => $today_call);
  855. $pending = array('visit' => $pending_visit, 'testride' => $pending_testride, 'call' => $pending_call);
  856. $tomorrow = array('visit' => $tomorrow_visit, 'testride' => $tomorrow_testride, 'call' => $tomorrow_call);
  857. $data = array('today' => $today, 'pending' => $pending, 'tomorrow' => $tomorrow);
  858. //LOG
  859. $logstr = 'ENQUIRY DASHBOARD';
  860. globalfunc::insertUserLog($parent, $logstr);
  861. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success1']), 200);
  862. }
  863. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  864. /* /////////////////////////////// DASHBOARD SALES //////////////////////////////////////////////// */
  865. private function enquirysales($parent)
  866. {
  867. //sales/2018/2
  868. globalfunc::checkMethodType($parent, array('GET'));
  869. globalfunc::checkParamCount($parent, 3);
  870. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  871. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  872. $year_data = escape_str($parent->params[1]);
  873. $last_data = escape_str($parent->params[2]);
  874. $last_data_arr = explode('?', $last_data);
  875. $month_data = escape_str(trim($last_data_arr[0]));
  876. $smpin = $parent->current_user_data->smpin;
  877. //*****************SALES****************
  878. //TARGET
  879. $user_target = projectfunc::userSalesTarget($parent, $parent->current_user_id, '', $year_data, $month_data);
  880. //ACHIEVED
  881. $user_achieved = projectfunc::userSalesAchieved($parent, $parent->current_user_id, '', $year_data, $month_data);
  882. $sales = array('target' => $user_target, 'achieved' => $user_achieved, 'month' => date('M', strtotime('2018-' . $month_data . "-01")), 'year' => $year_data);
  883. //****************ENQUIRY****************
  884. $achieved_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%' AND is_dms=1 AND is_deleted=0", "1");
  885. switch ($parent->current_user_data->segment) {
  886. case '1': //TARGET
  887. $enquiry_target = (string) ($user_target * 5); //SALES TARGET multiple by 5
  888. break;
  889. case '2': //TARGET
  890. $enquiry_target = (string) ($user_target * 3); //SALES TARGET multiple by 3
  891. break;
  892. default:
  893. $enquiry_target = (string) ($user_target * 3); //SALES TARGET multiple by 3
  894. break;
  895. }
  896. //ACHIEVED
  897. $enquiry_achieved = $achieved_arr['result'][0]->data_count;
  898. $enquiry = array('target' => $enquiry_target, 'achieved' => $enquiry_achieved, 'month' => date('M', strtotime('2018-' . $month_data . "-01")), 'year' => $year_data);
  899. //*****************STATUS
  900. $hot_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%' AND status='H' AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  901. $warm_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%' AND status='W' AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  902. $cold_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%' AND status='P' AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')", "1");
  903. $hot = $hot_arr['result'][0]->data_count;
  904. $warm = $warm_arr['result'][0]->data_count;
  905. $cold = $cold_arr['result'][0]->data_count;
  906. $status_arr = array("hot" => $hot, "warm" => $warm, "cold" => $cold);
  907. //*****************STAGE
  908. $testride_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%' AND enquiry_stage='T' AND is_dms=1 AND is_deleted=0 ", "1");
  909. $booked_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%' AND enquiry_stage='O' AND is_dms=1 AND is_deleted=0 ", "1");
  910. $invoiced_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%' AND enquiry_stage IN('Z','P') AND is_dms=1 AND is_deleted=0 ", "1");
  911. $lost_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%' AND status='L' AND is_dms=1 AND is_deleted=0 ", "1");
  912. $postponed_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%' AND status='E' AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V') ", "1");
  913. $delivered_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "COUNT(id) data_count", " smpin='" . $smpin . "' AND created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%' AND enquiry_stage IN ('O','V') AND is_dms=1 AND is_deleted=0 ", "1");
  914. $testride = $testride_arr['result'][0]->data_count;
  915. $booked = $booked_arr['result'][0]->data_count;
  916. $invoiced = $invoiced_arr['result'][0]->data_count;
  917. $lost = $lost_arr['result'][0]->data_count;
  918. $postponed = $postponed_arr['result'][0]->data_count;
  919. $delivered = $delivered_arr['result'][0]->data_count;
  920. $stage_arr = array("testride" => $testride, 'booked' => $booked, 'invoiced' => $invoiced, 'lost' => $lost, 'postponed' => $postponed, 'delivered' => $delivered);
  921. $data = array('enquiry' => $enquiry, 'sales' => $sales, 'status' => $status_arr, 'stage' => $stage_arr);
  922. //LOG
  923. $logstr = 'SALES DASHBOARD';
  924. globalfunc::insertUserLog($parent, $logstr);
  925. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success1']), 200);
  926. }
  927. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  928. /* /////////////////////////////// LIST DATA //////////////////////////////////////////////// */
  929. private function listdata($parent)
  930. {
  931. //sales/2018/2
  932. globalfunc::checkMethodType($parent, array('POST'));
  933. globalfunc::checkParamCount($parent, 1);
  934. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  935. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  936. $smpin = $parent->current_user_data->smpin;
  937. try {
  938. //PAGINATION SETTINGS
  939. $limit_cond = '';
  940. $data_arr = array();
  941. $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
  942. $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';
  943. $REQUEST_KEYS = array('listtype' => 'string');
  944. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  945. $listtype = escape_str($parent->_request['listtype']);
  946. $cond = '';
  947. switch ($listtype) {
  948. case 'today':
  949. $todaytype = escape_str($parent->_request['todaytype']);
  950. if (strtolower($todaytype) == 'visit') {
  951. $cond = " AND e.modeofcontact IN ('S','V') ";
  952. } else if (strtolower($todaytype) == 'test drive') {
  953. $cond = " AND e.enquiry_stage='T'";
  954. } else if (strtolower($todaytype) == 'call') {
  955. $cond = " AND e.modeofcontact IN ('E','F','O','T')";
  956. }
  957. $cond .= " AND enquiry_stage NOT IN ('Z','O','P','V') AND DATE(e.newvechicledatatime)= '" . CUR_DATE . "'";
  958. break;
  959. case 'tomorrow':
  960. $todaytype = escape_str($parent->_request['todaytype']);
  961. if (strtolower($todaytype) == 'visit') {
  962. $cond = " AND e.modeofcontact IN ('S','V') ";
  963. } else if (strtolower($todaytype) == 'test drive') {
  964. $cond = " AND e.enquiry_stage='T'";
  965. } else if (strtolower($todaytype) == 'call') {
  966. $cond = " AND e.modeofcontact IN ('E','F','O','T')";
  967. }
  968. $tomorrow_date = date('Y-m-d', strtotime('+1 day', strtotime(NOW)));
  969. $cond .= " AND enquiry_stage NOT IN ('Z','O','P','V') AND DATE(e.newvechicledatatime)= '" . $tomorrow_date . "'";
  970. break;
  971. case 'date':
  972. $REQUEST_KEYS = array('date' => 'date|Y-m-d');
  973. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  974. $date = escape_str($parent->_request['date']);
  975. $todaytype = escape_str($parent->_request['todaytype']);
  976. if (strtolower($todaytype) == 'visit') {
  977. $cond = " AND e.modeofcontact IN ('S','V') ";
  978. } else if (strtolower($todaytype) == 'test drive') {
  979. $cond = " AND e.enquiry_stage='T'";
  980. } else if (strtolower($todaytype) == 'call') {
  981. $cond = " AND e.modeofcontact IN ('E','F','O','T')";
  982. }
  983. $cond .= " AND enquiry_stage NOT IN ('Z','O','P','V') AND DATE(newvechicledatatime)= '" . $date . "'";
  984. break;
  985. case 'pending':
  986. $REQUEST_KEYS = array('pendingtype' => 'string');
  987. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  988. $pendingtype = escape_str($parent->_request['pendingtype']);
  989. if (strtolower($pendingtype) == 'visit') {
  990. $cond = " AND e.modeofcontact IN ('S','V') ";
  991. } else if (strtolower($pendingtype) == 'test drive') {
  992. $cond = "AND e.enquiry_stage='T'";
  993. } else if (strtolower($pendingtype) == 'call') {
  994. $cond = " AND e.modeofcontact IN ('E','F','O','T')";
  995. }
  996. $last_ten_date = date('Y-m-d', strtotime('-10 day', strtotime(NOW)));
  997. $cond .= " AND enquiry_stage NOT IN ('Z','O','P','V') AND e.newvechicledatatime<'" . CUR_DATE . " 00:00:00' AND newvechicledatatime>'" . $last_ten_date . " 00:00:00'";
  998. //$cond.=(in_array(strtolower($pendingtype),array("visit","test drive","call")))?" AND enquiry_stage='".$pendingtype."'":$parent->response(array('response'=>'failed', 'message' => $this->page_data['error5']), 406);
  999. //$cond.= " AND enquiry_stage='".$pendingtype."'";
  1000. //$cond.= " AND enquiry_stage='".$pendingtype."'";
  1001. break;
  1002. case 'hot':
  1003. case 'warm':
  1004. case 'cold':
  1005. case 'testride':
  1006. case 'booked':
  1007. case 'invoiced':
  1008. case 'lost':
  1009. case 'postponed':
  1010. $REQUEST_KEYS = array('month' => 'string', 'year' => 'string');
  1011. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  1012. $month_data = escape_str($parent->_request['month']);
  1013. $year_data = escape_str($parent->_request['year']);
  1014. if (in_array($listtype, array("hot", "warm", "cold", 'lost', 'postponed'))) {
  1015. switch ($listtype) {
  1016. case 'hot':$listtype_str = 'H';
  1017. break;
  1018. case 'warm':$listtype_str = 'W';
  1019. break;
  1020. case 'cold':$listtype_str = 'P';
  1021. break;
  1022. case 'lost':$listtype_str = 'L';
  1023. break;
  1024. case 'postponed':$listtype_str = 'E';
  1025. break;
  1026. }
  1027. if ($listtype != 'lost') {
  1028. $cond .= " AND enquiry_stage NOT IN ('Z','O','P','V')";
  1029. }
  1030. $cond .= " AND e.status='" . $listtype_str . "'";
  1031. } else {
  1032. // $str=($listtype=='testride')?"T":$listtype;
  1033. switch ($listtype) {
  1034. case 'testride':$str = 'T';
  1035. break;
  1036. case 'booked':$str = 'O';
  1037. break;
  1038. case 'invoiced':$str = 'Z';
  1039. break;
  1040. }
  1041. $cond = " AND e.enquiry_stage='" . $str . "'";
  1042. }
  1043. $cond .= "AND e.created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%'";
  1044. break;
  1045. case 'model':
  1046. $REQUEST_KEYS = array('month' => 'string', 'year' => 'number', 'model' => 'string');
  1047. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  1048. $month_data = escape_str($parent->_request['month']);
  1049. $year_data = escape_str($parent->_request['year']);
  1050. $model = escape_str($parent->_request['model']);
  1051. switch ($model) {
  1052. case 'INTRUDER':$cond .= " AND e.model1='GL'";
  1053. break;
  1054. case 'BURGMAN':$cond .= " AND e.model1='UB125'";
  1055. break;
  1056. case 'ACCESS 125':$cond .= " AND e.model1 IN ('AC','ACZ')";
  1057. break;
  1058. case 'GIXXER 250':$cond .= " AND e.model1 IN ('GSX','GSXSF') AND e.variant1 IN (SELECT variant_code FROM " . DMS_ENQUIRY_MODEL . " WHERE title_code IN ('GSX','GSXSF') AND variant LIKE '%250%')";
  1059. break;
  1060. case 'GIXXER':$cond .= " AND e.model1 IN ('GSX','GSXSF') AND e.variant1 IN (SELECT variant_code FROM " . DMS_ENQUIRY_MODEL . " WHERE title_code IN ('GSX','GSXSF') AND variant NOT LIKE '%250%')";
  1061. break;
  1062. case 'OTHERS':$cond .= " AND e.model1 NOT IN ('GSX','GSXSF','GL','UB125','AC','ACZ')";
  1063. break;
  1064. default:$parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  1065. }
  1066. $cond .= " AND e.created_on LIKE '" . date('Y-m', strtotime($year_data . '-' . $month_data . "-01")) . "-%'";
  1067. break;
  1068. default:$parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  1069. break;
  1070. }
  1071. //SEARCH
  1072. $model_cond = '';
  1073. $search = escape_str($parent->_request['search']);
  1074. if ($search != '') {
  1075. $model = $parent->getQueryValue("SELECT title_code FROM " . DMS_ENQUIRY_MODEL . " WHERE title LIKE '%" . $search . "%'");
  1076. if (count($model) > 0) {
  1077. $model_arr = array_column($model, 'title_code');
  1078. $model_quotes = array_map("quotes_array", $model_arr);
  1079. $model_cond = (count($model_quotes) > 0) ? " OR e.model1 IN (" . @implode(',', $model_quotes) . ")" : '';
  1080. }
  1081. $cond = " AND (e.enq_num LIKE '%" . $search . "%' OR e.first_name LIKE '%" . $search . "%' OR e.mobile LIKE '%" . $search . "%' " . $model_cond . ") ";
  1082. }
  1083. //$pending_testride_arr=$parent->selectQuery(DMS_ENQUIRY_MASTER,"COUNT(id) data_count"," smpin='".$smpin."' AND newvechicledatatime<'".CUR_DATE." 00:00:00' AND enquiry_stage='T' AND is_dms=1 AND is_deleted=0 AND enquiry_stage NOT IN ('Z','O','P','V')","1");
  1084. //echo "smpin='".$smpin."' ".$cond." ORDER BY newvechicledatatime ASC, id DESC ".$limit_cond; exit;
  1085. $data_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER . " e ", "SQL_CALC_FOUND_ROWS e.*", "e.smpin='" . $smpin . "' AND e.is_dms=1 AND e.is_deleted=0 " . $cond . " ORDER BY e.newvechicledatatime ASC, id DESC " . $limit_cond, "");
  1086. $total_arr = $parent->getQueryValue("SELECT FOUND_ROWS() as total_record");
  1087. $total = (count($total_arr) > 0) ? $total_arr[0]->total_record : 0;
  1088. //DATE TO STRING
  1089. if ($data_arr['nr'] > 0) {
  1090. foreach ($data_arr['result'] as $key => $res) {
  1091. //LEFT JOIN ".DMS_ENQUIRY_MODEL." m ON m.title_code=e.model1
  1092. //,m.title as model_name_str
  1093. $model_arr = $parent->selectQuery(DMS_ENQUIRY_MODEL, "title as model_name,variant as variant_name,color as color_name", "title_code='" . $res->model1 . "' AND variant_code='" . $res->variant1 . "' AND color_code='" . $res->color1 . "'", "");
  1094. $data_arr['result'][$key]->model_name = ($model_arr['nr'] > 0) ? $model_arr['result'][0]->model_name : $res->model1;
  1095. $data_arr['result'][$key]->variant_name = ($model_arr['nr'] > 0) ? $model_arr['result'][0]->variant_name : $res->variant1;
  1096. $data_arr['result'][$key]->color_name = ($model_arr['nr'] > 0) ? $model_arr['result'][0]->color_name : $res->color1;
  1097. $data_arr['result'][$key]->enq_through = ($res->is_starapp == 1) ? "HYPER-M App" : "DMS";
  1098. $data_arr['result'][$key]->newvechicledatatime_str = projectfunc::enqdatediff($parent, NOW, $res->newvechicledatatime);
  1099. $checkdate = date('Y-m-d', strtotime($res->newvechicledatatime));
  1100. //0-overdue,1-current day,2-future
  1101. switch (true) {
  1102. case (strtotime($checkdate) < strtotime(CUR_DATE)): $data_arr['result'][$key]->enq_date_type = 0;
  1103. break;
  1104. case (strtotime($checkdate) == strtotime(CUR_DATE)): $data_arr['result'][$key]->enq_date_type = 1;
  1105. break;
  1106. case (strtotime($checkdate) > strtotime(CUR_DATE)): $data_arr['result'][$key]->enq_date_type = 2;
  1107. break;
  1108. }
  1109. ///PENDING ENQUIRY MASTER
  1110. if (strtoupper($res->enquiry_stage) == 'T') {
  1111. $data_arr['result'][$key]->icon_type = 1;
  1112. } else if (strtoupper($res->modeofcontact) == 'S' || strtoupper($res->modeofcontact) == 'V') {
  1113. $data_arr['result'][$key]->icon_type = 2;
  1114. } else if (in_array(strtoupper($res->modeofcontact), array('E', 'F', 'O', 'T'))) {
  1115. $data_arr['result'][$key]->icon_type = 3;
  1116. } else {
  1117. $data_arr['result'][$key]->icon_type = 0;
  1118. }
  1119. //visit,call,testdrive
  1120. }
  1121. }
  1122. //LOG
  1123. $logstr = 'ENQUIRY LIST';
  1124. globalfunc::insertUserLog($parent, $logstr);
  1125. $last_page = ($total) ? ceil($total / $parent->current_limit) - 1 : 0;
  1126. $parent->response(array('response' => 'success', 'data' => $data_arr['result'], 'total' => $total, 'last_page' => $last_page, 'current_page' => $parent->current_page, 'message' => $this->page_data['success1'], 'q' => $cond), 200);
  1127. } catch (PDOException $e) {
  1128. $parent->response(array('response' => 'failed', 'message' => $e->getMessage()), 500);
  1129. } catch (Exception $e) {
  1130. $parent->response(array('response' => 'failed', 'message' => $e->getMessage()), 500);
  1131. }
  1132. }
  1133. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  1134. /* /////////////////////////////// FOLLOWUP //////////////////////////////////////////////// */
  1135. private function followup($parent)
  1136. {
  1137. globalfunc::checkParamCount($parent, 1);
  1138. globalfunc::checkMethodType($parent, array('POST'));
  1139. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  1140. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  1141. $smpin = $parent->current_user_data->smpin;
  1142. $REQUEST_KEYS = array('id' => 'number', 'status' => 'string');
  1143. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  1144. $status = strtoupper(escape_str($parent->_request['status']));
  1145. $reason = '';
  1146. $subreason = '';
  1147. $lostdealer = '';
  1148. $lostmodel = '';
  1149. //'newvechicledate'=>'date|d-m-Y','newvechicletime'=>'string', 'modeofcontact'=>'string','nextfollowup'=>'string',
  1150. switch ($status) {
  1151. case 'L': //Lost
  1152. $REQUEST_KEYS = array('reason' => 'string', 'subreason' => 'string');
  1153. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  1154. $reason = escape_str($parent->_request['reason']);
  1155. $subreason = escape_str($parent->_request['subreason']);
  1156. $lostdealer = escape_str($parent->_request['lostdealer']);
  1157. $lostmodel = escape_str($parent->_request['lostmodel']);
  1158. break;
  1159. case 'E': //Postponed
  1160. $REQUEST_KEYS = array('reason' => 'string', 'newvechicledate' => 'date|d-m-Y', 'newvechicletime' => 'string', 'modeofcontact' => 'string', 'nextfollowup' => 'string');
  1161. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  1162. $reason = escape_str($parent->_request['reason']);
  1163. break;
  1164. case 'P': //Cold
  1165. case 'H': //Hot
  1166. case 'W': //Warm
  1167. $REQUEST_KEYS = array('newvechicledate' => 'date|d-m-Y', 'newvechicletime' => 'string', 'modeofcontact' => 'string', 'nextfollowup' => 'string');
  1168. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  1169. break;
  1170. }
  1171. $id = escape_str($parent->_request['id']);
  1172. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id,enq_num,newvechicledatatime,enquiry_stage,newvechicletactionplan", " smpin='" . $smpin . "' AND id='" . $id . "' AND is_dms=1 AND is_deleted=0 ", "1");
  1173. if (!$check_arr['nr'] > 0) {
  1174. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  1175. }
  1176. $newvechicledate = escape_str($parent->_request['newvechicledate']);
  1177. $newvechicletime = escape_str($parent->_request['newvechicletime']);
  1178. $date_arr = @explode("-", $newvechicledate);
  1179. $date_str = $date_arr[2] . "-" . $date_arr[1] . "-" . $date_arr[0];
  1180. $newvechicledatatime = $date_str . " " . $newvechicletime;
  1181. $followup_remark = escape_str($parent->_request['followup_remark']);
  1182. $followup_remark = str_replace(array("\n", "\r"), ' ', $followup_remark);
  1183. $modeofcontact = escape_str($parent->_request['modeofcontact']);
  1184. $nextfollowup = escape_str($parent->_request['nextfollowup']);
  1185. $p_act_follow_date = date('m/d/Y', strtotime($check_arr['result'][0]->newvechicledatatime));
  1186. if ($status == 'L') {
  1187. $p_next_stage_date = date('m/d/Y', strtotime(CUR_DATE));
  1188. } else {
  1189. $p_next_stage_date = date('m/d/Y', strtotime($date_str));
  1190. }
  1191. $post = array("query" => "BEGIN pkg_smipl_star_app.sp_followup_update(:p_mspin, :p_enq_num, :p_act_follow_date, :p_enq_actual_stage, :p_status, :p_enq_actual_action, :p_enq_reas_cd, :p_enq_sub_reas_cd, :p_enq_lost_dlr, :p_enq_lost_mod, :p_at_remarks, :p_next_stage_date, :p_enq_next_action, :p_enq_next_stage, :p_financer_code, :p_competition_manufacture, :p_competition_model, :p_error, :p_err_msg ); END;", "params" => '[{"title":"p_mspin","value":"' . $smpin . '","type":""},{"title":"p_enq_num","value":"' . $check_arr['result'][0]->enq_num . '","type":""}, {"title":"p_act_follow_date","value":"' . $p_act_follow_date . '","type":""}, {"title":"p_enq_actual_stage","value":"' . $check_arr['result'][0]->enquiry_stage . '","type":""},{"title":"p_status","value":"' . $status . '","type":""},{"title":"p_enq_actual_action","value":"' . $check_arr['result'][0]->newvechicletactionplan . '","type":""},{"title":"p_enq_reas_cd","value":"' . $reason . '","type":""},{"title":"p_enq_sub_reas_cd","value":"' . $subreason . '","type":""},{"title":"p_enq_lost_dlr","value":"' . $lostdealer . '","type":""},{"title":"p_enq_lost_mod","value":"' . $lostmodel . '","type":""},{"title":"p_at_remarks","value":"' . $followup_remark . '","type":""},{"title":"p_next_stage_date","value":"' . $p_next_stage_date . '","type":""},{"title":"p_enq_next_action","value":"' . $modeofcontact . '","type":""},{"title":"p_enq_next_stage","value":"' . $nextfollowup . '","type":""},{"title":"p_financer_code","value":"","type":""},{"title":"p_competition_manufacture","value":"","type":""},{"title":"p_competition_model","value":"","type":""},{"title":"p_error","value":"2","type":"string","length":200},{"title":"p_err_msg","value":"","type":"string","length":1000}]');
  1192. $url = SUZ_DMS_URL;
  1193. $header = array('Authorization:Bearer ' . SUZ_TOKEN);
  1194. //LOG
  1195. $obj = new stdClass();
  1196. $obj->type = 'followupdate';
  1197. $obj->apirequest = $post['params'];
  1198. $log_id = projectfunc::cronLog($parent, $obj);
  1199. // $ch = curl_init();
  1200. // curl_setopt($ch, CURLOPT_URL, $url);
  1201. // curl_setopt($ch, CURLOPT_POST, 1);
  1202. // curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //Post Fields
  1203. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1204. // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1205. // $response = curl_exec($ch);
  1206. // $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  1207. // curl_close($ch);
  1208. $httpcode = '200';
  1209. $response="";
  1210. $error = 1;
  1211. $count = 0;
  1212. //LOG UPDATE
  1213. $obj = new stdClass();
  1214. $obj->id = $log_id;
  1215. $obj->apiresponse = $response;
  1216. projectfunc::updateCronLog($parent, $obj);
  1217. if ($httpcode == '200' && $response != '') {
  1218. $json = json_decode($response);
  1219. //LOG UPDATE
  1220. $obj = new stdClass();
  1221. $obj->id = $log_id;
  1222. $obj->insert_count = 0;
  1223. $obj->status = 1;
  1224. //$obj->apiresponse=$response;
  1225. projectfunc::updateCronLog($parent, $obj);
  1226. if (isset($json->response) && $json->response == 'success' && isset($json->data)) {
  1227. if ($json->data->p_err_msg == '' || $json->data->p_err_msg == null) {
  1228. $error = 0;
  1229. }
  1230. }
  1231. $emsg = $json->data->p_err_msg;
  1232. }
  1233. //LOG
  1234. $logstr = 'ENQUIRY FOLLOWUP SUBMIT';
  1235. globalfunc::insertUserLog($parent, $logstr, $check_arr['result'][0]->id);
  1236. if ($error == 0) {
  1237. if ($status != 'L') {
  1238. //UPDATE FOLLOW UP
  1239. $update_str = "UPDATE " . DMS_ENQUIRY_MASTER . " SET newvechicledate='" . $date_str . "', newvechicletime='" . $newvechicletime . "', newvechicledatatime='" . $newvechicledatatime . "' WHERE id='" . $check_arr['result'][0]->id . "'";
  1240. $parent->executeQuery($update_str);
  1241. }
  1242. //DIRECT STATUS UPDATE
  1243. $parent->executeQuery("UPDATE " . DMS_ENQUIRY_MASTER . " SET status='" . $status . "' WHERE id='" . $check_arr['result'][0]->id . "'");
  1244. $parent->response(array('response' => 'success', 'message' => $this->page_data['success2']), 200);
  1245. } else {
  1246. $emsg = ($emsg != '') ? $emsg : "Error to connect DMS. Please try after sometime";
  1247. $parent->response(array('response' => 'failed', 'message' => $emsg), 406);
  1248. }
  1249. }
  1250. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  1251. /* /////////////////////////////// STOCK AVAILABILITY //////////////////////////////////////////////// */
  1252. private function stockavailability($parent)
  1253. {
  1254. globalfunc::checkParamCount($parent, 1);
  1255. globalfunc::checkMethodType($parent, array('POST'));
  1256. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  1257. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  1258. $model = escape_str($parent->_request['model']);
  1259. $variant = escape_str($parent->_request['variant']);
  1260. $color = escape_str($parent->_request['color']);
  1261. $smpin = $parent->current_user_data->smpin;
  1262. $url = SUZ_DMS_URL;
  1263. $post = array("query" => "BEGIN pkg_smipl_star_app.sp_available_stock(:p_mspin, :p_pmc, :p_model_cd, :p_variant_cd, :p_color_cd, :p_list_cursor, :p_err_cd, :p_err_msg); END;", "params" => '[{"title":"p_mspin","value":"' . $smpin . '","type":""},{"title":"p_pmc","value":"2","type":""},{"title":"p_model_cd","value":"' . $model . '","type":""},{"title":"p_variant_cd","value":"' . $variant . '","type":""},{"title":"p_color_cd","value":"' . $color . '","type":""},{"title":"p_list_cursor","value":"","type":"cursor"},{"title":"p_err_cd","value":"","type":"string","length":200},{"title":"p_err_msg","value":"","type":"string","length":1000}]');
  1264. $header = array('Authorization:Bearer ' . SUZ_TOKEN);
  1265. //LOG
  1266. $obj = new stdClass();
  1267. $obj->type = 'callmodelstock';
  1268. $obj->apirequest = $post['params'];
  1269. $log_id = projectfunc::cronLog($parent, $obj);
  1270. // $ch = curl_init();
  1271. // curl_setopt($ch, CURLOPT_URL, $url);
  1272. // curl_setopt($ch, CURLOPT_POST, 1);
  1273. // curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //Post Fields
  1274. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1275. // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1276. // $response = curl_exec($ch);
  1277. // $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  1278. // curl_close($ch);
  1279. $httpcode = '200';
  1280. $response="";
  1281. $error = 1;
  1282. $count = 0;
  1283. //LOG UPDATE
  1284. $obj = new stdClass();
  1285. $obj->id = $log_id;
  1286. $obj->apiresponse = $response;
  1287. projectfunc::updateCronLog($parent, $obj);
  1288. //LOG
  1289. $logstr = 'ENQUIRY STOCK';
  1290. globalfunc::insertUserLog($parent, $logstr);
  1291. if ($httpcode == '200' && $response != '') {
  1292. $json = json_decode($response);
  1293. if (isset($json->response) && $json->response == 'success' && isset($json->data) && count($json->data) > 0) {
  1294. $data = $json->data;
  1295. $count = count($json->data);
  1296. //0-Data not Found,1-Available,2-Since Transfer,3-Not Available
  1297. $status = array('title' => 'Not Available', 'status' => 0);
  1298. if ($count > 0) {
  1299. if ($data[0]->AVAILABLE_STOCK > 0) {
  1300. $status = array('title' => 'Available', 'status' => 1);
  1301. }
  1302. if ($data[0]->AVAILABLE_STOCK == 0 && $data[0]->INTRANSIT_STOCK > 0) {
  1303. $status = array('title' => 'In Transit', 'status' => 2);
  1304. }
  1305. }
  1306. //LOG UPDATE
  1307. $obj = new stdClass();
  1308. $obj->id = $log_id;
  1309. $obj->insert_count = 1;
  1310. $obj->status = 1;
  1311. //$obj->apiresponse=$response;
  1312. projectfunc::updateCronLog($parent, $obj);
  1313. $parent->response(array('response' => 'success', 'data' => $status, 'message' => $this->page_data['success1']), 200);
  1314. }
  1315. }
  1316. $status = array('title' => 'Not Available', 'status' => 0);
  1317. $parent->response(array('response' => 'success', 'data' => $status, 'message' => $this->page_data['success1']), 200);
  1318. }
  1319. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  1320. /* /////////////////////////////// DETAILS //////////////////////////////////////////////// */
  1321. private function details($parent)
  1322. {
  1323. globalfunc::checkParamCount($parent, 2);
  1324. globalfunc::checkMethodType($parent, array('GET'));
  1325. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  1326. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  1327. $smpin = $parent->current_user_data->smpin;
  1328. $id = escape_str($parent->params[1]);
  1329. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id", " smpin='" . $smpin . "' AND is_deleted=0 AND id='" . $id . "'", "1");
  1330. if ($check_arr['nr'] != '1') {
  1331. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  1332. }
  1333. //GET DATA
  1334. $data_arr = $this->getEnquirydata($parent, $id);
  1335. //BROCHURE
  1336. $brochure_arr = array();
  1337. $brochure_url = SITE_URL . "explore_assets/model/";
  1338. $expmodel_data = $parent->selectQuery(TABLE_COMPARE_MODEL, "model_id,CASE WHEN model_brochure!='' THEN CONCAT('" . $brochure_url . "',model_brochure) ELSE '' END AS 'model_brochure' ", "is_deleted=0 AND is_other=0 AND `model_type` = '0'", "");
  1339. if ($expmodel_data['nr'] > 0) {
  1340. $arr_id = array_column($expmodel_data['result'], 'model_id');
  1341. $arr_name = array_column($expmodel_data['result'], 'model_brochure');
  1342. $brochure_arr = array_combine($arr_id, $arr_name);
  1343. }
  1344. // `model1`, `variant1`, `color1`
  1345. switch ($data_arr->model1) {
  1346. case 'GSX': //GIXXER
  1347. $id = (strpos($data_arr->variant1, 'GSX250') !== false || strpos($data_arr->variant_name, 'GIXXER 250') !== false) ? GIXXER_250_ID : GIXXER_ID;
  1348. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  1349. break;
  1350. case 'GSXSF': //GIXXER SF
  1351. $id = (strpos($data_arr->variant1, 'GSXF250') !== false || strpos($data_arr->variant_name, 'GIXXER SF 250') !== false) ? GIXXER_SF_250_ID : GIXXER_SF_ID;
  1352. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  1353. break;
  1354. case 'GL': //INTRUDER
  1355. $id = INTRUDER_ID;
  1356. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  1357. break;
  1358. case 'UB125': //BURGMAN
  1359. $id = BURGMAN_ID;
  1360. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  1361. break;
  1362. case 'AC':
  1363. case 'ACZ':
  1364. $id = ACCESS_ID;
  1365. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  1366. break;
  1367. default:
  1368. $brochure_url = '';
  1369. break;
  1370. }
  1371. $data_arr->brochure = $brochure_url;
  1372. //CALL HISTORY
  1373. $data_arr->history = array();
  1374. $url = SUZ_DMS_URL;
  1375. $post = array("query" => "BEGIN pkg_smipl_star_app.sp_followup_history(:p_mspin, :p_enq_num, :p_pmc, :p_cust_name, :p_mobile, :p_email, :p_model_cd, :p_model, :p_variant_cd, :p_variant, :p_status_cd, :p_status, :p_color_cd, :p_color, :p_make, :p_makemodel_cd, :p_makemodel, :p_evaluatorid, :p_evaluator_name, :p_expectedprice, :p_evaluatedprice, :p_buying_price, :p_buyertype, :p_enquiry_source, :p_enquiry_date, :list_cursor, :p_error, :p_err_msg, :p_remarks, :p_km_drive_month, :p_mode_of_purchase, :p_financer_code, :p_financer_name, :p_tl_remarks, :p_comp_manuf_cd, :p_comp_manuf_name, :p_comp_model_cd, :p_comp_model_name, :p_corporate_code, :p_rm_evaluator_remark, :p_evaluator_remark); END;", "params" => '[{"title":"p_mspin","value":"' . $smpin . '","type":""},{"title":"p_enq_num","value":"' . $data_arr->enq_num . '","type":""},{"title":"p_pmc","value":2,"type":""},{"title":"p_cust_name","value":"","type":"string","length":200},{"title":"p_mobile","value":"","type":"string","length":200},{"title":"p_email","value":"","type":"string","length":200},{"title":"p_model_cd","value":"","type":"string","length":200},{"title":"p_model","value":"","type":"string","length":200},{"title":"p_variant_cd","value":"","type":"string","length":200},{"title":"p_variant","value":"","type":"string","length":200},{"title":"p_status_cd","value":"","type":"string","length":200},{"title":"p_status","value":"","type":"string","length":200},{"title":"p_color_cd","value":"","type":"string","length":200},{"title":"p_color","value":"","type":"string","length":200},{"title":"p_make","value":"","type":"string","length":200},{"title":"p_makemodel_cd","value":"","type":"string","length":200},{"title":"p_makemodel","value":"","type":"string","length":200},{"title":"p_evaluatorid","value":"","type":"string","length":200},{"title":"p_evaluator_name","value":"","type":"string","length":200},{"title":"p_expectedprice","value":"","type":"string","length":200},{"title":"p_evaluatedprice","value":"","type":"string","length":200},{"title":"p_buying_price","value":"","type":"string","length":200},{"title":"p_buyertype","value":"","type":"string","length":200},{"title":"p_enquiry_source","value":"","type":"string","length":200},{"title":"p_enquiry_date","value":"","type":"string","length":200},{"title":"list_cursor","value":"","type":"cursor"},{"title":"p_error","value":"","type":"string","length":20 },{"title":"p_err_msg","value":"","type":"string","length":1000},{"title":"p_remarks","value":"","type":"string","length":1000},{"title":"p_km_drive_month","value":"","type":"string","length":200},{"title":"p_mode_of_purchase","value":"","type":"string","length":200},{"title":"p_financer_code","value":"","type":"string","length":200},{"title":"p_financer_name","value":"","type":"string","length":200},{"title":"p_tl_remarks","value":"","type":"string","length":200},{"title":"p_comp_manuf_cd","value":"","type":"string","length":200},{"title":"p_comp_manuf_name","value":"","type":"string","length":200},{"title":"p_comp_model_cd","value":"","type":"string","length":200},{"title":"p_comp_model_name","value":"","type":"string","length":200},{"title":"p_corporate_code","value":"","type":"string","length":200},{"title":"p_rm_evaluator_remark","value":"","type":"string","length":200},{"title":"p_evaluator_remark","value":"","type":"string","length":200}]');
  1376. $header = array('Authorization:Bearer ' . SUZ_TOKEN);
  1377. //LOG
  1378. $obj = new stdClass();
  1379. $obj->type = 'followhistory';
  1380. $obj->apirequest = $post['params'];
  1381. $log_id = projectfunc::cronLog($parent, $obj);
  1382. // $ch = curl_init();
  1383. // curl_setopt($ch, CURLOPT_URL, $url);
  1384. // curl_setopt($ch, CURLOPT_POST, 1);
  1385. // curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //Post Fields
  1386. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1387. // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1388. // $response = curl_exec($ch);
  1389. // $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  1390. // curl_close($ch);
  1391. $httpcode = '200';
  1392. $response="";
  1393. $error = 1;
  1394. $count = 0;
  1395. //LOG UPDATE
  1396. $obj = new stdClass();
  1397. $obj->id = $log_id;
  1398. $obj->apiresponse = $response;
  1399. projectfunc::updateCronLog($parent, $obj);
  1400. // $hobj=new stdClass();
  1401. // $hobj->title='Enquiry Created';
  1402. // $hobj->remarks=trim($parent->current_user_data->fname." ".$parent->current_user_data->lname);
  1403. // $hobj->created_on=date('Y-m-d',strtotime($data_arr->created_on));
  1404. // $hobj->created_on_str=date('d-M-Y',strtotime($data_arr->created_on));
  1405. // $hobj->image='';
  1406. // $hobj->type='';//testride
  1407. // $hobj->colorcode='#FFFF00';// Hexcode
  1408. // $hobj->type=$data_arr->action_str; //Testride
  1409. // $hobj->stage=$data_arr->enquiry_str;
  1410. // $hobj->status=$data_arr->status_str;
  1411. // $hobj->order=1;
  1412. // $data_arr->history[]=$hobj;
  1413. if ($httpcode == '200' && $response != '') {
  1414. //LOG UPDATE
  1415. $obj = new stdClass();
  1416. $obj->id = $log_id;
  1417. $obj->insert_count = count($json->data);
  1418. $obj->status = 1;
  1419. //$obj->apiresponse=$response;
  1420. projectfunc::updateCronLog($parent, $obj);
  1421. $json = json_decode($response);
  1422. if (isset($json->response) && $json->response == 'success' && isset($json->data) && count($json->data) > 0) {
  1423. $error = 0;
  1424. if (count($json->data)) {
  1425. foreach ($json->data as $res) {
  1426. $hobj = new stdClass();
  1427. $hobj->title = $res->ACTION_PLAN;
  1428. $hobj->remarks = ($res->REMARKS) ? $res->REMARKS : '';
  1429. $hobj->created_on = date('Y-m-d', strtotime($res->FOLLOW_PLAN_DATE));
  1430. $hobj->created_on_str = date('d-M-Y', strtotime($res->FOLLOW_PLAN_DATE));
  1431. $hobj->order = strtotime($res->FOLLOW_PLAN_DATE);
  1432. $hobj->image = '';
  1433. $hobj->type = ($res->ACTION_PLAN) ? $res->ACTION_PLAN : '';
  1434. $hobj->stage = ($res->STAGE_PLAN) ? $res->STAGE_PLAN : $res->STAGE_ACTUAL;
  1435. $hobj->status = ($res->FOLLOWSTATUS) ? $res->FOLLOWSTATUS : '';
  1436. // Hexcode
  1437. switch (trim($hobj->stage)) {
  1438. case 'Invoiced':
  1439. case 'Order Booking':
  1440. case 'Vehicle Delivered':
  1441. case 'Proforma Invoice':
  1442. $hobj->colorcode = '#008000'; //green
  1443. break;
  1444. case 'Lost':
  1445. $hobj->colorcode = '#FF0000'; //RED
  1446. break;
  1447. default:
  1448. $hobj->colorcode = '#FF8C00'; //orange
  1449. break;
  1450. }
  1451. $data_arr->history[] = $hobj;
  1452. }
  1453. }
  1454. }
  1455. }
  1456. //SORT
  1457. // if (count($data_arr->history) > 0) {
  1458. // usort($data_arr->history, 'comparator');
  1459. // }
  1460. //LOG
  1461. $logstr = 'ENQUIRY DETAILS';
  1462. globalfunc::insertUserLog($parent, $logstr, $id);
  1463. $parent->response(array('response' => 'success', 'data' => $data_arr, 'message' => $this->page_data['success1']), 200);
  1464. }
  1465. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  1466. /* /////////////////////////////// Share //////////////////////////////////////////////// */
  1467. private function sharebrochure($parent)
  1468. {
  1469. globalfunc::checkParamCount($parent, 1);
  1470. globalfunc::checkMethodType($parent, array('POST'));
  1471. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  1472. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  1473. $email = escape_str($parent->_request['email']);
  1474. $REQUEST_KEYS = array('name' => 'string', 'email' => 'string', 'model' => 'string', 'variant' => 'string');
  1475. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  1476. if (!globalfunc::isValidEmail($email)) {
  1477. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error12']), 406);
  1478. }
  1479. $smpin = $parent->current_user_data->smpin;
  1480. $name = escape_str($parent->_request['name']);
  1481. $model = escape_str($parent->_request['model']);
  1482. $variant = escape_str($parent->_request['variant']);
  1483. $checkmodel_data = $parent->selectQuery(DMS_ENQUIRY_MODEL, "id,title,variant", " status='1' AND enq_yn='Y' AND title_code='" . $model . "' AND variant_code='" . $variant . "'", "1");
  1484. if ($checkmodel_data['nr'] == 0) {
  1485. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error13']), 406);
  1486. }
  1487. $brochure_arr = array();
  1488. $brochure_url = SITE_URL . "explore_assets/model/";
  1489. $expmodel_data = $parent->selectQuery(TABLE_COMPARE_MODEL, "model_id,CASE WHEN model_brochure!='' THEN CONCAT('" . $brochure_url . "',model_brochure) ELSE '' END AS 'model_brochure' ", "is_deleted=0 AND is_other=0 AND `model_type` = '0'", "");
  1490. if ($expmodel_data['nr'] > 0) {
  1491. $arr_id = array_column($expmodel_data['result'], 'model_id');
  1492. $arr_name = array_column($expmodel_data['result'], 'model_brochure');
  1493. $brochure_arr = array_combine($arr_id, $arr_name);
  1494. }
  1495. $brochure_url = '';
  1496. switch (strtoupper($model)) {
  1497. case 'GSX': //GIXXER
  1498. $id = (strpos($variant, 'GSX250') !== false || strpos($checkmodel_data['result'][0]->title, 'GIXXER 250') !== false) ? GIXXER_250_ID : GIXXER_ID;
  1499. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  1500. break;
  1501. case 'GSXSF': //GIXXER SF
  1502. $id = (strpos($variant, 'GSXF250') !== false || strpos($checkmodel_data['result'][0]->title, 'GIXXER SF 250') !== false) ? GIXXER_SF_250_ID : GIXXER_SF_ID;
  1503. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  1504. break;
  1505. case 'GL': //INTRUDER
  1506. $id = INTRUDER_ID;
  1507. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  1508. break;
  1509. case 'UB125': //BURGMAN
  1510. $id = BURGMAN_ID;
  1511. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  1512. break;
  1513. case 'AC':
  1514. case 'ACZ':
  1515. $id = ACCESS_ID;
  1516. $brochure_url = isset($brochure_arr[$id]) ? $brochure_arr[$id] : '';
  1517. break;
  1518. default:
  1519. $brochure_url = '';
  1520. break;
  1521. }
  1522. if ($brochure_url == '') {
  1523. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error14']), 406);
  1524. }
  1525. // $id=escape_str($parent->params[1]);
  1526. // $check_arr=$parent->selectQuery(DMS_ENQUIRY_MASTER ,"id,email,share_token"," smpin='".$smpin."' AND is_deleted=0 AND id='".$id."'","1");
  1527. // if($check_arr['nr']!='1') $parent->response(array('response'=>'failed', 'message'=>$this->page_data['error6']),406);
  1528. //
  1529. // $email=$check_arr['result'][0]->email;
  1530. // if($email!='') $parent->response(array('response'=>'failed', 'message'=>$this->page_data['error11']),406);
  1531. //
  1532. // if($check_arr['result'][0]->share_token!='')
  1533. // {
  1534. // //SHARE TOKEN UPDATE
  1535. // $access_token=globalfunc::generateToken($parent,'enquiry',128);
  1536. // $update_str = "UPDATE ".DMS_ENQUIRY_MASTER." SET share_token='".$access_token."' WHERE id='".$id."'";
  1537. // $parent->executeQuery($update_str);
  1538. // }
  1539. $obj = array();
  1540. $obj['from'] = SUPPORT_EMAIL;
  1541. $obj['FromName'] = 'HYPER-M';
  1542. $obj['to'] = $email;
  1543. $obj['subject'] = 'HYPER-M - Brochure for ' . $checkmodel_data['result'][0]->title . ' ' . $checkmodel_data['result'][0]->variant;
  1544. $explore_url = $brochure_url;
  1545. $cond_mail_str1 = "Thank you for showing your interest in HYPER-M.";
  1546. $cond_mail_str2 = "We hope you had a great experience in exploring our range of Students";
  1547. $email_link = '<a href="' . $explore_url . '" style="font-weight:bold " >Click Here</a> to download the product e-brochure of ' . $checkmodel_data['result'][0]->title . ' ' . $checkmodel_data['result'][0]->variant . '<br>';
  1548. $message = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
  1549. <tbody>
  1550. <tr>
  1551. <td>
  1552. <table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
  1553. <tbody>
  1554. <tr>
  1555. <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">HYPER-M</td>
  1556. </tr>
  1557. <tr>
  1558. <td>
  1559. <table width="85%" align="center">
  1560. <tbody>
  1561. <tr>
  1562. <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  1563. line-height: 1.5;">
  1564. <div style="font-family:arial; color:#333; font-size:12px; padding:5px;">Dear ' . $name . ',</div>
  1565. </td>
  1566. </tr>
  1567. <tr>
  1568. <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  1569. line-height: 1.5;">
  1570. <div style="font-family:arial; color:#333; font-size:12px; padding:5px;">Greetings of the Day..!<br>
  1571. ' . $cond_mail_str1 . '<br>
  1572. ' . $cond_mail_str2 . '<br><br>
  1573. ' . $email_link . '
  1574. Thank you again for your visit and we look forward to see you soon.
  1575. </div>
  1576. </td>
  1577. </tr>
  1578. <tr>
  1579. <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  1580. line-height: 1.5;"><div style="font-family:arial; color:#333; font-size:12px; padding:5px;">
  1581. Visit us at: <a href=" ">click here<a><br>
  1582. Toll Free Number: 1800-121-7996 (Mon-Sat 9AM - 5:30PM)</p>
  1583. <p>This is a system generated e-mail, please do not reply to this mail. </p>
  1584. </div>
  1585. </td>
  1586. </tr>
  1587. </tbody>
  1588. </table>
  1589. </td>
  1590. </tr>
  1591. <tr>
  1592. <td style="padding-top:0px; padding-bottom:10px;"></td>
  1593. </tr>
  1594. <tr>
  1595. <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#3f3f3f; background:#fafafa; line-height:20px; border-bottom:2px solid black">
  1596. &nbsp;
  1597. </td>
  1598. </tr>
  1599. </tbody>
  1600. </table>
  1601. </td>
  1602. </tr>
  1603. </tbody>
  1604. </table>';
  1605. $obj['message'] = $message;
  1606. // globalfunc::sendMai($parent, $obj);
  1607. $parent->executeQuery("INSERT INTO `" . TABLE_ENQBROCHURESHARE . "` (`smpin`, `name`,email, `model`, `variant`, `created_on`) VALUES ('" . $smpin . "','" . $name . "','" . $email . "','" . $model . "','" . $variant . "' , '" . NOW . "')");
  1608. //LOG
  1609. $logstr = 'ENQUIRY SHARE BROCHURE';
  1610. globalfunc::insertUserLog($parent, $logstr);
  1611. $parent->response(array('response' => 'success', 'message' => $this->page_data['success7']), 200);
  1612. }
  1613. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  1614. /* /////////////////////////////// QUOTATION //////////////////////////////////////////////// */
  1615. private function quotation($parent)
  1616. {
  1617. globalfunc::checkParamCount($parent, 1);
  1618. globalfunc::checkMethodType($parent, array('POST'));
  1619. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  1620. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  1621. $smpin = $parent->current_user_data->smpin;
  1622. $model = escape_str($parent->_request['model']);
  1623. $variant = escape_str($parent->_request['variant']);
  1624. $REQUEST_KEYS = array('model' => 'string', 'variant' => 'string');
  1625. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  1626. //DMS_ENQUIRY_MODEL
  1627. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MODEL, "title,title_code,variant,variant_code", " title_code='" . $model . "' AND variant_code='" . $variant . "' AND enq_yn='Y' AND status=1 ", "1");
  1628. if (!$check_arr['nr'] > 0) {
  1629. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error15']), 406);
  1630. }
  1631. //echo $parent->current_user_data->dealer_code;
  1632. //DEALER
  1633. $check_arr = $parent->selectQuery(DMS_DEALER, "dealer_code,for_cd", "dealer_code='" . $parent->current_user_data->dealer_code . "' AND for_cd!='' AND is_deleted=0 ", "1");
  1634. if (!$check_arr['nr'] > 0) {
  1635. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error16']), 406);
  1636. }
  1637. $for_cd = $check_arr['result'][0]->for_cd;
  1638. //CALL DMS
  1639. $url = SUZ_DMS_URL;
  1640. $post = array("query" => "BEGIN pkg_smipl_star_app.sp_vehicle_model_price(:p_model, :p_for, :p_pmc, :list_cursor, :p_err_cd, :p_err_msg); END;", "params" => '[{"title":"p_model","value":"' . $model . '","type":""},{"title":"p_for","value":"' . $for_cd . '","type":""},{"title":"p_pmc","value":"2","type":""},{"title":"list_cursor","value":"","type":"cursor"},{"title":"p_err_cd","value":"","type":""},{"title":"p_err_msg","value":"","type":""}]');
  1641. $header = array('Authorization:Bearer ' . SUZ_TOKEN);
  1642. //LOG
  1643. $obj = new stdClass();
  1644. $obj->type = 'modelprice';
  1645. $obj->apirequest = $post['params'];
  1646. $log_id = projectfunc::cronLog($parent, $obj);
  1647. // $ch = curl_init();
  1648. // curl_setopt($ch, CURLOPT_URL, $url);
  1649. // curl_setopt($ch, CURLOPT_POST, 1);
  1650. // curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //Post Fields
  1651. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1652. // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1653. // $response = curl_exec($ch);
  1654. // $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  1655. // curl_close($ch);
  1656. $httpcode = '200';
  1657. $response="";
  1658. $error = 1;
  1659. $count = 0;
  1660. //LOG UPDATE
  1661. $obj = new stdClass();
  1662. $obj->id = $log_id;
  1663. $obj->apiresponse = $response;
  1664. projectfunc::updateCronLog($parent, $obj);
  1665. if ($httpcode == '200' && $response != '') {
  1666. $json = json_decode($response);
  1667. if (isset($json->response) && $json->response == 'success' && isset($json->data) && count($json->data) > 0) {
  1668. //LOG UPDATE
  1669. $obj = new stdClass();
  1670. $obj->id = $log_id;
  1671. $obj->insert_count = count($json->data);
  1672. $obj->status = 1;
  1673. //$obj->apiresponse=$response;
  1674. projectfunc::updateCronLog($parent, $obj);
  1675. foreach ($json->data as $res) {
  1676. if (strtolower($variant) == strtolower($res->VARIANT_CD)) {
  1677. $error = 0;
  1678. $data = array('exsh_price' => $res->EXSH_PRICE);
  1679. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success1']), 200);
  1680. break;
  1681. }
  1682. }
  1683. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error17']), 406);
  1684. }
  1685. if ($json->response == 'success' && $json->data->p_err_msg != '') {
  1686. $emsg = $json->data->p_err_msg;
  1687. }
  1688. }
  1689. //LOG
  1690. $logstr = 'ENQUIRY QUOTATION';
  1691. globalfunc::insertUserLog($parent, $logstr, $id);
  1692. if ($error == 1) {
  1693. $emsg = ($emsg != '') ? $emsg : "Error to connect DMS. Please try after sometime";
  1694. $parent->response(array('response' => 'failed', 'message' => $emsg), 406);
  1695. } else {
  1696. $parent->response(array('response' => 'success', 'message' => $this->page_data['success1']), 200);
  1697. }
  1698. }
  1699. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  1700. /* /////////////////////////////// SHARE QUOTATION //////////////////////////////////////////////// */
  1701. private function sharequotation($parent)
  1702. {
  1703. globalfunc::checkParamCount($parent, 1);
  1704. globalfunc::checkMethodType($parent, array('POST'));
  1705. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  1706. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  1707. $smpin = $parent->current_user_data->smpin;
  1708. $dealer_code = $parent->current_user_data->dealer_code;
  1709. //,'validity_date'=>''
  1710. $REQUEST_KEYS = array('name' => 'string', 'email' => 'string', 'mobile' => 'string', 'email' => 'string', 'model' => 'string', 'variant' => 'string', 'exsh_price' => 'number', 'total_price' => 'number');
  1711. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  1712. $name = escape_str($parent->_request['name']);
  1713. $email = escape_str($parent->_request['email']);
  1714. $mobile = escape_str($parent->_request['mobile']);
  1715. $model = escape_str($parent->_request['model']);
  1716. $variant = escape_str($parent->_request['variant']);
  1717. //DMS_ENQUIRY_MODEL
  1718. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MODEL, "title,title_code,variant,variant_code", " title_code='" . $model . "' AND variant_code='" . $variant . "' AND enq_yn='Y' AND status=1 ", "1");
  1719. if (!$check_arr['nr'] > 0) {
  1720. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error17']), 406);
  1721. }
  1722. $exsh_price = escape_str($parent->_request['exsh_price']);
  1723. $exsh_remark = escape_str($parent->_request['exsh_remark']);
  1724. $rto_price = escape_str($parent->_request['rto_price']);
  1725. $rto_remark = escape_str($parent->_request['rto_remark']);
  1726. $insurance_price = escape_str($parent->_request['insurance_price']);
  1727. $insurance_remark = escape_str($parent->_request['insurance_remark']);
  1728. $access_price = escape_str($parent->_request['access_price']);
  1729. $access_remark = escape_str($parent->_request['access_remark']);
  1730. $exwarr_price = escape_str($parent->_request['exwarr_price']);
  1731. $exwarr_remark = escape_str($parent->_request['exwarr_remark']);
  1732. $other_price = escape_str($parent->_request['other_price']);
  1733. $other_remark = escape_str($parent->_request['other_remark']);
  1734. $total_price = escape_str($parent->_request['total_price']);
  1735. $total_remark = escape_str($parent->_request['total_remark']);
  1736. $validity_date = escape_str($parent->_request['valid_date']);
  1737. $discount = escape_str($parent->_request['offer_price']);
  1738. $final_price = escape_str($parent->_request['after_discound']);
  1739. if (!$validity_date != '') {
  1740. $valid_day = 10;
  1741. $validity_date = date('Y-m-d', strtotime('+ ' . $valid_day . ' day', strtotime(CUR_DATE)));
  1742. }
  1743. $sharetoken = TIMETOKEN . globalfunc::generateToken($parent, '', 32);
  1744. $parent->executeQuery("INSERT INTO `" . TABLE_QUOTATIONSHARE . "` ( `smpin`, dealer_code, `sharetoken`, `name`, `mobile`, `email`, `model`, `variant`, `exsh_price`, `exsh_remark`, `rto_price`, `rto_remark`, `insurance_price`, `insurance_remark`, `access_price`, `access_remark`, `exwarr_price`, `exwarr_remark`, `other_price`, `other_remark`, `total_price`, `total_remark`,discount,final_price, `validity_date`, `created_on`, `modified_on`) VALUES ('" . $smpin . "','" . $dealer_code . "','" . $sharetoken . "', '" . $name . "', '" . $mobile . "', '" . $email . "', '" . $model . "', '" . $variant . "', '" . $exsh_price . "', '" . $exsh_remark . "', '" . $rto_price . "', '" . $rto_remark . "', '" . $insurance_price . "', '" . $insurance_remark . "', '" . $access_price . "', '" . $access_remark . "', '" . $exwarr_price . "', '" . $exwarr_remark . "', '" . $other_price . "', '" . $other_remark . "', '" . $total_price . "', '" . $total_remark . "','" . $discount . "','" . $final_price . "','" . $validity_date . "' ,'" . NOW . "', '" . NOW . "')");
  1745. //LOG
  1746. $logstr = 'SHARE QUOTATION';
  1747. globalfunc::insertUserLog($parent, $logstr);
  1748. $url = SITE_URL . "quotation/" . $sharetoken;
  1749. //GET DEALER DETAILS
  1750. $dealer_arr = $parent->selectQuery(DMS_DEALER, "*", "dealer_code='" . $dealer_code . "' AND is_deleted=0 ", "1");
  1751. $dealer_email = ($dealer_arr['nr'] > 0) ? $dealer_arr['result'][0]->email : '';
  1752. $obj = array();
  1753. $obj['from'] = SUPPORT_EMAIL;
  1754. $obj['FromName'] = 'HYPER-M';
  1755. $obj['to'] = $email;
  1756. if ($dealer_email != '') {
  1757. $obj['cc'] = $dealer_email;
  1758. }
  1759. $obj['subject'] = 'HYPER-M - Quotation for ' . $check_arr['result'][0]->title . ' ' . $check_arr['result'][0]->variant;
  1760. $explore_url = $url;
  1761. $cond_mail_str1 = "Thank you for showing your interest in HYPER-M.";
  1762. $cond_mail_str2 = "We hope you had a great experience in exploring our range of products";
  1763. $email_link = '<a href="' . $explore_url . '" style="font-weight:bold " >Click Here</a> to view the Quotation for ' . $check_arr['result'][0]->title . ' ' . $check_arr['result'][0]->variant . '<br>';
  1764. $dealer_details = '';
  1765. if ($dealer_arr['nr'] > 0) {
  1766. $dealer_details = $dealer_arr['result'][0]->dealer_name;
  1767. $dealer_details .= ($dealer_arr['result'][0]->address != '') ? '<br>' . $dealer_arr['result'][0]->address : '';
  1768. $dealer_details .= ($dealer_arr['result'][0]->phone != '') ? '<br>Mob : ' . $dealer_arr['result'][0]->phone : '';
  1769. $dealer_details .= ($dealer_arr['result'][0]->email != '') ? '<br>Email : ' . $dealer_arr['result'][0]->email : '';
  1770. }
  1771. $message = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
  1772. <tbody>
  1773. <tr>
  1774. <td>
  1775. <table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
  1776. <tbody>
  1777. <tr>
  1778. <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">HYPER-M</td>
  1779. </tr>
  1780. <tr>
  1781. <td>
  1782. <table width="85%" align="center">
  1783. <tbody>
  1784. <tr>
  1785. <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  1786. line-height: 1.5;">
  1787. <div style="font-family:arial; color:#333; font-size:12px; padding:5px;">Dear ' . $name . ',</div>
  1788. </td>
  1789. </tr>
  1790. <tr>
  1791. <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  1792. line-height: 1.5;">
  1793. <div style="font-family:arial; color:#333; font-size:12px; padding:5px;">Greetings of the Day..!<br>
  1794. ' . $cond_mail_str1 . '<br>
  1795. ' . $cond_mail_str2 . '<br><br>
  1796. ' . $email_link . '
  1797. Thank you again for your visit and we look forward to see you soon.
  1798. <br><br>Regards,<br>' . $dealer_details . '
  1799. </div>
  1800. </td>
  1801. </tr>
  1802. <tr>
  1803. <td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  1804. line-height: 1.5;"><div style="font-family:arial; color:#333; font-size:12px; padding:5px;">
  1805. Visit us at: <a href="">click here<a><br>
  1806. Toll Free Number: 1800-121-7996 (Mon-Sat 9AM - 5:30PM)</p>
  1807. <p>This is a system generated e-mail, please do not reply to this mail. </p>
  1808. </div>
  1809. </td>
  1810. </tr>
  1811. </tbody>
  1812. </table>
  1813. </td>
  1814. </tr>
  1815. <tr>
  1816. <td style="padding-top:0px; padding-bottom:10px;"></td>
  1817. </tr>
  1818. <tr>
  1819. <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#3f3f3f; background:#fafafa; line-height:20px; border-bottom:2px solid black">
  1820. &nbsp;
  1821. </td>
  1822. </tr>
  1823. </tbody>
  1824. </table>
  1825. </td>
  1826. </tr>
  1827. </tbody>
  1828. </table>';
  1829. $obj['message'] = $message;
  1830. // globalfunc::sendMai($parent, $obj);
  1831. $parent->response(array('response' => 'success', 'data' => $url, 'message' => $this->page_data['success6']), 200);
  1832. }
  1833. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  1834. /* /////////////////////////////// SHARE QUOTATION //////////////////////////////////////////////// */
  1835. // private function getquotation($parent)
  1836. // {
  1837. // globalfunc::checkParamCount($parent,2);
  1838. // globalfunc::checkMethodType($parent,array('GET'));
  1839. // globalfunc::checkAuthrozation($parent,array('type'=>'user'));
  1840. // projectfunc::authorizedRole($parent,array('8','9','10','11','12','13'));
  1841. //
  1842. // $token=escape_str($parent->params[1]);
  1843. //
  1844. // //DMS_ENQUIRY_MODEL
  1845. // $check_arr=$parent->selectQuery(TABLE_QUOTATIONSHARE ,"*","sharetoken='".$token."'","1");
  1846. // if(!$check_arr['nr']>0)
  1847. // {
  1848. // $client_ip=globalfunc::getIp($parent);
  1849. // $sec=LOCK_ACCESS_MINUTES*60;
  1850. // $expiry_time=date('Y-m-d H:i:s',strtotime('-'.$sec.' seconds',strtotime(NOW)));
  1851. // $lock_qry_str="SELECT SUM(lock_count) lock_count FROM ".TABLE_LOCK_ACCESS." WHERE is_deleted='0' AND modified_on>='".$expiry_time."' AND ip='".$client_ip."' GROUP BY ip LIMIT 1";
  1852. // $lock_value=$parent->getQueryValue($lock_qry_str);
  1853. // if(count($lock_value)>0 && $lock_value[0]->lock_count>=3)
  1854. // {
  1855. // $parent->response(array('response'=>'failed', 'message'=>'Sorry Invalid Access. Access Blocked For 10 min.'), 401);
  1856. // }
  1857. // globalfunc::insertLockLog($parent,$token);
  1858. // $parent->response(array('response'=>'failed','message'=>$this->page_data['error6']),406);
  1859. // }
  1860. // $id=$check_arr['result'][0]->id;
  1861. // $model_arr=$parent->selectQuery(DMS_ENQUIRY_MODEL ,"title,title_code,variant,variant_code"," title_code='".$check_arr['result'][0]->model."' AND variant_code='".$check_arr['result'][0]->variant."' ","1");
  1862. // $check_arr['result'][0]->model_str=($check_arr['nr']>0)?$model_arr['result'][0]->title:'';
  1863. // $check_arr['result'][0]->variant_str=($check_arr['nr']>0)?$model_arr['result'][0]->variant:'';
  1864. //
  1865. // $data_arr=$check_arr['result'][0];
  1866. //
  1867. // //LOG
  1868. // $logstr='GET QUOTATION';
  1869. // globalfunc::insertUserLog($parent,$logstr,$id);
  1870. //
  1871. //
  1872. // $parent->response(array('response'=>'success','data'=>$data_arr, 'message'=>$this->page_data['success1']),200);
  1873. // }
  1874. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  1875. /* /////////////////////////////// PRICELIST //////////////////////////////////////////////// */
  1876. private function pricelist($parent)
  1877. {
  1878. globalfunc::checkParamCount($parent, 1);
  1879. globalfunc::checkMethodType($parent, array('POST'));
  1880. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  1881. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  1882. $smpin = $parent->current_user_data->smpin;
  1883. $model = escape_str($parent->_request['model']);
  1884. $REQUEST_KEYS = array('model' => 'string');
  1885. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  1886. //DMS_ENQUIRY_MODEL
  1887. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MODEL, "variant,variant_code", " title_code='" . $model . "' AND enq_yn='Y' AND status=1 GROUP BY variant_code ", "");
  1888. if (!$check_arr['nr'] > 0) {
  1889. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error15']), 406);
  1890. }
  1891. $model_arr = $check_arr['result'];
  1892. //DEALER
  1893. $check_arr = $parent->selectQuery(DMS_DEALER, "dealer_code,for_cd", "dealer_code='" . $parent->current_user_data->dealer_code . "' AND for_cd!='' AND is_deleted=0 ", "1");
  1894. if (!$check_arr['nr'] > 0) {
  1895. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error16']), 406);
  1896. }
  1897. $for_cd = $check_arr['result'][0]->for_cd;
  1898. //CALL DMS
  1899. $url = SUZ_DMS_URL;
  1900. $post = array("query" => "BEGIN pkg_smipl_star_app.sp_vehicle_model_price(:p_model, :p_for, :p_pmc, :list_cursor, :p_err_cd, :p_err_msg); END;", "params" => '[{"title":"p_model","value":"' . $model . '","type":""},{"title":"p_for","value":"' . $for_cd . '","type":""},{"title":"p_pmc","value":"2","type":""},{"title":"list_cursor","value":"","type":"cursor"},{"title":"p_err_cd","value":"","type":""},{"title":"p_err_msg","value":"","type":""}]');
  1901. $header = array('Authorization:Bearer ' . SUZ_TOKEN);
  1902. //LOG
  1903. $obj = new stdClass();
  1904. $obj->type = 'modelprice';
  1905. $obj->apirequest = $post['params'];
  1906. $log_id = projectfunc::cronLog($parent, $obj);
  1907. // $ch = curl_init();
  1908. // curl_setopt($ch, CURLOPT_URL, $url);
  1909. // curl_setopt($ch, CURLOPT_POST, 1);
  1910. // curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //Post Fields
  1911. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1912. // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1913. // $response = curl_exec($ch);
  1914. // $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  1915. // curl_close($ch);
  1916. $httpcode = '200';
  1917. $response="";
  1918. $error = 1;
  1919. $count = 0;
  1920. $vari_arr = array();
  1921. //LOG UPDATE
  1922. $obj = new stdClass();
  1923. $obj->id = $log_id;
  1924. $obj->apiresponse = $response;
  1925. projectfunc::updateCronLog($parent, $obj);
  1926. if ($httpcode == '200' && $response != '') {
  1927. $json = json_decode($response);
  1928. if (isset($json->response) && $json->response == 'success' && isset($json->data) && count($json->data) > 0) {
  1929. //LOG UPDATE
  1930. $obj = new stdClass();
  1931. $obj->id = $log_id;
  1932. $obj->insert_count = count($json->data);
  1933. $obj->status = 1;
  1934. //$obj->apiresponse=$response;
  1935. projectfunc::updateCronLog($parent, $obj);
  1936. foreach ($json->data as $res) {
  1937. $code = strtolower($res->VARIANT_CD);
  1938. $vari_arr[$code] = $res->EXSH_PRICE;
  1939. }
  1940. foreach ($model_arr as $mkey => $val) {
  1941. $error = 0;
  1942. $variant_code = strtolower($model_arr[$mkey]->variant_code);
  1943. $model_arr[$mkey]->exsh_price = (isset($vari_arr[$variant_code])) ? $vari_arr[$variant_code] : '';
  1944. $obj = new stdClass();
  1945. $obj->model = $model;
  1946. $obj->variant = $variant_code;
  1947. $obj->variantname = $model_arr[0]->variant;
  1948. //print_r($obj);
  1949. $model_arr[$mkey]->model_image = projectfunc::modelimage($parent, $obj);
  1950. }
  1951. }
  1952. if ($json->response == 'success' && $json->data->p_err_msg != '') {
  1953. $emsg = $json->data->p_err_msg;
  1954. }
  1955. }
  1956. //LOG
  1957. $logstr = 'ENQUIRY PRICE LIST';
  1958. globalfunc::insertUserLog($parent, $logstr, $id);
  1959. $parent->response(array('response' => 'success', 'data' => $model_arr, 'message' => $this->page_data['success1']), 200);
  1960. }
  1961. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  1962. /* /////////////////////////////// TEST RIDE //////////////////////////////////////////////// */
  1963. private function testride($parent)
  1964. {
  1965. globalfunc::checkParamCount($parent, 2);
  1966. globalfunc::checkMethodType($parent, array('POST'));
  1967. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  1968. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13'));
  1969. $smpin = $parent->current_user_data->smpin;
  1970. $id = escape_str($parent->params[1]);
  1971. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id", " smpin='" . $smpin . "' AND is_deleted=0 AND is_dms=1 AND id='" . $id . "'", "1");
  1972. if ($check_arr['nr'] != '1') {
  1973. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  1974. }
  1975. //CALL DMS
  1976. //LOG
  1977. $logstr = 'ENQUIRY TESTRIDE';
  1978. globalfunc::insertUserLog($parent, $logstr, $id);
  1979. $parent->response(array('response' => 'success', 'message' => $this->page_data['success1']), 200);
  1980. }
  1981. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  1982. /* /////////////////////////////// PLANNER LIST //////////////////////////////////////////////// */
  1983. private function getplannerdetails($parent, $id)
  1984. {
  1985. $list_arr = $parent->selectQuery(TABLE_ENQUIRYPLANNER, "*,DATE_FORMAT(plan_date, '%d-%m-%Y')plandate,DATE_FORMAT(plan_fromtime, '%H:%i') fromtime,DATE_FORMAT(plan_totime, '%H:%i') totime", "id='" . $id . "' AND is_deleted=0", "1");
  1986. return ($list_arr['nr']) ? $list_arr['result'][0] : new stdClass();
  1987. }
  1988. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  1989. /* /////////////////////////////// PLANNER LIST //////////////////////////////////////////////// */
  1990. private function plannerlist($parent)
  1991. {
  1992. globalfunc::checkParamCount($parent, 1);
  1993. globalfunc::checkMethodType($parent, array('POST'));
  1994. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  1995. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13', '14'));
  1996. $userid = $parent->current_user_id;
  1997. $type = escape_str($parent->_request['type']);
  1998. $monthdata = array();
  1999. $todaydata = array();
  2000. $date_arr = array();
  2001. $REQUEST_KEYS = array('type' => 'string');
  2002. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  2003. if ($type == 'month') {
  2004. $REQUEST_KEYS = array('month' => 'number', 'year' => 'number');
  2005. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  2006. $month = escape_str($parent->_request['month']);
  2007. $year = escape_str($parent->_request['year']);
  2008. if (!globalfunc::isValidDateTimeString($year . '-' . $month . '-01', 'Y-m-d', 'Asia/Kolkata')) {
  2009. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error21']), 406);
  2010. }
  2011. $start_date = date('Y-m-d', strtotime($year . '-' . $month . '-01'));
  2012. $end_date = date('Y-m-t', strtotime($year . '-' . $month . '-01'));
  2013. $temp = $start_date;
  2014. while (strtotime($temp) <= strtotime($end_date)) {
  2015. $date_str = @explode('-', $temp);
  2016. $value = $date_str[2];
  2017. $monthdata[$value] = array('date' => $temp, 'data' => array());
  2018. $temp = date('Y-m-d', strtotime('+ 1 day', strtotime($temp)));
  2019. }
  2020. $get_list_arr = $parent->selectQuery(TABLE_ENQUIRYPLANNER, "*,DATE_FORMAT(plan_date, '%d-%m-%Y')plandate,DATE_FORMAT(plan_fromtime, '%H:%i') fromtime,DATE_FORMAT(plan_totime, '%H:%i') totime", " is_deleted='0' AND userid='" . $userid . "' AND plan_date>='" . $start_date . "' AND plan_date<='" . $end_date . "' ORDER BY plan_fromtime ASC", "");
  2021. if ($get_list_arr['nr'] > 0) {
  2022. foreach ($get_list_arr['result'] as $res) {
  2023. $value = date('d', strtotime($res->plan_date));
  2024. $monthdata[$value]['data'][] = $res;
  2025. }
  2026. }
  2027. } else if ($type == 'today') {
  2028. $start_date = CUR_DATE;
  2029. $end_date = CUR_DATE;
  2030. $get_list_arr = $parent->selectQuery(TABLE_ENQUIRYPLANNER, "*,DATE_FORMAT(plan_date, '%d-%m-%Y')plandate,DATE_FORMAT(plan_fromtime, '%H:%i') fromtime,DATE_FORMAT(plan_totime, '%H:%i') totime", " is_deleted='0' AND userid='" . $userid . "' AND plan_date>='" . $start_date . "' AND plan_date<='" . $end_date . "' ORDER BY plan_fromtime ASC", "");
  2031. $todaydata = ($get_list_arr['nr'] > 0) ? $get_list_arr['result'] : array();
  2032. $monthdata = new stdClass();
  2033. } else if ($type == 'date') {
  2034. $REQUEST_KEYS = array('date' => 'date|Y-m-d');
  2035. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  2036. $date = escape_str($parent->_request['date']);
  2037. $start_date = $date;
  2038. $end_date = $date;
  2039. $get_list_arr = $parent->selectQuery(TABLE_ENQUIRYPLANNER, "*,DATE_FORMAT(plan_date, '%d-%m-%Y')plandate,DATE_FORMAT(plan_fromtime, '%H:%i') fromtime,DATE_FORMAT(plan_totime, '%H:%i') totime", " is_deleted='0' AND userid='" . $userid . "' AND plan_date>='" . $start_date . "' AND plan_date<='" . $end_date . "' ORDER BY plan_fromtime ASC", "");
  2040. $date_arr = ($get_list_arr['nr'] > 0) ? $get_list_arr['result'] : array();
  2041. } else {
  2042. $parent->response(array('response' => 'failed', 'message' => "Invalid type format"), 406);
  2043. }
  2044. $data = array('month' => $monthdata, 'today' => $todaydata, 'date' => $date_arr);
  2045. //LOG
  2046. $logstr = 'PLANNER LIST';
  2047. globalfunc::insertUserLog($parent, $logstr, $id);
  2048. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success1']), 200);
  2049. }
  2050. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  2051. /* /////////////////////////////// PLANNER INSERT //////////////////////////////////////////////// */
  2052. private function plannersave($parent)
  2053. {
  2054. globalfunc::checkParamCount($parent, 1);
  2055. globalfunc::checkMethodType($parent, array('POST'));
  2056. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  2057. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13', '14'));
  2058. $userid = $parent->current_user_id;
  2059. $REQUEST_KEYS = array('title' => 'string', 'description' => 'string', 'plandate' => 'string', 'fromtime' => 'string', 'totime' => 'string');
  2060. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  2061. $title = escape_str($parent->_request['title']);
  2062. $description = escape_str($parent->_request['description']);
  2063. $date = escape_str($parent->_request['plandate']);
  2064. $date_arr = @explode('-', $date);
  2065. $date_str = $date_arr[2] . "-" . $date_arr[1] . "-" . $date_arr[0];
  2066. $fromtime = escape_str($parent->_request['fromtime']);
  2067. $totime = escape_str($parent->_request['totime']);
  2068. if (!globalfunc::isValidDateTimeString($date_str, 'Y-m-d', 'Asia/Kolkata')) {
  2069. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error18']), 406);
  2070. }
  2071. if (!globalfunc::isValidDateTimeString($date_str . " " . $fromtime . ":00", 'Y-m-d H:i:s', 'Asia/Kolkata')) {
  2072. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error19']), 406);
  2073. }
  2074. if (!globalfunc::isValidDateTimeString($date_str . " " . $totime . ":00", 'Y-m-d H:i:s', 'Asia/Kolkata')) {
  2075. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error19']), 406);
  2076. }
  2077. $fromdatetime = $date_str . " " . $fromtime;
  2078. $todatetime = $date_str . " " . $totime;
  2079. //CHECK SLOT ALREADY EXIST
  2080. $list_arr = $parent->selectQuery(TABLE_ENQUIRYPLANNER, "*", " is_deleted='0' AND userid='" . $userid . "' AND ((plan_fromtime BETWEEN '" . $fromdatetime . "' AND '" . $todatetime . "') OR (plan_totime BETWEEN '" . $fromdatetime . "' AND '" . $todatetime . "') ) ", "1");
  2081. if ($list_arr['nr'] > 0) {
  2082. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error20']), 406);
  2083. }
  2084. $parent->executeQuery("INSERT INTO `" . TABLE_ENQUIRYPLANNER . "` (`userid`, `plan_date`, `plan_title`, plan_description, `plan_fromtime`, `plan_totime`, `created_on`, `modified_on`) VALUES ('" . $userid . "','" . $date_str . "','" . $title . "','" . $description . "', '" . $fromdatetime . "','" . $todatetime . "','" . NOW . "', '" . NOW . "')");
  2085. $id = $parent->lastInsertId();
  2086. $data = $this->getplannerdetails($parent, $id);
  2087. //LOG
  2088. $logstr = 'PLANNER INSERT';
  2089. globalfunc::insertUserLog($parent, $logstr, $id);
  2090. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success3']), 200);
  2091. }
  2092. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  2093. /* /////////////////////////////// PLANNER UPDATE //////////////////////////////////////////////// */
  2094. private function plannerupdate($parent)
  2095. {
  2096. globalfunc::checkParamCount($parent, 2);
  2097. globalfunc::checkMethodType($parent, array('POST'));
  2098. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  2099. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13', '14'));
  2100. $userid = $parent->current_user_id;
  2101. $id = escape_str($parent->params[1]);
  2102. $list_arr = $parent->selectQuery(TABLE_ENQUIRYPLANNER, "*", "id='" . $id . "' AND is_deleted='0' AND userid='" . $userid . "'", "1");
  2103. if (!$list_arr['nr'] > 0) {
  2104. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  2105. }
  2106. $REQUEST_KEYS = array('title' => 'string', 'description' => 'string', 'plandate' => 'string', 'fromtime' => 'string', 'totime' => 'string');
  2107. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  2108. $title = escape_str($parent->_request['title']);
  2109. $description = escape_str($parent->_request['description']);
  2110. $date = escape_str($parent->_request['plandate']);
  2111. $date_arr = @explode('-', $date);
  2112. $date_str = $date_arr[2] . "-" . $date_arr[1] . "-" . $date_arr[0];
  2113. $fromtime = escape_str($parent->_request['fromtime']);
  2114. $totime = escape_str($parent->_request['totime']);
  2115. if (!globalfunc::isValidDateTimeString($date_str, 'Y-m-d', 'Asia/Kolkata')) {
  2116. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error18']), 406);
  2117. }
  2118. if (!globalfunc::isValidDateTimeString($date_str . " " . $fromtime . ":00", 'Y-m-d H:i:s', 'Asia/Kolkata')) {
  2119. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error19']), 406);
  2120. }
  2121. if (!globalfunc::isValidDateTimeString($date_str . " " . $totime . ":00", 'Y-m-d H:i:s', 'Asia/Kolkata')) {
  2122. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error19']), 406);
  2123. }
  2124. $fromdatetime = $date_str . " " . $fromtime;
  2125. $todatetime = $date_str . " " . $totime;
  2126. //CHECK SLOT ALREADY EXIST
  2127. $list_arr = $parent->selectQuery(TABLE_ENQUIRYPLANNER, "*", " is_deleted='0' AND id!='" . $id . "' AND userid='" . $userid . "' AND ((plan_fromtime BETWEEN '" . $fromdatetime . "' AND '" . $todatetime . "') OR (plan_totime BETWEEN '" . $fromdatetime . "' AND '" . $todatetime . "') ) ", "1");
  2128. if ($list_arr['nr'] > 0) {
  2129. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error20']), 406);
  2130. }
  2131. $parent->executeQuery("UPDATE " . TABLE_ENQUIRYPLANNER . " SET `plan_date`='" . $date_str . "', `plan_title`='" . $title . "', plan_description='" . $description . "', `plan_fromtime`='" . $fromdatetime . "', `plan_totime`='" . $todatetime . "', `modified_on`='" . NOW . "' WHERE id='" . $id . "'");
  2132. $data = $this->getplannerdetails($parent, $id);
  2133. //LOG
  2134. $logstr = 'PLANNER UPDATE';
  2135. globalfunc::insertUserLog($parent, $logstr, $id);
  2136. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success4']), 200);
  2137. }
  2138. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  2139. /* /////////////////////////////// PLANNER DELETE //////////////////////////////////////////////// */
  2140. private function plannerdelete($parent)
  2141. {
  2142. globalfunc::checkParamCount($parent, 2);
  2143. globalfunc::checkMethodType($parent, array('DELETE'));
  2144. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  2145. projectfunc::authorizedRole($parent, array('8', '9', '10', '11', '12', '13', '14'));
  2146. $userid = $parent->current_user_id;
  2147. $id = escape_str($parent->params[1]);
  2148. $list_arr = $parent->selectQuery(TABLE_ENQUIRYPLANNER, "*", "id='" . $id . "' AND is_deleted='0' AND userid='" . $userid . "'", "1");
  2149. if (!$list_arr['nr'] > 0) {
  2150. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  2151. }
  2152. $parent->executeQuery("UPDATE " . TABLE_ENQUIRYPLANNER . " SET is_deleted=1, `modified_on`='" . NOW . "' WHERE id='" . $id . "'");
  2153. //LOG
  2154. $logstr = 'PLANNER DELETE';
  2155. globalfunc::insertUserLog($parent, $logstr, $id);
  2156. $parent->response(array('response' => 'success', 'message' => $this->page_data['success5']), 200);
  2157. }
  2158. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  2159. /* /////////////////////////////// PLANNER TIMER //////////////////////////////////////////////// */
  2160. private function plannertimer($parent)
  2161. {
  2162. globalfunc::checkParamCount($parent, 1);
  2163. globalfunc::checkMethodType($parent, array('GET'));
  2164. $t_arr = array("00", "30");
  2165. for ($i = 6; $i < 23; $i++) {
  2166. $m = ($i < 10) ? "0" . $i : $i;
  2167. foreach ($t_arr as $tstr) {
  2168. //$t=($tstr<10)?"0".$tstr:$tstr;
  2169. $tvalue = $m . ":" . $tstr;
  2170. $time_arr[] = array('title' => $tvalue, 'title_code' => $tvalue);
  2171. }
  2172. }
  2173. $data = $time_arr;
  2174. //LOG
  2175. $logstr = 'PLANNER TIMER';
  2176. globalfunc::insertUserLog($parent, $logstr, $id);
  2177. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success1']), 200);
  2178. }
  2179. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  2180. /* /////////////////////////////// SMPIN DEALER //////////////////////////////////////////////// */
  2181. private function smpindealer($parent)
  2182. {
  2183. globalfunc::checkParamCount($parent, 2);
  2184. globalfunc::checkMethodType($parent, array('GET'));
  2185. $smpin = escape_str($parent->params[1]);
  2186. $dse_details = $this->getdsedetails($parent, $smpin);
  2187. $dealer_arr = $parent->selectQuery(DMS_DEALER, "dealer_code,dealer_name,phone,email,address,state,city", " dealer_code='" . $dse_details->dealer_code . "' ", "1");
  2188. $data = ($dealer_arr['nr'] > 0) ? $dealer_arr['result'] : array();
  2189. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success1']), 200);
  2190. }
  2191. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  2192. /* /////////////////////////////// DEALER //////////////////////////////////////////////// */
  2193. private function dealer($parent)
  2194. {
  2195. globalfunc::checkParamCount($parent, 2);
  2196. globalfunc::checkMethodType($parent, array('GET'));
  2197. $dealer_code = escape_str($parent->params[1]);
  2198. $dealer_arr = $parent->selectQuery(DMS_DEALER, "dealer_code,dealer_name,phone,email,address,state,city", " dealer_code='" . $dealer_code . "' ", "1");
  2199. $data = ($dealer_arr['nr'] > 0) ? $dealer_arr['result'] : array();
  2200. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success1']), 200);
  2201. }
  2202. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  2203. /* /////////////////////////////// PLANNER TIMER //////////////////////////////////////////////// */
  2204. private function getdsedetails($parent, $smpin)
  2205. {
  2206. $data = $parent->selectQuery(DMS_EMPLOYEE, "*", "smpin='" . $smpin . "' AND status=1", "1");
  2207. if (!$data['nr'] > 0) {
  2208. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error1']), 406);
  2209. }
  2210. return $data['result'][0];
  2211. }
  2212. /* /////////////////////////////// COMMON //////////////////////////////////////////////// */
  2213. private function followupcommon($parent)
  2214. {
  2215. globalfunc::checkMethodType($parent, array('GET'));
  2216. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  2217. $purpose_data = $parent->selectQuery(DMS_ENQUIRY_PURPOSE, "id,title,title_code", " status='1'", "");
  2218. $modeofcontact_data = $parent->selectQuery(DMS_ENQUIRY_MODE, "title,title_code", " status='1' ", "");
  2219. $purpose_arr = ($purpose_data['nr'] > 0) ? $purpose_data['result'] : array();
  2220. $modeofcontact_arr = ($modeofcontact_data['nr'] > 0) ? $modeofcontact_data['result'] : array();
  2221. $t_arr = array("00", "30");
  2222. for ($i = 9; $i < 19; $i++) {
  2223. $m = ($i < 10) ? "0" . $i : $i;
  2224. foreach ($t_arr as $tstr) {
  2225. //$t=($tstr<10)?"0".$tstr:$tstr;
  2226. $tvalue = $m . ":" . $tstr;
  2227. $time_arr[] = array('title' => $tvalue, 'title_code' => $tvalue);
  2228. }
  2229. }
  2230. //LOST REASON
  2231. $lostreason = array();
  2232. $reason_data = $parent->selectQuery(DMS_ENQUIRY_REASON, "list_desc title,list_code title_code", " list_flag='L' AND status=1", "");
  2233. if ($reason_data['nr'] > 0) {
  2234. foreach ($reason_data['result'] as $rkey => $res) {
  2235. $subreason_data = $parent->selectQuery(DMS_ENQUIRY_SUBREASON, "list_desc title,list_code title_code", " reason_code='" . $res->title_code . "' AND status=1", "");
  2236. $reason_data['result'][$rkey]->subreason = ($subreason_data['nr'] > 0) ? $subreason_data['result'] : array();
  2237. }
  2238. $lostreason = $reason_data['result'];
  2239. }
  2240. //POSTPONED REASON
  2241. $reason_data = $parent->selectQuery(DMS_ENQUIRY_REASON, "list_desc title,list_code title_code", " list_flag='E' AND status=1", "");
  2242. $postponedreason = ($reason_data['nr'] > 0) ? $reason_data['result'] : array();
  2243. //LOST MODEL
  2244. $lost_data = $parent->selectQuery(DMS_ENQUIRY_LOSTMODEL, "cmodel_desc title,cmodel_cd title_code", " status=1", "");
  2245. $lost_model = ($lost_data['nr'] > 0) ? $lost_data['result'] : array();
  2246. $data = array('purpose' => $purpose_arr, 'time' => $time_arr, 'modeofcontact' => $modeofcontact_arr, 'lostreason' => $lostreason, 'postponedreason' => $postponedreason, 'lost_model' => $lost_model);
  2247. //LOG
  2248. $logstr = 'ENQUIRY FOLLOWUP COMMON';
  2249. globalfunc::insertUserLog($parent, $logstr);
  2250. $parent->response(array('response' => 'success', 'data' => $data, 'message' => $this->page_data['success1']), 200);
  2251. }
  2252. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  2253. /* ///////////////////////// TESTRIDE UPDATE //////////////////// */
  2254. private function testrideupdate($parent)
  2255. {
  2256. globalfunc::checkParamCount($parent, 1);
  2257. globalfunc::checkMethodType($parent, array('POST'));
  2258. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  2259. $REQUEST_KEYS = array('id' => 'number', 'license' => 'string', 'license_expiry' => 'date|d-m-Y');
  2260. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  2261. $id = escape_str($parent->_request['id']);
  2262. $license = escape_str($parent->_request['license']);
  2263. $license_expiry_str = escape_str($parent->_request['license_expiry']);
  2264. $date_arr = @explode("-", $license_expiry_str);
  2265. $license_expiry = $date_arr[2] . "-" . $date_arr[1] . "-" . $date_arr[0];
  2266. //CHECK SLOT ALREADY EXIST
  2267. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id,mobile ", " id='" . $id . "' AND is_dms=1 AND is_deleted=0 ", "1");
  2268. if (!$check_arr['nr'] > 0) {
  2269. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  2270. }
  2271. $otp = globalfunc::generateOTP();
  2272. $parent->executeQuery("UPDATE `" . DMS_ENQUIRY_MASTER . "` SET license='" . $license . "',license_expiry='" . $license_expiry . "',otp='" . $otp . "' WHERE id='" . $id . "' ");
  2273. $mobile = $check_arr['result'][0]->mobile;
  2274. $sms_message = "Your one time password is " . $otp;
  2275. // globalfunc::sendSMS($parent, $mobile, $sms_message);
  2276. //LOG
  2277. $logstr = 'TESTRIDE UPDATE';
  2278. globalfunc::insertUserLog($parent, $logstr, $id);
  2279. $parent->response(array('response' => 'success', 'message' => $this->page_data['success1']), 200);
  2280. }
  2281. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  2282. /* ///////////////////////// TESTRIDE OTP //////////////////// */
  2283. private function testrideotp($parent)
  2284. {
  2285. globalfunc::checkParamCount($parent, 1);
  2286. globalfunc::checkMethodType($parent, array('POST'));
  2287. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  2288. $REQUEST_KEYS = array('id' => 'number', 'otp' => 'number');
  2289. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  2290. $id = escape_str($parent->_request['id']);
  2291. $otp = escape_str($parent->_request['otp']);
  2292. //CHECK SLOT ALREADY EXIST
  2293. $check_arr = $parent->selectQuery(DMS_ENQUIRY_MASTER, "id,otp ", " id='" . $id . "' AND is_dms=1 AND is_deleted=0 ", "1");
  2294. if (!$check_arr['nr'] > 0) {
  2295. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error6']), 406);
  2296. }
  2297. if ($otp != $check_arr['result'][0]->otp) {
  2298. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error3']), 406);
  2299. }
  2300. $parent->executeQuery("UPDATE `" . DMS_ENQUIRY_MASTER . "` SET is_testride=1 WHERE id='" . $id . "' ");
  2301. //LOG
  2302. $logstr = 'TESTRIDE OTP';
  2303. globalfunc::insertUserLog($parent, $logstr, $id);
  2304. $parent->response(array('response' => 'success', 'message' => $this->page_data['success1']), 200);
  2305. }
  2306. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  2307. }