PageRenderTime 68ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/lms_debug/protected/controllers/LeadsController_17_nov_2014.php

https://gitlab.com/badelal143/lms_debug
PHP | 3431 lines | 2832 code | 318 blank | 281 comment | 521 complexity | 0ece98c313a62f12a06b6b44fce1961b MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0
  1. <?php
  2. class LeadsController extends Controller
  3. {
  4. const SHARED_TITLE = "Admin Panel";
  5. /**
  6. * Declares class-based actions.
  7. */
  8. public function filters()
  9. {
  10. return array( 'accessControl',array(
  11. 'CHttpCacheFilter + view',
  12. 'cacheControl' => " max-age=604800, must-revalidate",
  13. ) ); // perform access control for CRUD operations
  14. }
  15. public function actions()
  16. {
  17. return array(
  18. // captcha action renders the CAPTCHA image displayed on the contact page
  19. 'captcha'=>
  20. array(
  21. 'class'=>'CCaptchaAction',
  22. 'backColor'=>0xFFFFFF,
  23. ),
  24. // page action renders "static" pages stored under 'protected/views/site/pages'
  25. // They can be accessed via: index.php?r=site/page&view=FileName
  26. 'page'=>array(
  27. 'class'=>'CViewAction',
  28. ),
  29. );
  30. }
  31. /**
  32. * This is the 'roles' action that is invoked
  33. * when an action is not explicitly requested by users.
  34. */
  35. public function actionlead_welcome()
  36. {
  37. $model = new WelcomeMaster();
  38. $model = WelcomeMaster::model()->find("moduleId = '1' ");
  39. $this->render('lead_welcome',array('model'=>$model));
  40. }
  41. /**
  42. * This is the 'roles' action that is invoked
  43. * when an action is not explicitly requested by users.
  44. */
  45. public function actionlead_list()
  46. {
  47. $relationManager = $_SESSION['relationalManager'];
  48. $managerMemberId = implode(",",array_unique(@$relationManager));
  49. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  50. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
  51. } else {
  52. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  53. }
  54. //$modelLead = Lead::model()->findAll(" $querycondition ");
  55. $this->render('lead_list');
  56. }
  57. /**
  58. * This is the 'lead_list_allocator' action that is invoked
  59. * when an action is not explicitly requested by users.
  60. */
  61. public function actionlead_list_allocator()
  62. {
  63. // renders the view file 'protected/views/site/index.php'
  64. // using the default layout 'protected/views/layouts/main.php'
  65. $this->render('lead_list_allocator');
  66. }
  67. /**
  68. * This is the 'lead_list_allocator' action that is invoked
  69. * when an action is not explicitly requested by users.
  70. */
  71. public function actionfollowup_lead_list()
  72. {
  73. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  74. $relationManager = $_SESSION['relationalManager'];
  75. $managerMemberId = implode(",",array_unique(@$relationManager));
  76. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  77. $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
  78. } else {
  79. $querycondition = " startDate = '".@$today12PM."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  80. }
  81. //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
  82. $this->render('followup_lead_list');
  83. }
  84. public function actionfollowup_overall_lead_list()
  85. {
  86. $relationManager = $_SESSION['relationalManager'];
  87. $managerMemberId = implode(",",array_unique(@$relationManager));
  88. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  89. $querycondition = ' status="Pending" ';
  90. } else {
  91. $querycondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  92. }
  93. //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
  94. $this->render('followup_overall_lead_list');
  95. }
  96. /**
  97. * This is the 'lead_list_allocator' action that is invoked
  98. * when an action is not explicitly requested by users.
  99. */
  100. public function actionlead_list_tc()
  101. {
  102. // renders the view file 'protected/views/site/index.php'
  103. // using the default layout 'protected/views/layouts/main.php'
  104. $this->render('lead_list_tc');
  105. }
  106. /**
  107. * This is the 'lead_list_allocator' action that is invoked
  108. * when an action is not explicitly requested by users.
  109. */
  110. public function actionjunk_lead_list()
  111. {
  112. //$modelLead = Lead::model()->findAll(" leadStatusId = '36' ");
  113. $this->render('junk_lead_list');
  114. }
  115. /**
  116. * This is the 'lead_list_allocator' action that is invoked
  117. * when an action is not explicitly requested by users.
  118. */
  119. public function actionduplicate_lead_list()
  120. {
  121. //$modelLead = Lead::model()->findAll(" leadStatusId = '10' ");
  122. $this->render('duplicate_lead_list');
  123. }
  124. public function actionclose_lead_list()
  125. {
  126. //$modelLead = Lead::model()->findAll(" leadStatusId = '7' ");
  127. $this->render('close_lead_list');
  128. }
  129. /**
  130. * This is the 'lead_list_allocator' action that is invoked
  131. * when an action is not explicitly requested by users.
  132. */
  133. public function actionallocated_lead_list()
  134. {
  135. $relationManager = $_SESSION['relationalManager'];
  136. $managerMemberId = implode(",",array_unique(@$relationManager));
  137. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  138. $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
  139. } else {
  140. $querycondition = " currentAllocatedId >0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  141. }
  142. //$modelLead = Lead::model()->findAll(" $querycondition ");
  143. $this->render('allocated_lead_list');
  144. }
  145. /**
  146. * This is the 'lead_list_allocator' action that is invoked
  147. * when an action is not explicitly requested by users.
  148. */
  149. public function actionleads_details()
  150. {
  151. // renders the view file 'protected/views/site/index.php'
  152. // using the default layout 'protected/views/layouts/main.php'
  153. //for follow up
  154. $parser = new CHtmlPurifier();
  155. if(isset($_POST['LeadFollowup'])){
  156. if(isset($_POST['LeadFollowup']['chkActionValid']) && @$_POST['LeadFollowup']['chkActionValid']==1){
  157. $res = $this->actionlead_followup(@$_POST['LeadFollowup'],$parser->purify(intval(@$_POST['Lead']['leadStatusId'])));
  158. $decodeRes = json_decode($res);
  159. if(@$decodeRes->status == 'success'){
  160. echo CJSON::encode(array(
  161. 'status'=>'success'
  162. ));
  163. } else {
  164. echo $res;
  165. }
  166. }
  167. }
  168. $leadFollDesc = @$_POST['LeadFollowup']['description'];
  169. // end of for follow ups
  170. $leadId = $parser->purify(intval(@$_GET['leadId']));
  171. $actionId = $parser->purify(intval(@$_REQUEST['actionId']));
  172. $actionmodel=LeadFollowup::model()->findByPk($actionId);
  173. $model = new Lead();
  174. $this->performAjaxValidation($model);
  175. $model->scenario = 'Lead';
  176. $managerMemberId = implode(",",$_SESSION['relationalManager']);
  177. $chkAllocatedLeads = $managerMemberId?Lead::model()->findAll(array("select"=>" leadId","condition"=>" leadStatusId != '26' AND leadStatusId != '25' AND currentAllocatedId IN (".@$managerMemberId.") ")):'0';
  178. $allocatedArr=array();
  179. foreach($chkAllocatedLeads as $key=>$value){
  180. $allocatedArr[]=$chkAllocatedLeads[$key]->leadId;
  181. }
  182. //print_r($allocatedArr);
  183. //die;
  184. /*if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin'){
  185. if(!in_array($leadId,$allocatedArr)){
  186. $this->redirect(array('leads/lead_list'));
  187. }
  188. }*/
  189. if(!empty($leadId)){
  190. $model=Lead::model()->findByPk($leadId);
  191. $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
  192. if(count($chkrecentlyViewed) == 0){
  193. $recentlyViewed = new recentlyViewed;
  194. $recentlyViewed->setAttributes(array(
  195. 'userId' => Yii::app()->session->get('id'),
  196. 'leadId' => $leadId,
  197. 'moduleId' => 0,
  198. 'updatedOn' => $_SESSION['id'],
  199. 'updatedBy' => $_SESSION['id'],
  200. ));
  201. $recentlyViewed->save(false);
  202. }
  203. }
  204. if(isset($_POST['Lead']))
  205. {
  206. if($_POST['LeadFollowup']['startDate']!='') {
  207. $finalLeadDesc = @$leadFollDesc;
  208. } else {
  209. $finalLeadDesc = @$_POST['Lead']['leadDescription'];
  210. }
  211. $model->setAttributes(array(
  212. 'updatedOn' => time(), //additional
  213. 'updatedBy' => $_SESSION['id'], //additional
  214. 'status' => 'Active', //additional //additional
  215. 'leadDescription' => @$finalLeadDesc, //additional //additional
  216. ));
  217. $prevLeadStatusId=$model->leadStatusId;
  218. foreach($_POST['Lead'] as $name=>$value)
  219. {
  220. if($model->leadStatusId==''){
  221. $model->leadStatusId=$model->leadStatusParentId;
  222. }
  223. if($model->email=='Email'){
  224. $model->email='';
  225. }
  226. if($model->name=='Name'){
  227. $model->name='';
  228. }
  229. if($model->address=='Address'){
  230. $model->address='';
  231. }
  232. if($model->ws_proposalid=='Proposal No.'){
  233. $model->ws_proposalid='';
  234. }
  235. if($model->children=="Children (Less than 25 Yrs)"){
  236. $model->children='';
  237. }
  238. if($model->ageGroup=="Age of eldest member"){
  239. $model->ageGroup='';
  240. }
  241. if($model->leadDescription=="Lead Description"){
  242. $model->leadDescription='';
  243. }
  244. if($model->leadStatusId==''){
  245. $model->leadStatusId=$prevLeadStatusId;
  246. }
  247. if(@$leadId!='' && $model->leadStatusId!='34' && @$model->leadStatusId!='35'){
  248. $model->isRead='yes';
  249. }
  250. if(is_array($value)){
  251. $value = '';
  252. } else {
  253. $value = $value;
  254. }
  255. $model->$name=$parser->purify($value);
  256. }
  257. if($model->leadStatusParentId=='1'){
  258. $model->salesClosedUpdatedOn=time();
  259. }
  260. $fetchAgentDetails=LeadSourceMaster::model()->findByPk($model->leadSourceId);
  261. $model->agentId = @$fetchAgentDetails->leadSourceCode;
  262. $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
  263. if(@$leadId!='' && $model->leadStatusId!='34'){
  264. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  265. }
  266. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
  267. if($model->leadStatusId=='1'){
  268. $model->scenario = 'salesclosed';
  269. }
  270. if(count($chkStatusMandatoryOrNot) > 0){
  271. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  272. if($condMandatory == 'No'){
  273. if($model->validate(array('mobile'))){
  274. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  275. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  276. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  277. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  278. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  279. $modelHistory = new LeadHistory();
  280. $modelHistory->scenario = 'LeadHistory';
  281. $modelHistory->setAttributes(array(
  282. 'leadId' => @$leadId, //additional data you want to insert
  283. 'updatedOn' => time(), //additional
  284. 'updatedBy' => $_SESSION['id'], //additional
  285. 'status' => 'Active', //additional
  286. 'leadDescription' => @$finalLeadDesc,
  287. ));
  288. foreach($_POST['Lead'] as $name1=>$value1)
  289. {
  290. if($modelHistory->leadStatusId==''){
  291. $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
  292. }
  293. if(@$_POST['LeadFollowup']['description']=='Description'){
  294. $activitydesc = '';
  295. } else {
  296. $activitydesc = @$_POST['LeadFollowup']['description'];
  297. }
  298. $modelHistory->activityDescription=@$activitydesc;
  299. if($model->leadStatusId==''){
  300. $model->leadStatusId=2;
  301. }
  302. if($modelHistory->email=='Email'){
  303. $modelHistory->email='';
  304. }
  305. if($modelHistory->name=='Name'){
  306. $modelHistory->name='';
  307. }
  308. if($modelHistory->address=='Address'){
  309. $modelHistory->address='';
  310. }
  311. if($modelHistory->leadDescription=="Lead Description"){
  312. $modelHistory->leadDescription='';
  313. }
  314. if($modelHistory->children=="Children (Less than 25 Yrs)"){
  315. $modelHistory->children='';
  316. }
  317. if($modelHistory->ageGroup=="Age of eldest member"){
  318. $modelHistory->ageGroup='';
  319. }
  320. if(is_array($value1)){
  321. $value1 = '';
  322. } else {
  323. $value1 = $value1;
  324. }
  325. $modelHistory->$name1=$parser->purify($value1);
  326. }
  327. $model->save(false);
  328. $modelHistory->save();
  329. CJSON::encode(array(
  330. 'status'=>'success'
  331. ));
  332. Yii::app()->end();
  333. }
  334. }
  335. }
  336. $model->save();
  337. if($model->validate()){
  338. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  339. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  340. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  341. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  342. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  343. $modelHistory = new LeadHistory();
  344. $modelHistory->scenario = 'LeadHistory';
  345. $modelHistory->setAttributes(array(
  346. 'leadId' => @$leadId, //additional data you want to insert
  347. 'updatedOn' => time(), //additional
  348. 'updatedBy' => $_SESSION['id'], //additional
  349. 'status' => 'Active', //additional
  350. 'leadDescription' => @$finalLeadDesc,
  351. ));
  352. foreach($_POST['Lead'] as $name1=>$value1)
  353. {
  354. if($modelHistory->leadStatusId==''){
  355. $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
  356. }
  357. $modelHistory->activityDescription=@$_POST['LeadFollowup']['description'];
  358. if($model->leadStatusId==''){
  359. $model->leadStatusId=2;
  360. }
  361. if(is_array($value1)){
  362. $value1 = '';
  363. } else {
  364. $value1 = $value1;
  365. }
  366. $modelHistory->$name1=$parser->purify($value1);
  367. }
  368. $modelHistory->save();
  369. echo CJSON::encode(array(
  370. 'status'=>'success'
  371. ));
  372. Yii::app()->end();
  373. //Yii::app()->end();
  374. //die;
  375. //$this->redirect(array('leads/leads_details'));
  376. } else {
  377. @$error = CActiveForm::validate(@$model);
  378. if($error!='[]')
  379. echo @$error;
  380. Yii::app()->end();
  381. //$this->render('leads_details',array('model'=>$model));
  382. }
  383. } else {
  384. $this->render('leads_details',array('model'=>@$model,'actionmodel'=>@$actionmodel,'quotesmobile'=>@$model->mobile));
  385. }
  386. }
  387. protected function performAjaxValidation($models)
  388. {
  389. if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')
  390. {
  391. echo CActiveForm::validate($models);
  392. Yii::app()->end();
  393. }
  394. }
  395. /**
  396. * This is the 'lead_list_allocator' action that is invoked
  397. * when an action is not explicitly requested by users.
  398. */
  399. public function actionlead_followup()
  400. {
  401. $actionId = @$_REQUEST['actionId'];
  402. $model = new LeadFollowup();
  403. $model->scenario = 'LeadFollowup';
  404. if(isset($actionId) && !empty($actionId)){
  405. $model=LeadFollowup::model()->findByPk($actionId);
  406. } else {
  407. }
  408. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  409. $model->scenario = 'LeadFollowupTask';
  410. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  411. $model->scenario = 'LeadFollowup';
  412. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  413. $model->scenario = 'LeadFollowup';
  414. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  415. $model->scenario = 'LeadFollowupNotes';
  416. }
  417. $parser = new CHtmlPurifier();
  418. $this->performAjaxValidation($model);
  419. if(isset($_POST['LeadFollowup']))
  420. {
  421. $userId = $_POST['LeadFollowup']['userId'];
  422. $followupstartdatewithtime = strtotime(@$_POST['LeadFollowup']['startDate'])+(@$_POST['LeadFollowup']['hour']*60*60)+(@$_POST['LeadFollowup']['minutes']*60);
  423. $model->setAttributes(array(
  424. 'createdOn' => time(), //additional data you want to insert
  425. 'updatedOn' => time(), //additional
  426. 'updatedBy' => @$userId, //additional
  427. 'createdBy' => @$userId, //additional
  428. 'status' => 'Pending', //additional
  429. ));
  430. foreach($_POST['LeadFollowup'] as $name=>$value)
  431. {
  432. if(is_array($value)){
  433. $value = '';
  434. } else {
  435. $value = $value;
  436. }
  437. $model->$name=$parser->purify($value);
  438. }
  439. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  440. $model->startDateWithTime=@$followupstartdatewithtime;
  441. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  442. $prefix=substr(time(),0,5);
  443. $folder = 'siteupload/';
  444. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  445. if($model->notesFile !='')
  446. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  447. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  448. }
  449. if(@$_POST['LeadFollowup']['startDate']!='') {
  450. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  451. $model->startDate=@$startDateVal;
  452. }
  453. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  454. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  455. $model->taskDueDate=@$taskDueDateVal;
  456. }
  457. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  458. $model->taskCompleted='yes';
  459. }
  460. if($model->validate()){
  461. $checkForSameDateExistsOrNot=LeadFollowup::model()->findAll(" leadId='".@$_POST['LeadFollowup']['leadId']."' and startDate <= '".$model->startDate."' and userId = '".@$userId."' and createdBy = '".@$userId."' ");
  462. if(count(@$checkForSameDateExistsOrNot) > 0){
  463. $update = Yii::app()->db->createCommand("UPDATE leadFollowup SET taskCompleted = 'yes',status = 'Completed' WHERE startDate <= '".$model->startDate."' and userId = '".@$userId."' and createdBy = '".@$userId."' and leadId='".@$_POST['LeadFollowup']['leadId']."' ")->execute();
  464. }
  465. $model->save();
  466. $leadId = $_POST['LeadFollowup']['leadId'];
  467. return CJSON::encode(array(
  468. 'status'=>'success'
  469. ));
  470. Yii::app()->end();
  471. } else {
  472. $error = CActiveForm::validate($model);
  473. if($error!='[]')
  474. return $error;
  475. Yii::app()->end();
  476. }
  477. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  478. }
  479. $this->redirect(array('leads/lead_list'));
  480. }
  481. /**
  482. * This is the 'lead_list_allocator' action that is invoked
  483. * when an action is not explicitly requested by users.
  484. */
  485. public function actionlead_followupcalender()
  486. {
  487. $actionId = @$_REQUEST['actionId'];
  488. $model = new LeadFollowup();
  489. $model->scenario = 'LeadFollowup';
  490. if(isset($actionId) && !empty($actionId)){
  491. $model=LeadFollowup::model()->findByPk($actionId);
  492. } else {
  493. }
  494. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  495. $model->scenario = 'LeadFollowupTask';
  496. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  497. $model->scenario = 'LeadFollowup';
  498. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  499. $model->scenario = 'LeadFollowup';
  500. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  501. $model->scenario = 'LeadFollowupNotes';
  502. }
  503. $this->performAjaxValidation($model);
  504. if(isset($_POST['LeadFollowup']))
  505. {
  506. $userId = $_POST['LeadFollowup']['userId'];
  507. $model->setAttributes(array(
  508. 'createdOn' => time(), //additional data you want to insert
  509. 'updatedOn' => time(), //additional
  510. 'updatedBy' => @$userId, //additional
  511. 'createdBy' => @$userId, //additional
  512. 'status' => 'Pending', //additional
  513. ));
  514. foreach($_POST['LeadFollowup'] as $name=>$value)
  515. {
  516. $model->$name=$value;
  517. }
  518. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  519. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  520. $prefix=substr(time(),0,5);
  521. $folder = 'siteupload/';
  522. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  523. if($model->notesFile !='')
  524. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  525. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  526. }
  527. if(@$_POST['LeadFollowup']['startDate']!='') {
  528. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  529. $model->startDate=@$startDateVal;
  530. }
  531. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  532. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  533. $model->taskDueDate=@$taskDueDateVal;
  534. }
  535. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  536. $model->taskCompleted='yes';
  537. }
  538. if($model->validate()){
  539. $model->save();
  540. $leadId = $_POST['LeadFollowup']['leadId'];
  541. echo CJSON::encode(array(
  542. 'status'=>'success'
  543. ));
  544. Yii::app()->end();
  545. } else {
  546. $error = CActiveForm::validate($model);
  547. if($error!='[]')
  548. return $error;
  549. Yii::app()->end();
  550. }
  551. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  552. }
  553. $this->redirect(array('leads/lead_list'));
  554. }
  555. public function actionlead_contacts()
  556. {
  557. // renders the view file 'protected/views/site/index.php'
  558. // using the default layout 'protected/views/layouts/main.php'
  559. $model = new LeadContacts();
  560. $model->scenario = 'LeadContacts';
  561. $this->performAjaxValidation($model);
  562. if(!empty($_GET['contactId']))
  563. {
  564. $leadContactId=$_GET['leadContactId'];
  565. $model=LeadContacts::model()->findByPk($leadContactId);
  566. }
  567. if(!empty($_POST['LeadContacts']['leadContactId']))
  568. {
  569. $leadContactId=$_POST['LeadContacts']['leadContactId'];
  570. $model=LeadContacts::model()->findByPk($leadContactId);
  571. }
  572. if(isset($_POST['LeadContacts']))
  573. {
  574. $userId = $_POST['LeadContacts']['userId'];
  575. $leadId = $_POST['LeadContacts']['leadId'];
  576. $model->setAttributes(array(
  577. 'createdOn' => time(), //additional data you want to insert
  578. 'updatedOn' => time(), //additional
  579. 'updatedBy' => @$userId, //additional
  580. 'createdBy' => @$userId, //additional
  581. 'status' => 'Active', //additional
  582. ));
  583. foreach($_POST['LeadContacts'] as $name=>$value)
  584. {
  585. $model->$name=$value;
  586. }
  587. if($model->validate()){
  588. $model->save();
  589. echo CJSON::encode(array(
  590. 'status'=>'success'
  591. ));
  592. Yii::app()->end();
  593. } else {
  594. $error = CActiveForm::validate($model);
  595. if($error!='[]')
  596. echo $error;
  597. Yii::app()->end();
  598. }
  599. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  600. }
  601. $this->redirect(array('leads/lead_list'));
  602. }
  603. public function actionChangeContactStatus()
  604. {
  605. $Id=$_REQUEST['contactId'];
  606. $leadId=$_REQUEST['leadId'];
  607. $status=$_REQUEST['status'];
  608. if(isset($status)&&($status=='Inactive')){
  609. $status="Active";
  610. } else {
  611. $status="Inactive";
  612. }
  613. if(!empty($Id))
  614. {
  615. $model=LeadContacts::model()->findByPk($Id);
  616. }
  617. else
  618. {
  619. $model = LeadContacts::model()->findAll();
  620. }
  621. $model->status=$status;
  622. $model->save();
  623. $this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  624. }
  625. /**
  626. * This is the 'roles' action that is invoked
  627. * when an action is not explicitly requested by users.
  628. */
  629. public function actioncreate_lead()
  630. {
  631. $model=new Lead();
  632. $model->scenario = 'Lead';
  633. if(!empty($_GET['leadId']))
  634. {
  635. $leadId=$_GET['leadId'];
  636. $model=Lead::model()->findByPk($leadId);
  637. $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
  638. if(count($chkrecentlyViewed) == 0){
  639. $recentlyViewed = new recentlyViewed;
  640. $recentlyViewed->setAttributes(array(
  641. 'userId' => Yii::app()->session->get('id'),
  642. 'leadId' => $leadId,
  643. 'moduleId' => 0,
  644. 'createdOn' => time(),
  645. 'updatedOn' => time(),
  646. 'updatedBy' => time(),
  647. 'createdBy' => time(),
  648. ));
  649. $recentlyViewed->save(false);
  650. }
  651. }
  652. if(!empty($_POST['Lead']['leadId']))
  653. {
  654. $leadId=$_POST['Lead']['leadId'];
  655. $model=Lead::model()->findByPk($leadId);
  656. }
  657. if(isset($_POST['Lead']))
  658. {
  659. $model->setAttributes(array(
  660. 'createdOn' => time(), //additional data you want to insert
  661. 'updatedOn' => time(), //additional
  662. 'updatedBy' => Yii::app()->session->get('id'), //additional
  663. 'createdBy' => Yii::app()->session->get('id'),
  664. ));
  665. foreach($_POST['Lead'] as $name=>$value)
  666. {
  667. $model->$name=$value;
  668. if($model->leadStatusId==''){
  669. $model->leadStatusId=$model->leadStatusParentId;
  670. }
  671. if($model->leadStatusId==''){
  672. $model->leadStatusId=34;
  673. }
  674. if($model->mobile=='Mobile*'){
  675. $model->mobile='';
  676. }
  677. if($model->email=='Email'){
  678. $model->email='';
  679. }
  680. if($model->name=='Name'){
  681. $model->name='';
  682. }
  683. if($model->address=='Address'){
  684. $model->address='';
  685. }
  686. if($model->children=="Children (Less than 25 Yrs)"){
  687. $model->children='';
  688. }
  689. if($model->ageGroup=="Age of eldest member"){
  690. $model->ageGroup='';
  691. }
  692. }
  693. if($model->leadStatusParentId=='1'){
  694. $model->salesClosedUpdatedOn=time();
  695. }
  696. if($model->leadSourceId=='' or empty($model->leadSourceId)){
  697. $model->leadSourceId = '2';
  698. }
  699. $fetchAgentDetails=LeadSourceMaster::model()->findByPk($model->leadSourceId);
  700. $model->agentId = @$fetchAgentDetails->leadSourceCode;
  701. $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
  702. if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin') {
  703. @$model->leadStatusId=35;
  704. @$model->currentAllocatedId=Yii::app()->session->get('id');
  705. }
  706. if(@$leadId!='' && $model->leadStatusId!='34'){
  707. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  708. }
  709. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  710. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  711. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  712. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  713. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  714. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
  715. if(count($chkStatusMandatoryOrNot) > 0){
  716. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  717. if($condMandatory == 'No'){
  718. if($model->validate(array('mobile'))){
  719. $mobileNumber = @$_POST['Lead']['mobile'];
  720. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
  721. if(empty($checkJunkNumber)){
  722. $beforethreemonth = time()-7776000;
  723. $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
  724. if(empty($checkDuplicateNumber)){
  725. $model->save(false);
  726. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  727. } else {
  728. $duplicateLeadId = $checkDuplicateNumber->leadId;
  729. $model->leadStatusId='10';
  730. $model->duplicateLeadId=@$duplicateLeadId;
  731. $model->currentAllocatedId=$checkDuplicateNumber->currentAllocatedId;
  732. $model->save(false);
  733. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  734. }
  735. } else {
  736. $model->leadStatusId='36';
  737. $model->save(false);
  738. Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
  739. }
  740. $this->redirect(array('leads/lead_list'));
  741. // $model->save(false);
  742. // $this->redirect(array('leads/lead_list'));
  743. }
  744. }
  745. }
  746. if($model->leadStatusId==36){
  747. $model->save(false);
  748. $this->redirect(array('leads/lead_list'));
  749. } else {
  750. if($model->validate()){
  751. $mobileNumber = $_POST['Lead']['mobile'];
  752. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
  753. if(empty($checkJunkNumber)){
  754. $beforethreemonth = time()-7776000;
  755. $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
  756. if(empty($checkDuplicateNumber)){
  757. $model->save();
  758. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  759. } else {
  760. $duplicateLeadId = $checkDuplicateNumber->leadId;
  761. $model->leadStatusId='10';
  762. $model->duplicateLeadId=@$duplicateLeadId;
  763. $model->save();
  764. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  765. }
  766. } else {
  767. $model->leadStatusId='36';
  768. $model->save();
  769. Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
  770. }
  771. $this->redirect(array('leads/lead_list'));
  772. } else {
  773. $this->render('create_lead',array('model'=>$model));
  774. }
  775. }
  776. } else {
  777. $this->render('create_lead',array('model'=>$model));
  778. }
  779. }
  780. public function actionAllocateLeads(){
  781. $Id = $_REQUEST['userids'];
  782. $teamId = @$_REQUEST['Team']['teamId'];
  783. $userId = $_REQUEST['Team']['teamMemberId'];
  784. $updatedBy = @$_SESSION['id'];
  785. $updatedOn = time();
  786. $teamIdString = '';
  787. if($teamId)
  788. {
  789. $teamIdString = ',teamId = ' . $teamId . ', ';
  790. }
  791. foreach($Id as $key => $value)
  792. {
  793. $commonQueryString = ", updatedBy = $updatedBy, updatedOn = $updatedOn where leadId = $value";
  794. $updateLead = "update lead set currentAllocatedId = $userId, leadStatusId = 35, currentAllocatedDate = $updatedOn $commonQueryString";
  795. Yii::app()->db->createCommand($updateLead)->execute();
  796. }
  797. $red = @$_REQUEST['red'];
  798. if($this->action->id=='AllocateLeads' && $red == 1)
  799. {
  800. $this->redirect(array('leads/lead_list'));
  801. }
  802. $this->redirect(array('leads/fresh_leads'));
  803. }
  804. public function actionAllocateLeadsRES()
  805. {
  806. $Id = $_REQUEST['userids'];
  807. $teamId = @$_REQUEST['Team']['teamId'];
  808. $userId = $_REQUEST['Team']['teamMemberId'];
  809. $updatedBy = @$_SESSION['id'];
  810. foreach($Id as $key=>$value){
  811. $model = new AllocatedLeads();
  812. $model->scenario = 'AllocatedLeads';
  813. $model->setAttributes(array(
  814. 'currentAllocatedDate' => time(), //additional data you want to insert
  815. 'createdOn' => time(), //additional data you want to insert
  816. 'updatedOn' => time(), //additional
  817. 'updatedBy' => @$updatedBy, //additional
  818. 'createdBy' => @$updatedBy, //additional
  819. 'leadStatusId' => '35', //additional //additional
  820. ));
  821. $leadId = @$value;
  822. $model->leadId = @$value;
  823. $model->userId = @$userId;
  824. $model->teamId = @$teamId;
  825. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  826. $model->allocatedId = null;
  827. $model->isNewRecord = true;
  828. $model->save();
  829. $model=new Lead();
  830. $model->scenario = 'Lead';
  831. $updatedOn = time();
  832. Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  833. }
  834. $red = @$_REQUEST['red'];
  835. if($this->action->id=='AllocateLeads' && $red == 1) {
  836. $this->redirect(array('leads/lead_list'));
  837. } else {
  838. $this->redirect(array('leads/fresh_leads'));
  839. }
  840. //$this->redirect(array('leads/lead_list'));
  841. }
  842. /**
  843. * This is the 'lead_list_allocator' action that is invoked
  844. * when an action is not explicitly requested by users.
  845. */
  846. public function actionlead_assign()
  847. {
  848. $model = new Lead();
  849. $model->scenario = 'Lead';
  850. $leadId = $_REQUEST['AssignLead']['leadId'];
  851. $userId = $_REQUEST['AssignLead']['userId'];
  852. $assign = $_REQUEST['AssignLead']['assign'];
  853. if($leadId!='') {
  854. $updatedOn = time();
  855. $chkleadStatus = Lead::model()->findByPk($leadId);
  856. $existsOrNot = $chkleadStatus['leadStatusId'];
  857. $leadStatusIdUpdate = $existsOrNot?$existsOrNot:'34';
  858. if($leadStatusIdUpdate == 34){
  859. $leadStatusIdUpdate = 35;
  860. } else {
  861. $leadStatusIdUpdate = $leadStatusIdUpdate;
  862. }
  863. if($assign=='open') {
  864. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>'','status'=>'Active','leadStatusId'=>34,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>''));
  865. } elseif($assign=='self'){
  866. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$userId,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  867. } else {
  868. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$assign,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  869. }
  870. echo CJSON::encode(array(
  871. 'status'=>'success'
  872. ));
  873. Yii::app()->end();
  874. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  875. } else {
  876. $this->redirect(array('leads/lead_list'));
  877. }
  878. }
  879. /**
  880. * This is the 'roles' action that is invoked
  881. * when an action is not explicitly requested by users.
  882. */
  883. public function actionarchive_leads()
  884. {
  885. // renders the view file 'protected/views/site/index.php'
  886. // using the default layout 'protected/views/layouts/main.php'
  887. $model=new Lead();
  888. //$model=Lead::model()->findAll();
  889. $this->render('archive_leads',array('model'=>$model));
  890. }
  891. /**
  892. * This is the 'roles' action that is invoked
  893. * when an action is not explicitly requested by users.
  894. */
  895. public function actionbulk_import_leads()
  896. {
  897. // renders the view file 'protected/views/site/index.php'
  898. // using the default layout 'protected/views/layouts/main.php'
  899. $model=new Lead();
  900. $this->render('bulk_import_lead',array('model'=>$model));
  901. }
  902. /**
  903. * This is the 'roles' action that is invoked
  904. * when an action is not explicitly requested by users.
  905. */
  906. public function actionjunk_leads()
  907. {
  908. // renders the view file 'protected/views/site/index.php'
  909. // using the default layout 'protected/views/layouts/main.php'
  910. $this->render('junk_leads');
  911. }
  912. /**
  913. * This is the 'module master' action that is invoked
  914. * when an action is not explicitly requested by users.
  915. */
  916. public function actionmodule_master()
  917. {
  918. // renders the view file 'protected/views/site/index.php'
  919. // using the default layout 'protected/views/layouts/main.php'
  920. $model=new ModuleMaster();
  921. $model->scenario = 'ModuleMaster';
  922. if(!empty($_GET['moduleId']))
  923. {
  924. $moduleId=$_GET['moduleId'];
  925. $model=ModuleMaster::model()->findByPk($moduleId);
  926. }
  927. if(!empty($_POST['ModuleMaster']['moduleId']))
  928. {
  929. $moduleId=$_POST['ModuleMaster']['moduleId'];
  930. $model=ModuleMaster::model()->findByPk($moduleId);
  931. }
  932. if(isset($_POST['ModuleMaster']))
  933. {
  934. $model->setAttributes(array(
  935. 'createdOn' => time(), //additional data you want to insert
  936. 'updatedOn' => time(), //additional
  937. 'updatedBy' => time(), //additional
  938. 'createdBy' => time(),
  939. 'status' => 'Activated', //additional //additional
  940. ));
  941. foreach($_POST['ModuleMaster'] as $name=>$value)
  942. {
  943. $model->$name=$value;
  944. }
  945. if($model->validate()){
  946. $model->save();
  947. $model2=ModuleMaster::model()->findAll();
  948. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  949. Yii::app()->user->setFlash('module_master_msg_success','Successfully Inserted');
  950. } else {
  951. Yii::app()->user->setFlash('module_master_msg_error','Please check. error occured');
  952. $this->render('module_master',array('model'=>$model));
  953. }
  954. } else {
  955. $model2=ModuleMaster::model()->findAll();
  956. //Yii::app()->user->setFlash('lead_stage_msg_error','Please check. error occured');
  957. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  958. }
  959. }
  960. /**
  961. * This is the action to handle external exceptions.
  962. */
  963. public function actionError()
  964. {
  965. if($error=Yii::app()->errorHandler->error)
  966. {
  967. if(Yii::app()->request->isAjaxRequest)
  968. echo $error['message'];
  969. else
  970. $this->render('error', $error);
  971. }
  972. }
  973. /**
  974. * Displays the contact page
  975. */
  976. public function actionContact()
  977. {
  978. $model=new ContactForm;
  979. if(isset($_POST['ContactForm']))
  980. {
  981. $model->attributes=$_POST['ContactForm'];
  982. if($model->validate())
  983. {
  984. $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
  985. $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
  986. $headers="From: $name <{$model->email}>\r\n".
  987. "Reply-To: {$model->email}\r\n".
  988. "MIME-Version: 1.0\r\n".
  989. "Content-type: text/plain; charset=UTF-8";
  990. mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
  991. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  992. $this->refresh();
  993. }
  994. }
  995. $this->render('contact',array('model'=>$model));
  996. }
  997. /**
  998. * Displays the login page
  999. */
  1000. public function actionLogin()
  1001. {
  1002. $model=new User;
  1003. // if it is ajax validation request
  1004. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  1005. {
  1006. echo CActiveForm::validate($model);
  1007. Yii::app()->end();
  1008. }
  1009. // collect user input data
  1010. if(isset($_POST['User']))
  1011. {
  1012. $model->attributes=$_POST['User'];
  1013. // validate user input and redirect to the previous page if valid
  1014. if($model->validate() && $model->login()){
  1015. $this->redirect(array('masters/dashboard'));
  1016. } else {
  1017. $this->redirect(Yii::app()->user->returnUrl);
  1018. }
  1019. }
  1020. // display the login form
  1021. $this->render('login',array('model'=>$model));
  1022. }
  1023. /**
  1024. * Logs out the current user and redirect to homepage.
  1025. */
  1026. public function actionLogout()
  1027. {
  1028. setcookie ('PHPSESSID', '', time(), '/', '', 0, 0); // Destroy the cookie.
  1029. Yii::app()->user->logout();
  1030. $this->redirect(Yii::app()->homeUrl);
  1031. }
  1032. public function getPageType()
  1033. {
  1034. return "Leads";
  1035. }
  1036. public function init(){
  1037. $obj =new RecentlyViewedController(); // preparing object
  1038. $data=$obj->actionUserRoleAccess();
  1039. $moduleArray=array();
  1040. if(Yii::app()->session->get('type')=='superadmin'){
  1041. $moduleArray['read']='yes';
  1042. $moduleArray['write']='yes';
  1043. $moduleArray['delete']='yes';
  1044. }else{
  1045. foreach($data as $key=>$value){
  1046. if($data[$key]->modules->moduleName=='Leads'){
  1047. $moduleArray['moduleName']=$data[$key]->modules->moduleName;
  1048. $moduleArray['read']=$data[$key]->read;
  1049. $moduleArray['write']=$data[$key]->write;
  1050. $moduleArray['delete']=$data[$key]->delete;
  1051. }
  1052. }
  1053. }
  1054. return $moduleArray;
  1055. }
  1056. public function getNameFromNumber($num) {
  1057. $numeric = $num % 26;
  1058. $letter = chr(65 + $numeric);
  1059. $num2 = intval($num / 26);
  1060. if ($num2 > 0) {
  1061. return getNameFromNumber($num2 - 1) . $letter;
  1062. } else {
  1063. return $letter;
  1064. }
  1065. }
  1066. /*function actionexportArchiveList()
  1067. {
  1068. // generate a resultset
  1069. $model=new User;
  1070. $model=User::model()->findAll();
  1071. // render data to xlsx format and echo resultant file back to browser.
  1072. ExcelExporter::sendAsXLS($model, true, 'closedLeads.xls');
  1073. }*/
  1074. public function actionDownloadLeadTemp(){
  1075. Yii::import('ext.phpexcel.XPHPExcel');
  1076. $objPHPExcel= XPHPExcel::createPHPExcel();
  1077. $objPHPExcel->getProperties()->setCreator("LeadTemplate")
  1078. ->setLastModifiedBy("LeadTemplate")
  1079. ->setTitle("LeadTemplate")
  1080. ->setSubject("LeadTemplate")
  1081. ->setDescription("LeadTemplate.")
  1082. ->setKeywords("LeadTemplate")
  1083. ->setCategory("LeadTemplate");
  1084. //echo $total_excelColumns=$this->getNameFromNumber(4);
  1085. $total_excelColumns='I';
  1086. // Rename worksheet
  1087. $objPHPExcel->getActiveSheet()->setTitle('ClosedLeads');
  1088. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1089. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1090. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
  1091. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1092. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1093. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1094. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1095. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1096. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1097. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1098. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
  1099. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1100. array(
  1101. 'font' => array(
  1102. 'name' => 'Times New Roman',
  1103. 'bold' => true,
  1104. 'italic' => false,
  1105. 'size' => 12
  1106. ),
  1107. 'borders' => array(
  1108. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1109. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1110. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1111. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1112. ),
  1113. 'alignment' => array(
  1114. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1115. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1116. 'wrap' => true
  1117. )
  1118. ),
  1119. 'A1:'.$total_excelColumns.'1'
  1120. );
  1121. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1122. // Add some data
  1123. $objPHPExcel->setActiveSheetIndex(0)
  1124. ->setCellValue('A1', 'Name')
  1125. ->setCellValue('B1', 'City')
  1126. ->setCellValue('C1', 'Email')
  1127. ->setCellValue('D1', 'Mobile')
  1128. ->setCellValue('E1', 'Suminsured')
  1129. ->setCellValue('F1', 'Age')
  1130. ->setCellValue('G1', 'No. Of Members')
  1131. ->setCellValue('H1', 'Date on submit')
  1132. ->setCellValue('I1', 'Lead Source');
  1133. // Miscellaneous glyphs, UTF-8
  1134. $objPHPExcel->setActiveSheetIndex(0)
  1135. ->setCellValue('A2', 'Lead Name')
  1136. ->setCellValue('B2', 'city')
  1137. ->setCellValue('C2', 'test@yesk.com')
  1138. ->setCellValue('D2', '9999999999')
  1139. ->setCellValue('E2', '56')
  1140. ->setCellValue('F2', '23')
  1141. ->setCellValue('G2', 'test')
  1142. ->setCellValue('H2', '07-Sep-2013')
  1143. ->setCellValue('I2', 'test');
  1144. //To create new sheet in current file
  1145. /*$objPHPExcel->createSheet(1);
  1146. $objPHPExcel->setActiveSheetIndex(1);
  1147. $objPHPExcel->getActiveSheet()->setTitle('Title');
  1148. */
  1149. // Redirect output to a clientÂ’s web browser (Excel5)
  1150. header('Content-Type: application/vnd.ms-excel');
  1151. header('Content-Disposition: attachment;filename="LeadTemplates.xls"');
  1152. header('Cache-Control: max-age=0');
  1153. // If you're serving to IE 9, then the following may be needed
  1154. header('Cache-Control: max-age=1');
  1155. // If you're serving to IE over SSL, then the following may be needed
  1156. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  1157. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1158. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1159. header ('Pragma: public'); // HTTP/1.0
  1160. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1161. $objWriter->save('php://output');
  1162. Yii::app()->end();
  1163. }
  1164. public function actionImportLeadTemplate(){
  1165. $model=new lead();
  1166. $data='';
  1167. $final_arr=@$_POST['final_arr']?@$_POST['final_arr']:'';
  1168. if(isset($_POST['ImportLeads']) && empty($final_arr) && !empty($_FILES['Lead']['name']['import'])){
  1169. Yii::import('ext.phpexcelreader.JPhpExcelReader');
  1170. $model->attributes='import';
  1171. $model->import=CUploadedFile::getInstance($model,'import');
  1172. $prefix=substr(time(),0,5);
  1173. $folder = '/tempdata';
  1174. $model->import->saveAs($folder.$prefix.$model->import);
  1175. $data=new JPhpExcelReader($folder.$prefix.$model->import);
  1176. //$this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
  1177. //$this->redirect(Yii::app()->createUrl('leads/bulk_import_leads'),array('data'=>$data,'model'=>$model));
  1178. $this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
  1179. }
  1180. if(isset($_POST['ImportLeads']) && !empty($final_arr) && isset($final_arr) && empty($_FILES['Lead']['name']['import'])){
  1181. $final_arr = unserialize(urldecode($_POST["final_arr"]));
  1182. $dateTime=time();
  1183. /*echo '<pre>';
  1184. print_r($final_arr);*/
  1185. for($i=0;$i<sizeof($final_arr);$i++)
  1186. {
  1187. $leadStatusId = '0';
  1188. $duplicateLeadId = '0';
  1189. $currentAllocatedId = '0';
  1190. $junkNumberQuery = Yii::app()->db->createCommand("SELECT `junkLeadNumberId` FROM `junkLeadNumberMaster` WHERE `junkLeadNumber` = '".@$final_arr[$i]['mobile']."' ")->queryAll();
  1191. $junkNumberResult = $junkNumberQuery;
  1192. $fetchAgentDetails=LeadSourceMaster::model()->findByPk($final_arr[$i]['leadSourceId']);
  1193. //$duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' ")->queryAll();(Original, changed below by Baljeet)
  1194. $duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId`,`currentAllocatedId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' order by leadId ASC LIMIT 1")->queryAll();
  1195. $duplicateResult = ($duplicateQuery);
  1196. //echo '<br>duplicateResult----------'.count($duplicateResult);
  1197. if(count($junkNumberResult) > 0){
  1198. $leadStatusId = '36';
  1199. $duplicateLeadId = '';
  1200. $currentAllocatedId = '';
  1201. } elseif(count($duplicateResult)>0){
  1202. $leadStatusId = '10';
  1203. $duplicateLeadId = @$duplicateResult[0]['leadId'];
  1204. $currentAllocatedId = @$duplicateResult[0]['currentAllocatedId']; //added by baljeet
  1205. } else {
  1206. $leadStatusId = '34';
  1207. $duplicateLeadId = '';
  1208. $currentAllocatedId = '';
  1209. }
  1210. /*echo '<br>leadStatusId---'.$leadStatusId;
  1211. echo '<br>duplicateLeadId---'.$duplicateLeadId;
  1212. echo '<br>currentAllocatedId---'.$currentAllocatedId;*/
  1213. $model=new lead();
  1214. $model->name=$final_arr[$i]['name'];
  1215. $model->cityId=$final_arr[$i]['cityId'];
  1216. $model->email=$final_arr[$i]['email'];
  1217. $model->mobile=$final_arr[$i]['mobile'];
  1218. $model->si=$final_arr[$i]['suminsured'];
  1219. $model->age=$final_arr[$i]['age'];
  1220. $model->members=$final_arr[$i]['noofmembers'];
  1221. $model->dateonSubmit=$final_arr[$i]['dateonsubmit'];
  1222. $model->leadSourceId=$final_arr[$i]['leadSourceId'];
  1223. $model->leadStatusId=$leadStatusId;
  1224. $model->duplicateLeadId=@$duplicateLeadId;
  1225. $model->currentAllocatedId=@$currentAllocatedId;
  1226. $model->productId='1';
  1227. $model->status='Active';
  1228. $model->createdOn=$dateTime;
  1229. $model->createdBy=Yii::app()->session->get('id');
  1230. $model->updatedOn=$dateTime;
  1231. $model->updatedBy=Yii::app()->session->get('id');
  1232. $model->isBulkImport='YES';
  1233. $model->agentId = @$fetchAgentDetails->leadSourceCode;
  1234. $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
  1235. $model->isNewRecord = true;
  1236. $model->save(false);
  1237. }
  1238. $this->redirect(array('leads/lead_list'));
  1239. }
  1240. if(isset($_POST['ImportLeads']) && empty($final_arr) && empty($_FILES['Lead']['name']['import'])){
  1241. $model->validate();
  1242. $this->render('bulk_import_lead',array('model'=>$model));
  1243. }
  1244. }
  1245. public function actionleadSearch()
  1246. {
  1247. $searched = new Lead();
  1248. if(@$_REQUEST['lead']['leadSearchBox']=='' && @$_REQUEST['mob']=='') {
  1249. $this->redirect(array('leads/lead_list'));
  1250. } else {
  1251. $this->render('lead_search',array('searched'=>@$searched));
  1252. }
  1253. }
  1254. public function actionExportExcel()
  1255. {
  1256. // It calls the actionCreateExcel to generates excel reports'
  1257. $this->actionCreateExcel();
  1258. }
  1259. public function actionCreateExcel(){
  1260. //Here is the code to set conditions for fetch records from database
  1261. $criteria = new CDbCriteria;
  1262. $criteria->select = 't.*,`city`.`city`, `state`.`state`, `leadSourceMaster`.`leadSourceTitle`,`leadSourceMaster`.`leadSourceCode`,`leadStageMaster`.`leadStage`,`leadStatus`.`leadStatus`, `customerTypeMaster`.`customerType`,`productMaster`.`productName`,`policyTypeMaster`.`policyType`,`planTypeMaster`.`planType`,`campaign`.`campaignName`';
  1263. $criteria->join ='LEFT JOIN city ON (city.cityId = t.cityId) LEFT JOIN state ON (state.stateId = t.stateId) LEFT JOIN leadSourceMaster ON (leadSourceMaster.leadSourceId = t.leadSourceId) LEFT JOIN leadStageMaster ON (leadStageMaster.leadStageId = t.leadStageId)LEFT JOIN leadStatus ON (leadStatus.leadStatusId = t.leadStatusId)LEFT JOIN customerTypeMaster ON (customerTypeMaster.customerTypeId = t.customerTypeId)LEFT JOIN productMaster ON (productMaster.productId = t.productId)LEFT JOIN policyTypeMaster ON (policyTypeMaster.policyTypeId = t.policyTypeId)LEFT JOIN planTypeMaster ON (planTypeMaster.planTypeId = t.planTypeId)LEFT JOIN campaign ON (campaign.campaignId = t.campaignId)';
  1264. $criteria->condition='t.status != "Allocated" AND t.leadStatusId != "25" AND t.leadStatusId != "26" ';
  1265. $criteria->order='leadId DESC';
  1266. $model=new LeadReport();
  1267. $model->scenario = 'LeadReport';
  1268. $reportmodel=LeadReport::model()->findAll($criteria);
  1269. $data=array();
  1270. $datas = $reportmodel;
  1271. foreach($datas as $key=>$value){
  1272. $data[$key]=$value;
  1273. }
  1274. if(count($data)>0){
  1275. Yii::import('ext.phpexcel.XPHPExcel');
  1276. $objPHPExcel= XPHPExcel::createPHPExcel();
  1277. $objPHPExcel->getProperties()->setCreator("ReligareLMS")
  1278. ->setLastModifiedBy("ReligareLMS")
  1279. ->setTitle("Office 2007 XLSX Test Document")
  1280. ->setSubject("Office 2007 XLSX Test Document")
  1281. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  1282. ->setKeywords("office 2007 openxml php")
  1283. ->setCategory("Test result file");
  1284. $total_excelColumns=$this->getNameFromNumber(8);
  1285. // Rename worksheet
  1286. $objPHPExcel->getActiveSheet()->setTitle('Sample Excel');
  1287. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1288. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1289. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
  1290. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1291. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1292. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1293. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1294. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1295. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1296. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1297. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1298. array(
  1299. 'font' => array(
  1300. 'name' => 'Times New Roman',
  1301. 'bold' => true,
  1302. 'italic' => false,
  1303. 'size' => 12
  1304. ),
  1305. 'borders' => array(
  1306. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1307. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1308. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1309. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1310. ),
  1311. 'alignment' => array(
  1312. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1313. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1314. 'wrap' => true
  1315. )
  1316. ),
  1317. 'A1:'.$total_excelColumns.'1'
  1318. );
  1319. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1320. // Add some data
  1321. $objPHPExcel->setActiveSheetIndex(0)
  1322. ->setCellValue('A1', 'SNO.')
  1323. ->setCellValue('B1', 'Name')
  1324. ->setCellValue('C1', 'Mobile')
  1325. ->setCellValue('D1', 'Email')
  1326. ->setCellValue('E1', 'Lead Stage')
  1327. ->setCellValue('F1', 'Date and Time')
  1328. ->setCellValue('G1', 'UTM Code')
  1329. ->setCellValue('H1', 'status');
  1330. // Miscellaneous glyphs, UTF-8
  1331. $i=0;
  1332. $k=2;
  1333. $sn=1;
  1334. while($i<count($data)){
  1335. $objPHPExcel->setActiveSheetIndex(0)
  1336. ->setCellValue('A'.$k,$sn)
  1337. ->setCellValue('B'.$k,$data[$i]['name'])
  1338. ->setCellValue('C'.$k,$data[$i]['mobile'])
  1339. ->setCellValue('D'.$k,$data[$i]['email'])
  1340. ->setCellValue('E'.$k,$data[$i]['leadStage'])
  1341. ->setCellValue('F'.$k,date("d/m/y h:i A",$data[$i]['createdOn']))
  1342. ->setCellValue('G'.$k,$data[$i]['leadSourceCode'])
  1343. ->setCellValue('H'.$k,$data[$i]['status']);
  1344. $i++;$k++;$sn++;}
  1345. // Redirect output to a clientÂ’s web browser (Excel5)
  1346. header('Content-Type: application/vnd.ms-excel');
  1347. header('Content-Disposition: attachment;filename="lead_report.xls"');
  1348. header('Cache-Control: max-age=0');
  1349. // If you're serving to IE 9, then the following may be needed
  1350. header('Cache-Control: max-age=1');
  1351. // If you're serving to IE over SSL, then the following may be needed
  1352. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1353. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1354. header ('Pragma: public'); // HTTP/1.0
  1355. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1356. $objWriter->save('php://output');
  1357. Yii::app()->end();
  1358. }
  1359. else{
  1360. $model = new Lead();
  1361. $model = Lead::model()->findAll("status = 'Active'");
  1362. $this->render('lead_list',array('model'=>$model));
  1363. }
  1364. }
  1365. public function actiongetSourceResults(){
  1366. $models=new Lead();
  1367. $type=@$_REQUEST['type'];
  1368. $searchTxt=@$_REQUEST['searchTxt'];
  1369. if(isset($searchTxt) && !empty($searchTxt)){
  1370. $this->renderPartial('searchSourceLeads',array('searchTxt'=>$searchTxt,'type'=>@$type));
  1371. } else {
  1372. if($type=='fresh'){
  1373. $functs="fresh_leads";
  1374. }
  1375. if($type=='new'){
  1376. $functs="lead_list";
  1377. }
  1378. if($type=='duplicate'){
  1379. $functs="duplicate_lead_list";
  1380. }
  1381. if($type=='junk'){
  1382. $functs="junk_lead_list";
  1383. }
  1384. if($type=='allocated'){
  1385. $functs="allocated_lead_list";
  1386. }
  1387. if($type=='cip'){
  1388. $functs="cip_lead_list";
  1389. }
  1390. if($type=='plc'){
  1391. $functs="plc_lead_list";
  1392. }
  1393. if($type=='closed'){
  1394. $functs="close_lead_list";
  1395. }
  1396. if($type==''){
  1397. $functs="lead_list";
  1398. }
  1399. echo Yii::app()->createUrl('leads/'.@$functs);
  1400. exit;
  1401. }
  1402. }
  1403. public function actionAutocompleteSearch(){
  1404. $models=new Lead();
  1405. $term=@$_REQUEST['term'];
  1406. $type=@$_REQUEST['type'];
  1407. if($type=="fresh"){
  1408. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1409. }
  1410. if($type=="new"){
  1411. $relationManager = $_SESSION['relationalManager'];
  1412. $managerMemberId = implode(",",array_unique(@$relationManager));
  1413. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1414. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
  1415. } else {
  1416. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1417. }
  1418. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1419. //$models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
  1420. }
  1421. if($type=="duplicate"){
  1422. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '10' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1423. }
  1424. if($type=="dupforday"){
  1425. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1426. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '10' AND createdOn > '".@$today12PM."' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1427. }
  1428. if($type=="junk"){
  1429. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '36' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1430. }
  1431. if($type=="allocated"){
  1432. $relationManager = $_SESSION['relationalManager'];
  1433. $managerMemberId = implode(",",array_unique(@$relationManager));
  1434. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1435. $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
  1436. } else {
  1437. $querycondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1438. }
  1439. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1440. }
  1441. if($type=="followup"){
  1442. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1443. $relationManager = $_SESSION['relationalManager'];
  1444. $managerMemberId = implode(",",array_unique(@$relationManager));
  1445. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1446. $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
  1447. } else {
  1448. $querycondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1449. }
  1450. $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
  1451. }
  1452. if($type=="allfollowup"){
  1453. $relationManager = $_SESSION['relationalManager'];
  1454. $managerMemberId = implode(",",array_unique(@$relationManager));
  1455. $currentDate=date('d-m-Y',time());
  1456. $starttimestamp=strtotime($currentDate);
  1457. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1458. $querycondition = ' status="Pending" ';
  1459. } else {
  1460. $querycondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1461. }
  1462. $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
  1463. }
  1464. if($type=="closed"){
  1465. $relationManager = $_SESSION['relationalManager'];
  1466. $managerMemberId = implode(",",array_unique(@$relationManager));
  1467. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1468. $querycondition = "leadStatusId = '7'";
  1469. } else {
  1470. $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1471. }
  1472. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and concat(name,mobile,email) like '%$term%' ");
  1473. }
  1474. if($type=="cip"){
  1475. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=3")->queryAll();
  1476. $CIPids = array();
  1477. if(count($contactInProgList) > 0){
  1478. for($w=0;$w<count($contactInProgList);$w++){
  1479. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  1480. }
  1481. } else {
  1482. @$CIPids[] = '';
  1483. }
  1484. @$CIPids = implode(",",@$CIPids);
  1485. $relationManager = $_SESSION['relationalManager'];
  1486. $managerMemberId = implode(",",array_unique(@$relationManager));
  1487. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1488. $querycondition = " leadStatusId IN ( ".@$CIPids." ) ";
  1489. } else {
  1490. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  1491. }
  1492. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1493. }
  1494. if($type=="plc"){
  1495. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=41")->queryAll();
  1496. $CIPids = array();
  1497. if(count($contactInProgList) > 0){
  1498. for($w=0;$w<count($contactInProgList);$w++){
  1499. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  1500. }
  1501. } else {
  1502. @$CIPids[] = '';
  1503. }
  1504. @$CIPids = implode(",",@$CIPids);
  1505. $relationManager = $_SESSION['relationalManager'];
  1506. $managerMemberId = implode(",",array_unique(@$relationManager));
  1507. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1508. $querycondition = " leadStatusId IN ( ".@$CIPids." ) ";
  1509. } else {
  1510. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  1511. }
  1512. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1513. }
  1514. if($type=="cld"){
  1515. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1516. $relationManager = $_SESSION['relationalManager'];
  1517. $managerMemberId = implode(",",array_unique(@$relationManager));
  1518. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1519. $querycondition = 'leadStatusId = 12 AND startDate = "'.@$today12PM.'" ';
  1520. } else {
  1521. $querycondition = "leadStatusId = 12 AND startDate = '".@$today12PM."' AND userId IN (".@$managerMemberId.") ";
  1522. }
  1523. $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
  1524. }
  1525. if($type=="followup" or $type=="allfollowup" or $type=="cld"){
  1526. $arr = array();
  1527. foreach($models as $model) {
  1528. $arr[] = array(
  1529. 'label'=>substr($model->description,0,10), // label for dropdown list
  1530. 'value'=>substr($model->description,0,10), // value for input field
  1531. 'id'=>$model->leadFollowupId, // return value from autocomplete
  1532. );
  1533. }
  1534. if(count($models) > 0){
  1535. $arr['totalRecords'] = array(
  1536. 'totalRecords'=>count($models), // return value from autocomplete
  1537. );
  1538. }
  1539. }else {
  1540. $arr = array();
  1541. foreach($models as $model) {
  1542. $arr[] = array(
  1543. 'label'=>$model->mobile?$model->mobile.($model->name?'/'.$model->name:'').($model->email?'/'.$model->email:''):'', // label for dropdown list
  1544. 'value'=>$model->mobile?$model->mobile:$model->name, // value for input field
  1545. 'id'=>$model->leadId, // return value from autocomplete
  1546. );
  1547. }
  1548. if(count($models) > 0){
  1549. $arr['totalRecords'] = array(
  1550. 'totalRecords'=>count($models), // return value from autocomplete
  1551. );
  1552. }
  1553. }
  1554. echo CJSON::encode($arr);
  1555. Yii::app()->end();
  1556. //$this->renderPartial('searchLeads');
  1557. }
  1558. public function actionAutocompleteSearchSource(){
  1559. $models=new Lead();
  1560. $term=@$_REQUEST['term'];
  1561. $type=@$_REQUEST['type'];
  1562. if($type=="fresh"){
  1563. $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and concat(leadSourceTitle) like '%$term%'","order"=>"leadId desc"));
  1564. }
  1565. if($type=="new"){
  1566. $relationManager = $_SESSION['relationalManager'];
  1567. $managerMemberId = implode(",",array_unique(@$relationManager));
  1568. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1569. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
  1570. } else {
  1571. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1572. }
  1573. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%'");
  1574. //$models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
  1575. }
  1576. if($type=="duplicate"){
  1577. $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '10' and leadSourceTitle like '%$term%'","order"=>"leadId desc"));
  1578. }
  1579. if($type=="junk"){
  1580. $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '36' and leadSourceTitle like '%$term%'","order"=>"leadId desc"));
  1581. }
  1582. if($type=="allocated"){
  1583. $relationManager = $_SESSION['relationalManager'];
  1584. $managerMemberId = implode(",",array_unique(@$relationManager));
  1585. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1586. $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
  1587. } else {
  1588. $querycondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1589. }
  1590. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%'");
  1591. }
  1592. if($type=="followup"){
  1593. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1594. $relationManager = $_SESSION['relationalManager'];
  1595. $managerMemberId = implode(",",array_unique(@$relationManager));
  1596. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1597. $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
  1598. } else {
  1599. $querycondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1600. }
  1601. $models = LeadFollowup::model()->findAll(" $querycondition and description leadSourceTitle '%$term%'");
  1602. }
  1603. if($type=="closed"){
  1604. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1605. $relationManager = $_SESSION['relationalManager'];
  1606. $managerMemberId = implode(",",array_unique(@$relationManager));
  1607. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1608. $querycondition = "leadStatusId = '7'";
  1609. } else {
  1610. $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1611. }
  1612. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%' ");
  1613. }
  1614. if($type=="followup"){
  1615. $arr = array();
  1616. foreach($models as $model) {
  1617. $arr[] = array(
  1618. 'label'=>substr($model->description,0,10), // label for dropdown list
  1619. 'value'=>substr($model->description,0,10), // value for input field
  1620. 'id'=>$model->leadFollowupId, // return value from autocomplete
  1621. );
  1622. }
  1623. if(count($models) > 0){
  1624. $arr['totalRecords'] = array(
  1625. 'totalRecords'=>count($models), // return value from autocomplete
  1626. );
  1627. }
  1628. }else {
  1629. $arr = array();
  1630. foreach($models as $model) {
  1631. $arr[] = array(
  1632. 'label'=>$model->mobile?$model->mobile:$model->name, // label for dropdown list
  1633. 'value'=>$model->mobile?$model->mobile:$model->name, // value for input field
  1634. 'id'=>$model->leadId, // return value from autocomplete
  1635. );
  1636. }
  1637. if(count($models) > 0){
  1638. $arr['totalRecords'] = array(
  1639. 'totalRecords'=>count($models), // return value from autocomplete
  1640. );
  1641. }
  1642. }
  1643. echo CJSON::encode($arr);
  1644. Yii::app()->end();
  1645. //$this->renderPartial('searchLeads');
  1646. }
  1647. public function actionAutocompleteSearchRes(){
  1648. $models=new Lead();
  1649. $term=@$_REQUEST['id'];
  1650. $type=@$_REQUEST['type'];
  1651. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
  1652. $arr = array();
  1653. $this->renderPartial('searchLeads',array('name'=>$term));
  1654. }
  1655. public function actionexportArchiveList(){
  1656. $Leadname = @$_REQUEST['name'];
  1657. $Leadstatus = @$_REQUEST['status'];
  1658. $leadStage = @$_REQUEST['statge'];
  1659. $cond ='';
  1660. if(isset($Leadname) && !empty($Leadname)){
  1661. $cond .=" AND name like '%".@$Leadname."%'";
  1662. }
  1663. if(isset($Leadstatus) && !empty($Leadstatus)){
  1664. $cond .=" AND leadStatusId = '".@$Leadstatus."'";
  1665. }
  1666. if(isset($leadStage) && !empty($leadStage)){
  1667. $cond .=" AND leadStageId = '".@$leadStage."'";
  1668. }
  1669. $dataProvider = new CActiveDataProvider('Lead', array('criteria'=>array(
  1670. 'condition'=>' FROM_UNIXTIME(updatedOn) >= DATE_SUB(CURDATE(), INTERVAL 120 DAY) '.@$cond.' and leadStatusId NOT IN (12,8,1,4) ',
  1671. 'order'=>'',
  1672. )));
  1673. $iterator = new CDataProviderIterator($dataProvider);
  1674. $data=array();
  1675. $datas = $iterator;
  1676. foreach($datas as $key=>$value){
  1677. $data[$key]=$value;
  1678. }
  1679. Yii::import('ext.phpexcel.XPHPExcel');
  1680. $objPHPExcel= XPHPExcel::createPHPExcel();
  1681. $objPHPExcel->getProperties()->setCreator("ReligareLMS")
  1682. ->setLastModifiedBy("ReligareLMS")
  1683. ->setTitle("Office 2007 XLSX Leads Document")
  1684. ->setSubject("Office 2007 XLSX Leads Document")
  1685. ->setDescription("Archive Leads.")
  1686. ->setKeywords("Archive Leads")
  1687. ->setCategory("Archive Leads");
  1688. // Rename worksheet
  1689. $objPHPExcel->getActiveSheet()->setTitle('Sample Excel');
  1690. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1691. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1692. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
  1693. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1694. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1695. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1696. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1697. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1698. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1699. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1700. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
  1701. $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(30);
  1702. $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(30);
  1703. $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(30);
  1704. $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(30);
  1705. $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(30);
  1706. $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(30);
  1707. $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(30);
  1708. $objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(30);
  1709. $objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(30);
  1710. $objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(30);
  1711. $objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(30);
  1712. $objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(30);
  1713. $objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth(30);
  1714. $objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(30);
  1715. $objPHPExcel->getActiveSheet()->getColumnDimension('X')->setWidth(30);
  1716. $objPHPExcel->getActiveSheet()->getColumnDimension('y')->setWidth(30);
  1717. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1718. array(
  1719. 'font' => array(
  1720. 'name' => 'Times New Roman',
  1721. 'bold' => true,
  1722. 'italic' => false,
  1723. 'size' => 12
  1724. ),
  1725. 'borders' => array(
  1726. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1727. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1728. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1729. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1730. ),
  1731. 'alignment' => array(
  1732. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1733. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1734. 'wrap' => true
  1735. )
  1736. ),
  1737. 'A1:Y1'
  1738. );
  1739. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1740. // Add some data
  1741. $objPHPExcel->setActiveSheetIndex(0)
  1742. ->setCellValue('A1', 'SNO.')
  1743. ->setCellValue('B1', 'Name')
  1744. ->setCellValue('C1', 'Mobile Number')
  1745. ->setCellValue('D1', 'Email Id')
  1746. ->setCellValue('E1', 'Address')
  1747. ->setCellValue('F1', 'City')
  1748. ->setCellValue('G1', 'State')
  1749. ->setCellValue('H1', 'Members')
  1750. ->setCellValue('I1', 'Premium')
  1751. ->setCellValue('J1', 'Product Details')
  1752. ->setCellValue('K1', 'Lead Status')
  1753. ->setCellValue('L1', 'Status')
  1754. ->setCellValue('M1', 'isJunk')
  1755. ->setCellValue('N1', 'Lead Source')
  1756. ->setCellValue('O1', 'Lead Stage')
  1757. ->setCellValue('P1', 'Lead Description')
  1758. ->setCellValue('Q1', 'Activity Description')
  1759. ->setCellValue('R1', 'Customer Type')
  1760. ->setCellValue('S1', 'Product Name')
  1761. ->setCellValue('T1', 'Policy Type')
  1762. ->setCellValue('U1', 'Plan Type')
  1763. ->setCellValue('V1', 'Campaign Name')
  1764. ->setCellValue('W1', 'UTM Code')
  1765. ->setCellValue('X1', 'Owner')
  1766. ->setCellValue('Y1', 'Last Modified Date');
  1767. // Miscellaneous glyphs, UTF-8
  1768. $i=0;
  1769. $k=2;
  1770. $sn=1;
  1771. while($i<count($data)){
  1772. $str = preg_replace('/\s\s+/', ' ', $data[$i]['address']);
  1773. if($data[$i]['currentAllocatedId']==$data[$i]['createdBy']){
  1774. $owner = $data[$i]['ownerDetails']['firstName']." ".$data[$i]['ownerDetails']['lastName']."(C)";
  1775. } else {
  1776. if(isset($data[$i]['ownerDetails']['firstName']) && !empty($data[$i]['ownerDetails']['firstName'])){
  1777. $owner = $data[$i]['ownerDetails']['firstName']." ".$data[$i]['ownerDetails']['lastName'];
  1778. } else {
  1779. $owner = "NA";
  1780. }
  1781. }
  1782. $descrecords=Yii::app()->db->createCommand("select leadDescription from lead where leadId='".@$data[$i]['leadId']."' ")->queryAll();
  1783. $records=Yii::app()->db->createCommand("select description from leadFollowup where leadId='".@$data[$i]['leadId']."' ")->queryAll();
  1784. $ActivityRes = '';
  1785. for($j=0;$j<count($records);$j++){
  1786. @$ActivityRes .= @$records[0]['description'].",";
  1787. }
  1788. $lastModifieddate = date("d M Y H:i:s A",$data[$i]['updatedOn']);
  1789. //ReportsController::getLeadDescription(@$data->leadId);
  1790. //$data[$i]['ownerDetails']['firstName'];
  1791. $objPHPExcel->setActiveSheetIndex(0)
  1792. ->setCellValue('A'.$k,$sn)
  1793. ->setCellValue('B'.$k,$data[$i]['name'])
  1794. ->setCellValue('C'.$k,$data[$i]['mobile'])
  1795. ->setCellValue('D'.$k,$data[$i]['email'])
  1796. ->setCellValue('E'.$k,$str)
  1797. ->setCellValue('F'.$k,$data[$i]['city'])
  1798. ->setCellValue('G'.$k,$data[$i]['state'])
  1799. ->setCellValue('H'.$k,$data[$i]['members'])
  1800. ->setCellValue('I'.$k,$data[$i]['premium'])
  1801. ->setCellValue('J'.$k,$data[$i]['productDetails'])
  1802. ->setCellValue('K'.$k,$data[$i]['leadStatusDetails']['leadStatus'])
  1803. ->setCellValue('L'.$k,$data[$i]['status'])
  1804. ->setCellValue('M'.$k,$data[$i]['isJunk'])
  1805. ->setCellValue('N'.$k,$data[$i]['leadSourceTitle'])
  1806. ->setCellValue('O'.$k,$data[$i]['leadStage'])
  1807. ->setCellValue('P'.$k,@$descrecords[0]['leadDescription'])
  1808. ->setCellValue('Q'.$k,@$ActivityRes)
  1809. ->setCellValue('R'.$k,$data[$i]['customerType'])
  1810. ->setCellValue('S'.$k,$data[$i]['productName'])
  1811. ->setCellValue('T'.$k,$data[$i]['policyType'])
  1812. ->setCellValue('U'.$k,$data[$i]['planType'])
  1813. ->setCellValue('V'.$k,$data[$i]['campaignName'])
  1814. ->setCellValue('W'.$k,$data[$i]['leadSourceCode'])
  1815. ->setCellValue('X'.$k,$owner)
  1816. ->setCellValue('Y'.$k,$lastModifieddate);
  1817. $i++;$k++;$sn++;}
  1818. // Redirect output to a clientÂ’s web browser (Excel5)
  1819. header('Content-Type: application/vnd.ms-excel');
  1820. header('Content-Disposition: attachment;filename="lead_report.xls"');
  1821. header('Cache-Control: max-age=0');
  1822. // If you're serving to IE 9, then the following may be needed
  1823. header('Cache-Control: max-age=1');
  1824. // If you're serving to IE over SSL, then the following may be needed
  1825. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1826. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1827. header ('Pragma: public'); // HTTP/1.0
  1828. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1829. $objWriter->save('php://output');
  1830. Yii::app()->end();
  1831. }
  1832. public function actiongetCityList()
  1833. {
  1834. $data=City::model()->findAll(array('condition'=>'stateId=:stateId and status=:status','params'=>array(':stateId'=>(int) $_POST['stateId'],'status'=>'Active')));
  1835. $data=CHtml::listData($data,'cityId','city');
  1836. echo '<select class="styled" name="Lead[cityId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" onchange="changeText();">';
  1837. echo '<option value="" selected="selected">Select City</option>';
  1838. foreach($data as $value=>$name)
  1839. {
  1840. echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name));
  1841. }
  1842. echo '</select>';
  1843. echo '<span id="changeText" class="customStyleSelectBox" style="display: block;width:97px;"><span class="customStyleSelectBoxInner" style="width: 81px; display: block;">Select City</span></span>';
  1844. }
  1845. public function actiongetLeadStatus()
  1846. {
  1847. if(isset($_POST['parentId']) && !empty($_POST['parentId'])){
  1848. $data=LeadStatus::model()->findAll(array('condition'=>'parentId=:parentId and status=:status','params'=>array(':parentId'=>(int) @$_POST['parentId'],'status'=>'Active')));
  1849. $data=CHtml::listData($data,'leadStatusId','leadStatus');
  1850. echo '<select class="styled" name="Lead[leadStatusId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" id="leadprimarystatus" onchange="changeStatusText();getActionRes(this.value);">';
  1851. echo '<option value="" selected="selected">Select lead Status</option>';
  1852. foreach($data as $value=>$name)
  1853. {
  1854. echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name));
  1855. }
  1856. echo '</select>';
  1857. } else {
  1858. echo '<select class="styled" name="Lead[leadStatusId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" id="leadprimarystatus" onchange="changeStatusText();getActionRes(this.value);">';
  1859. echo '<option value="" selected="selected">Select lead Status</option>';
  1860. echo '</select>';
  1861. }
  1862. echo '<span id="changeStatusText" class="customStyleSelectBox" style="display: block;min-width:142px;"><span class="customStyleSelectBoxInner" style="width: 81px; display: block;">Select lead Status</span></span>';
  1863. }
  1864. public function actionexportLeads(){
  1865. $model=new Lead();
  1866. $type=@$_REQUEST['type'];
  1867. $relationManager = @$_SESSION['relationalManager'];
  1868. $managerMemberId = implode(",",array_unique(@$relationManager));
  1869. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1870. if($type=="freshLeads"){
  1871. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1872. $querycondition = " leadStatusId = '34' AND currentAllocatedId<1";
  1873. } else {
  1874. $querycondition = " leadStatusId = '34' AND currentAllocatedId<1";
  1875. }
  1876. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1877. 'condition'=>@$querycondition,
  1878. 'order'=>'leadId DESC',
  1879. ),
  1880. 'pagination'=>false,
  1881. ));
  1882. }
  1883. if($type=="newLeads"){
  1884. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1885. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead = 'no' ";
  1886. } else {
  1887. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead = 'no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1888. }
  1889. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1890. 'condition'=>@$querycondition,
  1891. 'order'=>'leadId DESC',
  1892. ),
  1893. 'pagination'=>array(
  1894. 'pageSize'=> 10,
  1895. ),
  1896. ));
  1897. }
  1898. if($type=="allocatedLeads"){
  1899. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1900. $queryCondition = " currentAllocatedId>0 AND isRead = 'yes' ";
  1901. } else {
  1902. $queryCondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1903. }
  1904. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1905. 'condition'=>@$queryCondition,
  1906. 'order'=>'leadId DESC',
  1907. )));
  1908. }
  1909. if($type=="Allfollowup"){
  1910. $currentDate=date('d-m-Y',time());
  1911. $starttimestamp=strtotime($currentDate);
  1912. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1913. $queryCondition = ' status="Pending" and userId = "'.@$_SESSION['id'].'" ';
  1914. } else {
  1915. $queryCondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1916. }
  1917. $dataProvider=new CActiveDataProvider('LeadFollowup', array('criteria'=>array(
  1918. 'condition'=>@$queryCondition,
  1919. 'order'=>'leadFollowupId DESC',
  1920. )));
  1921. }
  1922. if($type=="followupLeads"){
  1923. $currentDate=date('d-m-Y',time());
  1924. $starttimestamp=strtotime($currentDate);
  1925. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1926. $queryCondition = ' startDate = "'.@$starttimestamp.'" and status="Pending" and userId = "'.@$_SESSION['id'].'" ';
  1927. } else {
  1928. $queryCondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1929. }
  1930. $dataProvider=new CActiveDataProvider('LeadFollowup', array('criteria'=>array(
  1931. 'condition'=>@$queryCondition,
  1932. 'order'=>'leadFollowupId DESC',
  1933. )));
  1934. }
  1935. if($type=="duplicateLeads"){
  1936. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1937. 'condition'=>' leadStatusId = "10" ',
  1938. 'order'=>'leadId DESC',
  1939. )));
  1940. }
  1941. if($type=="dupforday"){
  1942. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1943. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1944. 'condition'=>' leadStatusId = "10" AND createdOn > "'.@$today12PM.'" ',
  1945. 'order'=>'leadId DESC',
  1946. )));
  1947. }
  1948. if($type=="junkLeads"){
  1949. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1950. 'condition'=>' leadStatusId = "36" ',
  1951. 'order'=>'leadId DESC',
  1952. )));
  1953. }
  1954. if($type=="closeLeads"){
  1955. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1956. $querycondition = "leadStatusId = '7' ";
  1957. } else {
  1958. $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1959. }
  1960. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1961. 'condition'=>@$querycondition,
  1962. 'order'=>'leadId desc',
  1963. ),
  1964. ));
  1965. }
  1966. if($type=="cip"){
  1967. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=3")->queryAll();
  1968. $CIPids = array();
  1969. if(count($contactInProgList) > 0){
  1970. for($w=0;$w<count($contactInProgList);$w++){
  1971. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  1972. }
  1973. } else {
  1974. @$CIPids[] = '';
  1975. }
  1976. @$CIPids = implode(",",@$CIPids);
  1977. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1978. $querycondition = "leadStatusId IN ( ".@$CIPids." ) ";
  1979. } else {
  1980. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  1981. }
  1982. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1983. 'condition'=>@$querycondition,
  1984. 'order'=>'leadId desc',
  1985. ),
  1986. 'pagination'=>false,
  1987. ));
  1988. }
  1989. if($type=="plc"){
  1990. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=41")->queryAll();
  1991. $CIPids = array();
  1992. if(count($contactInProgList) > 0){
  1993. for($w=0;$w<count($contactInProgList);$w++){
  1994. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  1995. }
  1996. } else {
  1997. @$CIPids[] = '';
  1998. }
  1999. @$CIPids = implode(",",@$CIPids);
  2000. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  2001. $querycondition = "leadStatusId IN ( ".@$CIPids." )";
  2002. } else {
  2003. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  2004. }
  2005. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  2006. 'condition'=>@$querycondition,
  2007. 'order'=>'leadId desc',
  2008. ),
  2009. 'pagination'=>false,
  2010. ));
  2011. }
  2012. $dataProvider->getTotalItemCount($dataProvider);
  2013. if($type=="followupLeads" or $type=="Allfollowup"){
  2014. $iterator = new CDataProviderIterator($dataProvider);
  2015. $file_name = "lms" . "_" . date("Y-m-d_H-i", time()) . ".csv";
  2016. header('Content-Type: text/html; charset=utf-8');
  2017. header("Content-type: application/octet-stream");
  2018. header("Content-Disposition: attachment; filename=\"$file_name\"");
  2019. header("Cache-Control: cache, must-revalidate");
  2020. header("Pragma: public");
  2021. $col = array(
  2022. 'SNO.','Name','Mobile','AgentId','Lead Desciption','Activity Desciption','Email','Action Type','Date and Time','Description','Owner');
  2023. foreach ($col as $key => $value) {
  2024. echo $value . ",";
  2025. }
  2026. echo "\n";
  2027. $i=1;
  2028. foreach($iterator as $data) {
  2029. echo $i++ . ",";
  2030. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->name)) . ",";
  2031. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->mobile)) . ",";
  2032. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->ws_agentid)) . ",";
  2033. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->leadDescription)) . ",";
  2034. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->description)) . ",";
  2035. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDetails->email)) . ",";
  2036. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->actionType)) . ",";
  2037. echo date("d/m/y h:i A",$data->createdOn) . ",";
  2038. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->description)) . ",";
  2039. echo (@$data->userId==@$data->leadDetails->createdBy)?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName."(C)":(@$data->ownerDetails->firstName?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName:"NA") . ",";
  2040. echo "\n";
  2041. }
  2042. } else {
  2043. $iterator = new CDataProviderIterator($dataProvider);
  2044. $file_name = "lms" . "_" . date("Y-m-d_H-i", time()) . ".csv";
  2045. header('Content-Type: text/html; charset=utf-8');
  2046. header("Content-type: application/octet-stream");
  2047. header("Content-Disposition: attachment; filename=\"$file_name\"");
  2048. header("Cache-Control: cache, must-revalidate");
  2049. header("Pragma: public");
  2050. $col = array(
  2051. 'SNO.','Name','Mobile','AgentId','Lead Desciption','Activity Desciption','Email','Lead Stage','Date and Time','Lead Status','Owner','status');
  2052. foreach ($col as $key => $value) {
  2053. echo $value . ",";
  2054. }
  2055. echo "\n";
  2056. $i=1;
  2057. foreach($iterator as $data) {
  2058. $sqlDesc = "select group_concat(description) as ActivityDescription from leadFollowup where leadId=".@$data->leadId." ";
  2059. $dataDesc=Yii::app()->db->createCommand($sqlDesc)->queryAll();
  2060. $leadActivity = @$dataDesc[0]['ActivityDescription']?@$dataDesc[0]['ActivityDescription']:'';
  2061. echo $i++ . ",";
  2062. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->name)) . ",";
  2063. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->mobile)) . ",";
  2064. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->ws_agentid)) . ",";
  2065. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadDescription)) . ",";
  2066. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$leadActivity)) . ",";
  2067. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->email)) . ",";
  2068. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data['leadStageDetails']['leadStage'])) . ",";
  2069. echo date("d/m/y h:i A",$data->createdOn) . ",";
  2070. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$data->leadStatusDetails->leadStatus)) . ",";
  2071. echo (@$data->currentAllocatedId==@$data->createdBy)?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName."(C)":(@$data->ownerDetails->firstName?@$data->ownerDetails->firstName." ".@$data->ownerDetails->lastName:"NA") . ",";
  2072. echo "\n";
  2073. }
  2074. }
  2075. }
  2076. public function actionapiPremimum()
  2077. {
  2078. $model = new Lead();
  2079. global $INDIVIDUAL,$FAMILYFLOATER,$GroupCareArray;
  2080. $INDIVIDUAL = array(
  2081. "200000" => "001",
  2082. "300000" => "003",
  2083. "400000" => "005",
  2084. "500000" => "007",
  2085. "700000" => "009",
  2086. "1000000" => "011",
  2087. "1500000" => "013",
  2088. "2000000" => "015",
  2089. "2500000" => "017",
  2090. "5000000" => "019",
  2091. "6000000" => "021"
  2092. );
  2093. $FAMILYFLOATER = array(
  2094. "200000" => "002",
  2095. "300000" => "004",
  2096. "400000" => "006",
  2097. "500000" => "008",
  2098. "700000" => "010",
  2099. "1000000" => "012",
  2100. "1500000" => "014",
  2101. "2000000" => "016",
  2102. "2500000" => "018",
  2103. "5000000" => "020",
  2104. "6000000" => "022"
  2105. );
  2106. $res = new MySanitizeClass;
  2107. $parser = new CHtmlPurifier();
  2108. if(is_array(@$_REQUEST['ageGroupOfEldestMember'])){
  2109. @$_REQUEST['ageGroupOfEldestMember'] = '';
  2110. } else {
  2111. @$_REQUEST['ageGroupOfEldestMember'] = @$_REQUEST['ageGroupOfEldestMember'];
  2112. }
  2113. if(is_array(@$_REQUEST['numberOfAdult'])){
  2114. @$_REQUEST['numberOfAdult'] = '';
  2115. } else {
  2116. @$_REQUEST['numberOfAdult'] = @$_REQUEST['numberOfAdult'];
  2117. }
  2118. if(is_array(@$_REQUEST['coverTypeCd'])){
  2119. @$_REQUEST['coverTypeCd'] = '';
  2120. } else {
  2121. @$_REQUEST['coverTypeCd'] = @$_REQUEST['coverTypeCd'];
  2122. }
  2123. if(is_array(@$_REQUEST['numberOfChildren'])){
  2124. @$_REQUEST['numberOfChildren'] = '';
  2125. } else {
  2126. @$_REQUEST['numberOfChildren'] = @$_REQUEST['numberOfChildren'];
  2127. }
  2128. if(is_array(@$_REQUEST['productId'])){
  2129. @$_REQUEST['productId'] = '';
  2130. } else {
  2131. @$_REQUEST['productId'] = @$_REQUEST['productId'];
  2132. }
  2133. if(is_array(@$_REQUEST['productTerm'])){
  2134. @$_REQUEST['productTerm'] = '';
  2135. } else {
  2136. @$_REQUEST['productTerm'] = @$_REQUEST['productTerm'];
  2137. }
  2138. if(is_array(@$_REQUEST['sumInsured'])){
  2139. @$_REQUEST['sumInsured'] = '';
  2140. } else {
  2141. @$_REQUEST['sumInsured'] = @$_REQUEST['sumInsured'];
  2142. }
  2143. if(is_array(@$_REQUEST['tenure'])){
  2144. @$_REQUEST['tenure'] = '';
  2145. } else {
  2146. @$_REQUEST['tenure'] = @$_REQUEST['tenure'];
  2147. }
  2148. $query['ageGroupOfEldestMember']=$parser->purify(@$_REQUEST['ageGroupOfEldestMember']);
  2149. $query['coverTypeCd']=$parser->purify(@$_REQUEST['coverTypeCd']);
  2150. $query['productId']=$parser->purify(@$productId1);
  2151. $query['productTerm']=$parser->purify(@$_REQUEST['productTerm']);
  2152. $query['sumInsured']=$parser->purify(@$_REQUEST['sumInsured']);
  2153. if(@$_REQUEST['coverTypeCd']=="INDIVIDUAL"){
  2154. $sumInsured=$parser->purify(intval(@$_REQUEST['sumInsured']));
  2155. if(@$sumInsured>0){
  2156. $sumInsured1=@$INDIVIDUAL[@$sumInsured];
  2157. }
  2158. $query['numberOfAdult']=$parser->purify(@$_REQUEST['numberOfAdult']);
  2159. $query['numberOfChildren']=0;
  2160. }else{
  2161. $sumInsured=$parser->purify(intval(@$_REQUEST['sumInsured']));
  2162. if(@$sumInsured>0){
  2163. $sumInsured1=@$FAMILYFLOATER[@$sumInsured];
  2164. }
  2165. $query['numberOfAdult']=$parser->purify(@$_REQUEST['numberOfAdult']);
  2166. $query['numberOfChildren']=$parser->purify(@$_REQUEST['numberOfChildren']);
  2167. }
  2168. $query['sumInsured1']=@$sumInsured1;
  2169. /*$_SESSION['ageGroupOfEldestMember']=@$query['ageGroupOfEldestMember'];// assign value to session for product tab
  2170. $_SESSION['coverTypeCd'] =@$query['coverTypeCd'];// assign value to session for product tab
  2171. $_SESSION['numberOfAdult'] =@$query['numberOfAdult']+$query['numberOfChildren'];// assign value to session for product tab
  2172. $_SESSION['numberOfChildren'] =@$query['numberOfChildren'];// assign value to session for product tab
  2173. $_SESSION['sumInsured'] =@$sumInsured;// assign value to session for product tab*/
  2174. $premiumArray=$this->csvToArray('tempdata/care_premium.csv');
  2175. $totalMember=$query['numberOfAdult']+$query['numberOfChildren'];
  2176. $planKey=$query['coverTypeCd'].":".$query['ageGroupOfEldestMember'].":".@$totalMember.":".$query['numberOfChildren'].":".$query['sumInsured1'];
  2177. $exactPremiumArray=$this->search(@$premiumArray,'Plan',@$planKey);
  2178. $exactCarePremiumArray=explode(":",@$exactPremiumArray[0]['Premium']);
  2179. $tenureidx = @$_REQUEST['tenure']-1;
  2180. $carePremium = @$exactCarePremiumArray[@$tenureidx];
  2181. //print_r($exactCarePremiumArray);
  2182. $ncppremiumArray=$this->csvToArray('tempdata/ncb_premium.csv');
  2183. $ncbtotalMember=$query['numberOfAdult']+$query['numberOfChildren'];
  2184. $ncbplanKey=$query['coverTypeCd'].":".$query['ageGroupOfEldestMember'].":".@$ncbtotalMember.":".$query['numberOfChildren'].":".$query['sumInsured1'];
  2185. $ncbexactPremiumArray=$this->search(@$ncppremiumArray,'Plan',@$ncbplanKey);
  2186. $exactNCBPremiumArray=explode(":",@$ncbexactPremiumArray[0]['Premium']);
  2187. //$tenureidx = $_REQUEST['tenure']-1;
  2188. $ncbPremium = @$exactNCBPremiumArray[@$tenureidx];
  2189. $addCarePremium = str_replace(',','',@$carePremium);
  2190. $addNCBPremium = str_replace(',','',@$ncbPremium);
  2191. $finalNcbPremium = number_format($addNCBPremium+$addCarePremium);
  2192. //print_r($premiumArray);
  2193. echo trim(@$carePremium).':'.trim(@$finalNcbPremium);
  2194. // echo @$exactPremiumArray[0]['Premium'];
  2195. //$this->render('lead_search',array('searched'=>$searched));
  2196. }
  2197. function csvToArray($csvFileName){
  2198. $row = 1;
  2199. $dataArray=array();
  2200. $columnArray=array();
  2201. $k=0;
  2202. $i=0;
  2203. if (($handle = fopen($csvFileName, "r")) !== FALSE) {
  2204. while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
  2205. $num = count($data);
  2206. if($k==0){
  2207. for ($c=0; $c < $num; $c++) {
  2208. $columnArray[$c]=@$data[$c];
  2209. }
  2210. }else{
  2211. for ($c=0; $c < $num; $c++) {
  2212. $columnName=$columnArray[$c];
  2213. $dataArray[$i][$columnName]=@$data[$c];
  2214. }
  2215. $i++;
  2216. }
  2217. $k++;
  2218. $row++;
  2219. }
  2220. fclose($handle);
  2221. }
  2222. return $dataArray;
  2223. }
  2224. function search($array, $key, $value){
  2225. $results = array();
  2226. if (is_array($array))
  2227. {
  2228. if (isset($array[$key]) && $array[$key] == $value)
  2229. $results[] = $array;
  2230. foreach ($array as $subarray){
  2231. $results = array_merge($results, $this->search($subarray, $key, $value));
  2232. }
  2233. }
  2234. return $results;
  2235. }
  2236. function quotesResults(){
  2237. }
  2238. public function actiongetPlanDetails(){
  2239. }
  2240. public function actionleadCreation(){
  2241. include_once("api/api.php");
  2242. $pageList = $this->xml2array(@file_get_contents(ADMINURL.'resource/product_subcategory.xml'),'1','');
  2243. $pageListArray = @$pageList['ProductSubCategory'];
  2244. $subcategoryList = $this->subcategory_page_array($pageListArray);
  2245. if(sanitize_data(@$_REQUEST['productId'])>0){
  2246. for($i=0; $i<count($subcategoryList); $i++){
  2247. if($subcategoryList[$i]["subCategoryId"]==sanitize_data($_REQUEST['productId']))
  2248. {
  2249. @$productId1="Care";
  2250. }
  2251. }
  2252. }else{
  2253. @$productId1="";
  2254. }
  2255. $query['coverTypeCd']=(@$_REQUEST['coverTypeCd']);
  2256. $query['productId']=@$productId1;
  2257. $query['sumInsured']=(@$_REQUEST['sumInsured']);
  2258. // if(@$_REQUEST['coverTypeCd']=="INDIVIDUAL"){
  2259. // switch(@$_REQUEST['sumInsured']){
  2260. // case '200000': $sumInsured1="001";
  2261. // break;
  2262. // case '300000': $sumInsured1="003";
  2263. // break;
  2264. // case '500000': $sumInsured1="005";
  2265. // break;
  2266. // case '1000000': $sumInsured1="007";
  2267. // break;
  2268. // default: $sumInsured1="007";
  2269. // break;
  2270. // }
  2271. // }else{
  2272. // switch(@$_REQUEST['sumInsured']){
  2273. // case '200000': $sumInsured1="002";
  2274. // break;
  2275. // case '300000': $sumInsured1="004";
  2276. // break;
  2277. // case '500000': $sumInsured1="006";
  2278. // break;
  2279. // case '1000000': $sumInsured1="008";
  2280. // break;
  2281. // default: $sumInsured1="008";
  2282. // break;
  2283. // }
  2284. // }
  2285. $tenure=(@$_REQUEST['tenure']);
  2286. $leadstage=(@$_POST['leadstage']);
  2287. $subject=(@$_POST['subject']);
  2288. $query['sumInsured1']=(@$_REQUEST['sumInsured']);
  2289. $query['firstname']=(@$_REQUEST["firstname"]);
  2290. $query['lastname']="";
  2291. $query['emailaddress1']=(@$_REQUEST["emailaddress1"]);
  2292. $query['telephone1']=(@$_REQUEST["telephone1"]);
  2293. $query['mobilephone']=(@$_REQUEST["mobilephone"]);
  2294. $query['premium']=(@$_REQUEST["premium".@$tenure]);
  2295. if(@$_SESSION['agentId']!=''){
  2296. $query['agentid']=@$_SESSION['agentId'];
  2297. }else{
  2298. $query['agentid']=AGENTID;
  2299. }
  2300. $query['noofyears']=@$tenure;
  2301. $query['quoteid']=time();
  2302. if(@$leadstage!=''){
  2303. $query['leadstage']=@$leadstage;
  2304. }else{
  2305. $query['leadstage']="SendQuotation";
  2306. }
  2307. if(@$subject!=''){
  2308. $query['subject']=@$subject." - ".(@$_REQUEST["mobilephone"]);
  2309. }else{
  2310. $query['subject']="Web-".(@$_REQUEST["mobilephone"]);
  2311. }
  2312. $dataArray= $this->LeadCreation($query);
  2313. $_SESSION["quotationReferenceNum"]=$query['quoteid'];
  2314. $_SESSION['mobileSend']="2";
  2315. $_SESSION['mobilephone']=(@$_REQUEST["mobilephone"]);
  2316. }
  2317. public function actionportalProposal(){
  2318. define("_SITEURL", "http://" . @$_SERVER['SERVER_NAME']. '/religare') ;
  2319. define("ADMINURL", "../", true);
  2320. global $INDIVIDUAL,$FAMILYFLOATER,$GroupCareArray;
  2321. $GroupCareArray = array("200000" => "2 Lac + 2 Lac", "300000" => "3 Lac + 3 Lac", "400000" => "4 Lac + 4 Lac", "500000" => "5 Lac + 5 Lac", "700000" => "7 Lac + 7 Lac", "1000000" => "10 Lac + 10 Lac", "1500000" => "15 Lac + 10 Lac", "2000000" => "20 Lac + 10 Lac", "2500000" => "25 Lac + 10 Lac", "5000000" => "50 Lac + 10 Lac", "6000000" => "60 Lac + 10 Lac");
  2322. $INDIVIDUAL = array(
  2323. "200000" => "001",
  2324. "300000" => "003",
  2325. "400000" => "005",
  2326. "500000" => "007",
  2327. "700000" => "009",
  2328. "1000000" => "011",
  2329. "1500000" => "013",
  2330. "2000000" => "015",
  2331. "2500000" => "017",
  2332. "5000000" => "019",
  2333. "6000000" => "021"
  2334. );
  2335. $FAMILYFLOATER = array(
  2336. "200000" => "002",
  2337. "300000" => "004",
  2338. "400000" => "006",
  2339. "500000" => "008",
  2340. "700000" => "010",
  2341. "1000000" => "012",
  2342. "1500000" => "014",
  2343. "2000000" => "016",
  2344. "2500000" => "018",
  2345. "5000000" => "020",
  2346. "6000000" => "022"
  2347. );
  2348. $WEBSUMINSURED = array(
  2349. "200000" => "1",
  2350. "300000" => "2",
  2351. "400000" => "3",
  2352. "500000" => "4",
  2353. "700000" => "5",
  2354. "1000000" => "6",
  2355. "1500000" => "7",
  2356. "2000000" => "8",
  2357. "2500000" => "9",
  2358. "5000000" => "10",
  2359. "6000000" => "11"
  2360. );
  2361. $WEBSUMINSURED1 = array(
  2362. "1" => "200000",
  2363. "2" => "300000",
  2364. "3" => "400000",
  2365. "4" => "500000",
  2366. "5" => "700000",
  2367. "6" => "1000000",
  2368. "7" => "1500000",
  2369. "8" => "2000000",
  2370. "9" => "2500000",
  2371. "10" => "5000000",
  2372. "11" => "6000000"
  2373. );
  2374. $proposalURL="https://rhicluat.religare.com/portalui/PortalExtProposal.run";
  2375. $pageList = $this->xml2array(@file_get_contents('resource/product_subcategory.xml'),'1','');
  2376. $pageListArray = @$pageList['ProductSubCategory'];
  2377. $subcategoryList = $this->subcategory_page_array($pageListArray);
  2378. $productId=(@$_POST['productId']);
  2379. $sumInsured=(@$_POST['sumInsured']);
  2380. $tenure=(@$_POST['premium']);
  2381. $totalAdults=(@$_POST['numberOfAdult']);
  2382. $numberOfChildren=(@$_POST['numberOfChildren']);
  2383. $numberOfAdult=$totalAdults-$numberOfChildren;
  2384. $mobileNumber=(@$_POST['mobile']);
  2385. $_SESSION['mobilephone']=$mobileNumber;
  2386. if($productId>0){
  2387. for($i=0; $i<count($subcategoryList); $i++){
  2388. if($subcategoryList[$i]["subCategoryId"]==$productId)
  2389. {
  2390. @$productId1=$subcategoryList[$i]["productCode"];
  2391. }
  2392. }
  2393. }else{
  2394. @$productId1="";
  2395. }
  2396. if(($tenure==1) || ($tenure==2) || ($tenure==3)){}else{header("Location: "._SITEURL);exit;}
  2397. if($productId1==""){header("Location: "._SITEURL);exit;}else{}
  2398. if(($numberOfChildren==0) || ($numberOfChildren==1) || ($numberOfChildren==2) || ($numberOfChildren==3) || ($numberOfChildren==4)){}else{ header("Location: "._SITEURL);exit;}
  2399. if($totalAdults>1){
  2400. $ageGroupOfEldestMember=(@$_POST['ageGroupOfEldestMember']);
  2401. switch($ageGroupOfEldestMember){
  2402. case '18 - 24': $ageGroupOfEldestMember="18 - 24";
  2403. break;
  2404. case '25 - 35': $ageGroupOfEldestMember="25 - 35";
  2405. break;
  2406. case '36 - 40': $ageGroupOfEldestMember="36 - 40";
  2407. break;
  2408. case '41 - 45': $ageGroupOfEldestMember="41 - 45";
  2409. break;
  2410. case '46 - 50': $ageGroupOfEldestMember="46 - 50";
  2411. break;
  2412. case '51 - 55': $ageGroupOfEldestMember="51 - 55";
  2413. break;
  2414. case '56 - 60': $ageGroupOfEldestMember="56 - 60";
  2415. break;
  2416. case '61 - 65': $ageGroupOfEldestMember="61 - 65";
  2417. break;
  2418. case '66 - 70': $ageGroupOfEldestMember="66 - 70";
  2419. break;
  2420. case '71 - 75': $ageGroupOfEldestMember="71 - 75";
  2421. break;
  2422. case '76 - 99': $ageGroupOfEldestMember="76 - 99";
  2423. break;
  2424. default: $ageGroupOfEldestMember="";
  2425. break;
  2426. }
  2427. if($ageGroupOfEldestMember==""){header("Location: "._SITEURL);exit;}else{}
  2428. $coverType="FAMILYFLOATER";
  2429. if(@$sumInsured>0){
  2430. $sumInsured1=$FAMILYFLOATER[@$sumInsured];
  2431. }
  2432. if($sumInsured1==""){header("Location: "._SITEURL);exit;}else{}
  2433. //$url1="&numberOfAdult=".@$numberOfAdult."&numberOfChildren=".@$numberOfChildren;
  2434. // $url="Location: ".@$proposalURL."?productFamily=HEALTH&pCode=".@$productId1."&coverType=FAMILYFLOATER&ageGroupOfEldestMember=".@$ageGroupOfEldestMember."&sumInsured=".@$sumInsured1."&tenure=".@$tenure.$url1."&mobileNum=".@$_POST['mobile'];
  2435. }else if($totalAdults=="1"){
  2436. $ageGroupOfEldestMember=@$_POST['ageGroupOfEldestMember'];
  2437. switch($ageGroupOfEldestMember){
  2438. case '5 - 24': $ageGroupOfEldestMember="5 - 24";
  2439. break;
  2440. case '25 - 35': $ageGroupOfEldestMember="25 - 35";
  2441. break;
  2442. case '36 - 40': $ageGroupOfEldestMember="36 - 40";
  2443. break;
  2444. case '41 - 45': $ageGroupOfEldestMember="41 - 45";
  2445. break;
  2446. case '46 - 50': $ageGroupOfEldestMember="46 - 50";
  2447. break;
  2448. case '51 - 55': $ageGroupOfEldestMember="51 - 55";
  2449. break;
  2450. case '56 - 60': $ageGroupOfEldestMember="56 - 60";
  2451. break;
  2452. case '61 - 65': $ageGroupOfEldestMember="61 - 65";
  2453. break;
  2454. case '66 - 70': $ageGroupOfEldestMember="66 - 70";
  2455. break;
  2456. case '71 - 75': $ageGroupOfEldestMember="71 - 75";
  2457. break;
  2458. case '76 - 99': $ageGroupOfEldestMember="76 - 99";
  2459. break;
  2460. default: $ageGroupOfEldestMember="";
  2461. break;
  2462. }
  2463. $coverType="INDIVIDUAL";
  2464. if($ageGroupOfEldestMember==""){header("Location: "._SITEURL);exit;}else{}
  2465. if(@$sumInsured>0){
  2466. $sumInsured1=$INDIVIDUAL[@$sumInsured];
  2467. }
  2468. if($sumInsured1==""){header("Location: "._SITEURL);exit;}else{}
  2469. $numberOfAdult=0;
  2470. $numberOfChildren=0;
  2471. // $url1="&numberOfAdult=0&numberOfChildren=0";
  2472. //$url="Location: ".@$proposalURL."?productFamily=HEALTH&pCode=".@$productId1."&coverType=INDIVIDUAL&ageGroupOfEldestMember=".@$ageGroupOfEldestMember."&sumInsured=".@$sumInsured1."&tenure=".@$tenure.$url1."&mobileNum=".@$_SESSION['mobilephone'];
  2473. }else{
  2474. header("Location: "._SITEURL);exit;
  2475. }
  2476. ?>
  2477. <form name="PortalProposal" id="PortalProposal" method="post" action="<?=@$proposalURL;?>">
  2478. <input type="hidden" name="productFamily" value="HEALTH" />
  2479. <input type="hidden" name="pCode" value="<?=@$productId1;?>" />
  2480. <input type="hidden" name="coverType" value="<?=@$coverType;?>" />
  2481. <input type="hidden" name="ageGroupOfEldestMember" value="<?=@$ageGroupOfEldestMember;?>" />
  2482. <input type="hidden" name="sumInsured" value="<?=@$sumInsured1;?>" />
  2483. <input type="hidden" name="tenure" value="<?=@$tenure;?>" />
  2484. <input type="hidden" name="numberOfAdult" value="<?=@$numberOfAdult;?>" />
  2485. <input type="hidden" name="numberOfChildren" value="<?=@$numberOfChildren;?>" />
  2486. <input type="hidden" name="mobileNum" value="<?=@$mobileNumber;?>" />
  2487. <input type="hidden" name="quotationReferenceNum" value="<?=@$_SESSION['quotationReferenceNum'];?>" />
  2488. <input type="hidden" name="agentId" value="<?=@$_SESSION['agentId'];?>" />
  2489. </form>
  2490. <script>
  2491. document.PortalProposal.submit();
  2492. </script>
  2493. <?php
  2494. }
  2495. function xml2array($contents, $get_attributes=1, $priority = 'tag'){
  2496. if(!$contents) return array();
  2497. if(!function_exists('xml_parser_create')) {
  2498. //print "'xml_parser_create()' function not found!";
  2499. return array();
  2500. }
  2501. //Get the XML parser of PHP - PHP must have this module for the parser to work
  2502. $parser = xml_parser_create('');
  2503. xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); # http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
  2504. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  2505. xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  2506. xml_parse_into_struct($parser, trim($contents), $xml_values);
  2507. xml_parser_free($parser);
  2508. if(!$xml_values) return;//Hmm...
  2509. //Initializations
  2510. $xml_array = array();
  2511. $parents = array();
  2512. $opened_tags = array();
  2513. $arr = array();
  2514. $current = &$xml_array; //Refference
  2515. //Go through the tags.
  2516. $repeated_tag_index = array();//Multiple tags with same name will be turned into an array
  2517. foreach($xml_values as $data) {
  2518. unset($attributes,$value);//Remove existing values, or there will be trouble
  2519. //This command will extract these variables into the foreach scope
  2520. // tag(string), type(string), level(int), attributes(array).
  2521. extract($data);//We could use the array by itself, but this cooler.
  2522. $result = array();
  2523. $attributes_data = array();
  2524. if(isset($value)) {
  2525. if($priority == 'tag') $result = $value;
  2526. else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode
  2527. }
  2528. //Set the attributes too.
  2529. if(isset($attributes) and $get_attributes) {
  2530. foreach($attributes as $attr => $val) {
  2531. if($priority == 'tag') $attributes_data[$attr] = $val;
  2532. else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
  2533. }
  2534. }
  2535. //See tag status and do the needed.
  2536. if($type == "open") {//The starting of the tag '<tag>'
  2537. $parent[$level-1] = &$current;
  2538. if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
  2539. $current[$tag] = $result;
  2540. if($attributes_data) $current[$tag. '_attr'] = $attributes_data;
  2541. $repeated_tag_index[$tag.'_'.$level] = 1;
  2542. $current = &$current[$tag];
  2543. } else { //There was another element with the same tag name
  2544. if(isset($current[$tag][0])) {//If there is a 0th element it is already an array
  2545. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
  2546. $repeated_tag_index[$tag.'_'.$level]++;
  2547. } else {//This section will make the value an array if multiple tags with the same name appear together
  2548. $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array
  2549. $repeated_tag_index[$tag.'_'.$level] = 2;
  2550. if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
  2551. $current[$tag]['0_attr'] = $current[$tag.'_attr'];
  2552. unset($current[$tag.'_attr']);
  2553. }
  2554. }
  2555. $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1;
  2556. $current = &$current[$tag][$last_item_index];
  2557. }
  2558. } elseif($type == "complete") { //Tags that ends in 1 line '<tag />'
  2559. //See if the key is already taken.
  2560. if(!isset($current[$tag])) { //New Key
  2561. $current[$tag] = $result;
  2562. $repeated_tag_index[$tag.'_'.$level] = 1;
  2563. if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data;
  2564. } else { //If taken, put all things inside a list(array)
  2565. if(isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array...
  2566. // ...push the new element into that array.
  2567. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
  2568. if($priority == 'tag' and $get_attributes and $attributes_data) {
  2569. $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
  2570. }
  2571. $repeated_tag_index[$tag.'_'.$level]++;
  2572. } else { //If it is not an array...
  2573. $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value
  2574. $repeated_tag_index[$tag.'_'.$level] = 1;
  2575. if($priority == 'tag' and $get_attributes) {
  2576. if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
  2577. $current[$tag]['0_attr'] = $current[$tag.'_attr'];
  2578. unset($current[$tag.'_attr']);
  2579. }
  2580. if($attributes_data) {
  2581. $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
  2582. }
  2583. }
  2584. $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken
  2585. }
  2586. }
  2587. } elseif($type == 'close') { //End of tag '</tag>'
  2588. $current = &$parent[$level-1];
  2589. }
  2590. }
  2591. return($xml_array);
  2592. }
  2593. function subcategory_page_array($pageListArray1){
  2594. $m =0;
  2595. $dataArr=array();
  2596. if(is_array(@$pageListArray1['subcategory'][0]) ) {
  2597. $pageListArray = $pageListArray1['subcategory'];
  2598. for($i=0;$i<sizeof($pageListArray);$i++) {
  2599. if(trim($pageListArray[$i]['isDeleted']['value'])=='no'){
  2600. $dataArr[$m]['subCategoryId'] = trim($pageListArray[$i]['subCategoryId']['value']);
  2601. $dataArr[$m]['categoryId'] =trim(@$pageListArray[$i]['categoryId']['value']);
  2602. $dataArr[$m]['subCategoryName'] = @$pageListArray[$i]['subCategoryName']['value'];
  2603. $dataArr[$m]['productCode'] = @$pageListArray[$i]['productCode']['value'];
  2604. $dataArr[$m]['description'] = @$pageListArray[$i]['description']['value'];
  2605. $dataArr[$m]['briefDescription'] = @$pageListArray[$i]['briefDescription']['value'];
  2606. $dataArr[$m]['metaTitle'] = @$pageListArray[$i]['metaTitle']['value'];
  2607. $dataArr[$m]['metaDescription'] = @$pageListArray[$i]['metaDescription']['value'];
  2608. $dataArr[$m]['metaKeywords'] = @$pageListArray[$i]['metaKeywords']['value'];
  2609. $dataArr[$m]['compare'] = @$pageListArray[$i]['compare']['value'];
  2610. $dataArr[$m]['exclusions'] =@$pageListArray[$i]['exclusions']['value'];
  2611. $dataArr[$m]['policyTerms'] =@$pageListArray[$i]['policyTerms']['value'];
  2612. $dataArr[$m]['agentpolicyTerms'] =@$pageListArray[$i]['agentpolicyTerms']['value'];
  2613. $dataArr[$m]['claim'] = @$pageListArray[$i]['claim']['value'];
  2614. $dataArr[$m]['logo'] = @$pageListArray[$i]['logo']['value'];
  2615. $dataArr[$m]['thumbnail'] = @$pageListArray[$i]['thumbnail']['value'];
  2616. $dataArr[$m]['isDeleted'] = trim($pageListArray[$i]['isDeleted']['value']);
  2617. $m++;
  2618. }
  2619. }
  2620. }else {
  2621. $pageListArray = @$pageListArray1['subcategory'];
  2622. if(trim($pageListArray['isDeleted']['value']) =='no') {
  2623. $dataArr[$m]['subCategoryId'] = trim($pageListArray['subCategoryId']['value']);
  2624. $dataArr[$m]['categoryId'] = trim($pageListArray['categoryId']['value']);
  2625. $dataArr[$m]['subCategoryName'] = $pageListArray['subCategoryName']['value'];
  2626. $dataArr[$m]['productCode'] = @$pageListArray['productCode']['value'];
  2627. $dataArr[$m]['description'] = $pageListArray['description']['value'];
  2628. $dataArr[$m]['briefDescription']= $pageListArray['briefDescription']['value'];
  2629. $dataArr[$m]['metaTitle'] = $pageListArray['metaTitle']['value'];
  2630. $dataArr[$m]['metaDescription'] = $pageListArray['metaDescription']['value'];
  2631. $dataArr[$m]['metaKeywords'] = $pageListArray['metaKeywords']['value'];
  2632. $dataArr[$m]['compare'] = $pageListArray['compare']['value'];
  2633. $dataArr[$m]['exclusions'] = $pageListArray['exclusions']['value'];
  2634. $dataArr[$m]['claim'] = $pageListArray['claim']['value'];
  2635. $dataArr[$m]['policyTerms'] =@$pageListArray['policyTerms']['value'];
  2636. $dataArr[$m]['agentpolicyTerms'] =@$pageListArray['agentpolicyTerms']['value'];
  2637. $dataArr[$m]['logo'] = @$pageListArray['logo']['value'];
  2638. $dataArr[$m]['thumbnail'] = @$pageListArray['thumbnail']['value'];
  2639. $dataArr[$m]['isDeleted'] = trim($pageListArray[$i]['isDeleted']['value']);
  2640. $m++;
  2641. }
  2642. }
  2643. //sort by
  2644. if (count ($dataArr) > 0) {
  2645. foreach ($dataArr as $key => $row) {
  2646. @$order_in_category[$key] = $row[0];//[0] is @$order_in_category
  2647. }
  2648. @array_multisort(@$order_in_category, SORT_ASC, $dataArr);
  2649. }
  2650. return $dataArr;
  2651. }
  2652. public function actiongetWebserviceLeadXMLResponse(){
  2653. $data='';
  2654. $leadURL=$_SERVER['DOCUMENT_ROOT']."/religarewebservices/data";
  2655. $r=0;
  2656. foreach(glob($leadURL . '/*request.xml') as $files){
  2657. $checkLeadExistorNot=Lead::model()->findByAttributes(array('fileName'=>$files));
  2658. if(count($checkLeadExistorNot)==0){
  2659. $data=file_get_contents($files);
  2660. $result=$this->xml2array($data);
  2661. $createdLeadDetails=$result['SOAP:Envelope']['SOAP:Body']['Createlead']['Lead'];
  2662. $OrganizationName=$result['SOAP:Envelope']['SOAP:Body']['Createlead']['OrganizationName'];
  2663. $type='Lead';
  2664. $leadsourceCode=$createdLeadDetails['leadsourcecode'];
  2665. $subject=$createdLeadDetails['subject'];
  2666. $firstname=$createdLeadDetails['firstname'];
  2667. $lastname=$createdLeadDetails['lastname'];
  2668. $emailaddress1=$createdLeadDetails['emailaddress1'];
  2669. $telephone1=$createdLeadDetails['telephone1'];
  2670. $mobilephone=$createdLeadDetails['mobilephone'];
  2671. $product=$createdLeadDetails['rhi_product'];
  2672. $suminsured=$createdLeadDetails['rhi_suminsured'];
  2673. $suminsured=(count($suminsured) > 0)?$suminsured:0;
  2674. $premium=$createdLeadDetails['rhi_premium'];
  2675. $premium=(count($premium) > 0)?$premium:0;
  2676. $quoteid=$createdLeadDetails['rhi_quoteid'];
  2677. $proposalid=$createdLeadDetails['rhi_proposalid'];
  2678. $leadstage=$createdLeadDetails['rhi_leadstage'];
  2679. $agentid=$createdLeadDetails['rhi_agentid'];
  2680. $noofyears=$createdLeadDetails['rhi_noofyears'];
  2681. $ProductMaster=ProductMaster::model()->findByAttributes(array('productName'=>$product));
  2682. $productId=$ProductMaster['productId'];
  2683. if(count($result) > 0){
  2684. //echo $files;
  2685. $model = new Lead;
  2686. $model->setAttributes(array(
  2687. 'name' => 'web services',
  2688. 'email' => '',
  2689. 'mobile' => $mobilephone,
  2690. 'productId' => $productId,
  2691. 'members' => 0,
  2692. 'si' => $suminsured,
  2693. 'premium' => $premium,
  2694. 'leadStageId' => '',
  2695. 'fileName' => addslashes($files),
  2696. 'status' => 'Active',
  2697. 'createdOn' => time(),
  2698. 'updatedOn' => time(),
  2699. 'updatedBy' => time(),
  2700. 'createdBy' => time(),
  2701. ));
  2702. //print_r($model);
  2703. $model->isNewRecord = true;
  2704. @$model->save(false);
  2705. } $r++;
  2706. }
  2707. }
  2708. $this->redirect(array('leads/lead_list'));
  2709. }
  2710. public function actionfresh_leads()
  2711. {
  2712. //$modelLead = Lead::model()->findAll("leadStatusId = '34' AND currentAllocatedId<1 ");
  2713. $this->render('fresh_lead_list');
  2714. }
  2715. public function actionviewAllTeams() {
  2716. if (!Yii::app()->request->isAjaxRequest){
  2717. }
  2718. else {
  2719. $this->renderPartial('/leads/partialAllTeamDetails');
  2720. Yii::app()->end();
  2721. }
  2722. }
  2723. public function actionViewLeadActivity() {
  2724. $followupId=@$_REQUEST['id'];
  2725. $model=new LeadFollowup;
  2726. $model=LeadFollowup::model()->findByPk($followupId);
  2727. if (!Yii::app()->request->isAjaxRequest){
  2728. // $this->render('yourView');
  2729. }
  2730. else {
  2731. $this->renderPartial('/leads/ViewLeadActivity',array('model'=>$model));
  2732. Yii::app()->end();
  2733. }
  2734. }
  2735. public function actionViewCalenderActs() {
  2736. //$cs = Yii::app()->getClientScript(); $cs->registerCoreScript('jquery');
  2737. $this->layout=false;
  2738. $startDate=@$_REQUEST['id'];
  2739. $model = LeadFollowup::model()->findAll(array("condition"=>"startDate = '".@$startDate."' AND userId = '".@$_SESSION['id']."' AND STATUS = 'Pending' AND (actionType = 'Meeting' OR actionType = 'Follow Up') ORDER BY hour DESC"));
  2740. if (!Yii::app()->request->isAjaxRequest){
  2741. $this->renderPartial('/leads/ViewCalenderActs',array('model'=>$model,'startDate'=>@$startDate));
  2742. }
  2743. else {
  2744. $this->renderPartial('/leads/ViewCalenderActs',array('model'=>$model,'startDate'=>@$startDate));
  2745. Yii::app()->end();
  2746. }
  2747. }
  2748. public function actionEditCalenderActivity() {
  2749. $this->layout=false;
  2750. $leadId=@$_REQUEST['leadId'];
  2751. $actionId=@$_REQUEST['actionId'];
  2752. $this->renderPartial('EditCalenderActivity',array('leadId'=>$leadId,'actionId'=>$actionId) ,false, true);
  2753. Yii::app()->end();
  2754. }
  2755. public function actiongetActionRes(){
  2756. $statusids = @$_POST['statusids'];
  2757. $model = new LeadStatus;
  2758. $model=LeadStatus::model()->findByPk($statusids);
  2759. echo $result = @$model['actionCompulsary'];
  2760. }
  2761. public function actioncip_lead_list()
  2762. {
  2763. //$model = new LeadStatus;
  2764. $this->render('contact_in_progress_lead_list');
  2765. }
  2766. public function actioncld_lead_list()
  2767. {
  2768. //$model = new Lead;
  2769. $this->render('cld_lead_list');
  2770. }
  2771. public function actionsearchCIP(){
  2772. if(Yii::app()->request->isAjaxRequest==1){
  2773. $models=new Lead();
  2774. $searchIDs =@$_REQUEST['searchIDs'];
  2775. if(isset($searchIDs) && !empty($searchIDs)){
  2776. $this->renderPartial('partialcip',array('searchTxt'=>$searchIDs,'type'=>'cip'));
  2777. }
  2778. } else {
  2779. $redirectUrl = Yii::app()->controller->id."/".$this->action->id;
  2780. $this->redirect("index.php?r=leads/cip_lead_list&pageSize=".@$_REQUEST['pageSize']);
  2781. }
  2782. }
  2783. public function actiondup_forthe_day_lead_list()
  2784. {
  2785. //$modelLead = new Lead;
  2786. $this->render('duplicate_forthe_daylead_list');
  2787. }
  2788. public function actionSearchArchiveLeads(){
  2789. $model = new Lead;
  2790. $teamId = @$_POST['Team']['teamId'];
  2791. $Leadname = @$_POST['Lead']['name'];
  2792. $Leadstatus = @$_POST['Lead']['status'];
  2793. $leadStage = @$_POST['Lead']['leadStage'];
  2794. $leadws_agentid = @$_POST['Lead']['ws_agentid'];
  2795. $leademail = @$_POST['Lead']['email'];
  2796. $leadmobile = @$_POST['Lead']['mobile'];
  2797. $this->render('archive_leads',array('model'=>$model,'teamId'=>$teamId,'Leadname'=>$Leadname,'Leadstatus'=>$Leadstatus,'leadStage'=>$leadStage,'Leadmobile'=>$leadmobile,'Leademail'=>$leademail,'Leadws_agentid'=>$leadws_agentid));
  2798. }
  2799. public function actionplc_lead_list()
  2800. {
  2801. //$model = new Lead;
  2802. $this->render('plc_lead_list');
  2803. }
  2804. public function getAgentIds($ws_agentid,$mobile){
  2805. $agentIds=Yii::app()->db->createCommand("select group_concat(distinct ws_agentid) as ws_agentid,count(distinct ws_agentid) as total from lead where mobile='".@$mobile."' and ws_agentid!='' order by leadId desc ")->queryAll();
  2806. if( $agentIds[0]['total'] > 1){
  2807. echo "<label class='linkUnderline' title='".@$agentIds[0]['ws_agentid']."'><a href='#'>".$ws_agentid."</a></label>";
  2808. } else if($agentIds[0]['total'] == 1) {
  2809. echo "<label title='".@$agentIds[0]['ws_agentid']."'><a href='#'>".$ws_agentid."</a></label>";
  2810. } else {
  2811. echo "";
  2812. }
  2813. //echo explode(',',$agentId);
  2814. }
  2815. public function getLeadStagesIds($leadStageId,$mobile){
  2816. $agentIds=Yii::app()->db->createCommand("select distinct leadStageId from lead where mobile='".@$mobile."' and leadStageId!='' order by leadId desc ")->queryAll();
  2817. $displayedSyage=Yii::app()->db->createCommand("select leadStage from leadStageMaster where leadStageId='".@$leadStageId."' ")->queryAll();
  2818. if(count($agentIds) > 0) {
  2819. for($i=0;$i<count($agentIds);$i++){
  2820. $leadstages=Yii::app()->db->createCommand("select leadStage from leadStageMaster where leadStageId='".@$agentIds[$i]['leadStageId']."' ")->queryAll();
  2821. $agentId[] = @$agentIds[$i]['leadStageId'];
  2822. $leadstages_new[] = @$leadstages[0]['leadStage'];
  2823. }
  2824. } else {
  2825. echo "";
  2826. }
  2827. if( count(@$leadstages_new) > 1){
  2828. echo "<label class='linkUnderline' title='".implode(',',$leadstages_new)."'><a href='#'>".@$displayedSyage[0]['leadStage']."</a></label>";
  2829. } else if( count(@$leadstages_new) == 1) {
  2830. echo "<label title='".implode(',',@$leadstages_new)."'><a href='#'>".@$displayedSyage[0]['leadStage']."</a></label>";
  2831. } else {
  2832. echo "";
  2833. }
  2834. //echo explode(',',$agentId);
  2835. }
  2836. public function actioninactive_users_leads()
  2837. {
  2838. $this->render('inactive_users_leads');
  2839. }
  2840. public function actionInactiveAllocateLeads()
  2841. {
  2842. $Id = $_REQUEST['userids'];
  2843. $teamId = @$_REQUEST['Team']['teamId'];
  2844. $userId = $_REQUEST['Team']['teamMemberId'];
  2845. $updatedBy = @$_SESSION['id'];
  2846. foreach($Id as $key=>$value){
  2847. $model = new AllocatedLeads();
  2848. $model->scenario = 'AllocatedLeads';
  2849. $model->setAttributes(array(
  2850. 'currentAllocatedDate' => time(), //additional data you want to insert
  2851. 'createdOn' => time(), //additional data you want to insert
  2852. 'updatedOn' => time(), //additional
  2853. 'updatedBy' => @$updatedBy, //additional
  2854. 'createdBy' => @$updatedBy, //additional
  2855. 'leadStatusId' => '35', //additional //additional
  2856. ));
  2857. $leadId = @$value;
  2858. $model->leadId = @$value;
  2859. $model->userId = @$userId;
  2860. $model->teamId = @$teamId;
  2861. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  2862. $model->allocatedId = null;
  2863. $model->isNewRecord = true;
  2864. $model->save();
  2865. $model=new Lead();
  2866. $model->scenario = 'Lead';
  2867. $updatedOn = time();
  2868. Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  2869. }
  2870. $red = @$_REQUEST['red'];
  2871. if($this->action->id=='AllocateLeads' && $red == 1) {
  2872. $this->redirect(array('leads/inactive_users_leads'));
  2873. } else {
  2874. $this->redirect(array('leads/inactive_users_leads'));
  2875. }
  2876. //$this->redirect(array('leads/lead_list'));
  2877. }
  2878. public function getLeadDescription($leadId){
  2879. $records=Yii::app()->db->createCommand("select leadDescription from lead where leadId='".@$leadId."' ")->queryAll();
  2880. if(count($records) > 0) {
  2881. for($i=0;$i<count($records);$i++){
  2882. $record[] = @$records[$i]['leadDescription'];
  2883. }
  2884. } else {
  2885. echo "";
  2886. }
  2887. if( count(@$record) > 1){
  2888. echo "<label title='".implode(',',$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
  2889. } else if( count(@$record) == 1) {
  2890. echo "<label title='".implode(',',@$record)."'><a href='#'>".implode(',',$record)."</a></label>";
  2891. } else {
  2892. echo "";
  2893. }
  2894. //echo explode(',',$agentId);
  2895. }
  2896. public function getLeadActivityDescription($leadId){
  2897. $records=Yii::app()->db->createCommand("select description from leadFollowup where leadId='".@$leadId."' ")->queryAll();
  2898. if(count($records) > 0) {
  2899. for($i=0;$i<count($records);$i++){
  2900. $record[] = @$records[$i]['description'];
  2901. }
  2902. } else {
  2903. echo "";
  2904. }
  2905. if( count(@$record) > 1){
  2906. echo "<label title='".implode(',',$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
  2907. } else if( count(@$record) == 1) {
  2908. echo "<label title='".implode(',',@$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
  2909. } else {
  2910. echo "";
  2911. }
  2912. //echo explode(',',$agentId);
  2913. }
  2914. public function actionloadleadtabs(){
  2915. $this->layout = false;
  2916. $this->renderPartial('leadTabs');
  2917. }
  2918. public function actiondeleted_database_tab()
  2919. {
  2920. $model=new Lead();
  2921. $model->set_period1=@$_POST['Lead']['period1']?@$_POST['Lead']['period1']:@$_REQUEST['period1'];
  2922. $model->set_period2=@$_POST['Lead']['period2']?@$_POST['Lead']['period2']:@$_REQUEST['period2'];
  2923. $this->render('deleted_database_tab',array('model'=>$model));
  2924. }
  2925. public function actiondelete_lead()
  2926. {
  2927. $deleteId=@$_REQUEST['leadId'];
  2928. if(Yii::app()->request->isAjaxRequest){
  2929. if(!empty($deleteId))
  2930. {
  2931. $model=Lead::model()->findByPk($deleteId);
  2932. }
  2933. else
  2934. {
  2935. $model = new Lead();
  2936. }
  2937. if($model->delete($deleteId)){
  2938. echo "Record deleted successfully";
  2939. } else {
  2940. echo "some error occured please try after some time";
  2941. }
  2942. } else {
  2943. $this->redirect(array('leads/deleted_database_tab'));
  2944. }
  2945. }
  2946. public function actionDeleteAllJunkLeads()
  2947. {
  2948. $model = new lead;
  2949. //print_r($_REQUEST);
  2950. $Id=$_REQUEST['leadids'];
  2951. foreach($Id as $key=>$value){
  2952. $model->deleteByPk($value);
  2953. }
  2954. $this->redirect(Yii::app()->request->urlReferrer);
  2955. }
  2956. public function actionDeleteAllJunkLeadsOneTime()
  2957. {
  2958. $model = new lead;
  2959. echo $startDate = @$_REQUEST['period1'];
  2960. $endDate = @$_REQUEST['period2'];
  2961. $alldeletedIds = @$_POST['alldeletedIds'];
  2962. $Id=unserialize(urldecode($_POST['alldeletedIds']));
  2963. foreach($Id as $key=>$value){
  2964. //echo $value;
  2965. $model->deleteByPk($value);
  2966. }
  2967. $modeldel = new leadsdeletedby;
  2968. $modeldel->id='';
  2969. $modeldel->startdate=@$startDate;
  2970. $modeldel->enddate=@$endDate;
  2971. $modeldel->data=$alldeletedIds;
  2972. $modeldel->deletedOn=time();
  2973. $modeldel->deletedBy=Yii::app()->session->get('userName');
  2974. $modeldel->deletedById=Yii::app()->session->get('id');
  2975. /* $modeldel->setAttributes(array(
  2976. 'id' => '', //additional data you want to insert
  2977. 'startdate' => @$startDate, //additional
  2978. 'enddate' => @$endDate, //additional
  2979. 'data' => 'sdfsdf', //additional
  2980. 'deletedOn' => time(), //additional
  2981. 'deletedBy' => Yii::app()->session->get('userName'), //additional
  2982. 'deletedById' =>Yii::app()->session->get('id'), //additional //additional
  2983. ));*/
  2984. $modeldel->save();
  2985. $this->redirect(Yii::app()->request->urlReferrer);
  2986. }
  2987. public function actionuser_monthly_report() {
  2988. $this->render('user_monthly_report');
  2989. }
  2990. public function actionuser_login_report() {
  2991. $this->render('user_login_report');
  2992. }
  2993. public function actiondownload_login_report() {
  2994. $limitvalue = @$_REQUEST['fetchrecordsBydropdown'];
  2995. $userid = @$_REQUEST['User']['id'];
  2996. if(isset($limitvalue) && !empty($limitvalue) && isset($userid) && !empty($userid)){
  2997. $paginationExcelValue = @$_POST['fetchrecordsBydropdown'];
  2998. if(isset($paginationExcelValue) && !empty($paginationExcelValue)){
  2999. $explodedpaginationValue = explode('-',$paginationExcelValue);
  3000. $startLimit = $explodedpaginationValue[0];
  3001. $endLimit = 10000;
  3002. } else {
  3003. $startLimit = '';
  3004. $endLimit = '';
  3005. }
  3006. if(isset($startLimit) && isset($endLimit) && !empty($endLimit)){
  3007. $limitCond = " limit $startLimit , $endLimit";
  3008. } else {
  3009. $limitCond = '';
  3010. }
  3011. //Here is the code to set conditions for fetch records from database
  3012. $condfilter = '';
  3013. if(isset($userid) && !empty($userid))
  3014. {
  3015. if(isset($userid) && !empty($userid))
  3016. {
  3017. $condfilter .= "t.userid = ".$userid." AND ";
  3018. }
  3019. if(isset($condfilter) && !empty($condfilter)){
  3020. $wherecon = "WHERE ";
  3021. } else {
  3022. $wherecon = "";
  3023. }
  3024. $data=Yii::app()->db->createCommand("select t.userId,t.userName,t.loginTime,t.type from userloginlog as t $wherecon $condfilter t.userId > 0 order by t.logId DESC $limitCond")->queryAll();
  3025. }else{
  3026. $data=0;
  3027. }
  3028. if(count($data)>0){
  3029. $file_name = "lms" . "_" . date("Y-m-d_H-i", time()) . ".csv";
  3030. header('Content-Type: text/html; charset=utf-8');
  3031. header("Content-type: application/octet-stream");
  3032. header("Content-Disposition: attachment; filename=\"$file_name\"");
  3033. header("Cache-Control: cache, must-revalidate");
  3034. header("Pragma: public");
  3035. $col = array(
  3036. 'SNO.','User Name','loginTime');
  3037. foreach ($col as $key => $value) {
  3038. echo $value . ",";
  3039. }
  3040. echo "\n";
  3041. $i=1;
  3042. foreach ($data as $key => $value) {
  3043. $loginTime = date("d M Y H:i:s A",$value['loginTime']);
  3044. echo $i++ . ",";
  3045. echo @$value["userName"] . ",";
  3046. echo @$loginTime . ",";
  3047. echo "\n";
  3048. }
  3049. }
  3050. else{
  3051. $this->redirect('index.php?r=leads/user_login_report');
  3052. //$dataProvider=new CActiveDataProvider('LeadReport', array('criteria'=>@$criteria,));
  3053. //$this->render('reports',array('model'=>$model,'dataProvider'=>$dataProvider));
  3054. }
  3055. } else {
  3056. $this->render('user_login_report');
  3057. }
  3058. }
  3059. public static function getMTD($leadStatusId){
  3060. $CurrentMonth_first_minute = mktime(0, 0, 0, date("n"), 1);
  3061. $CurrentMonth_last_minute = mktime(23, 59, 0, date("n"), date("t"));
  3062. $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = ".@$leadStatusId." and (l.updatedOn between '".@$CurrentMonth_first_minute."' and '".@$CurrentMonth_last_minute."') and u.status='Active' limit 1 ";
  3063. $count=Yii::app()->db->createCommand($sql)->queryColumn();
  3064. echo @$count[0];
  3065. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  3066. }
  3067. public static function getYTD($leadStatusId){
  3068. $CurrentYear_first_minute = mktime(0, 0, 0, 1, 1, date('Y'));
  3069. $CurrentYear_last_minute = mktime(0, 0, 0, 13, 0, date('Y'));
  3070. $sql = "select count(leadId) as total from lead l join user u on u.id=l.currentAllocatedId where l.leadStatusId = ".@$leadStatusId." and (l.updatedOn between '".@$CurrentYear_first_minute."' and '".@$CurrentYear_last_minute."') and u.status='Active' ";
  3071. $count=Yii::app()->db->createCommand($sql)->queryColumn();
  3072. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  3073. echo @$count[0];
  3074. }
  3075. public static function getUniqueMobLeadCountByStatus($leadStatusId){
  3076. if(isset($leadStatusId) && !empty($leadStatusId)){
  3077. $todayexpiryDate= date('d-M-Y',time());
  3078. $nontydaystime=strtotime("-90 days",strtotime($todayexpiryDate));
  3079. $date1Filer = @$_REQUEST['Lead']['createdOn'];
  3080. $date2Filer = @$_REQUEST['Lead']['createdOn2'];
  3081. $leadFilter = @$_REQUEST['LeadSourceMaster']['leadSourceId'];
  3082. $filterCond ='';
  3083. if(isset($leadFilter) && !empty($leadFilter)){
  3084. $filterCond .= " AND l.leadSourceId = ".$leadFilter."";
  3085. }
  3086. if(isset($date1Filer) && !empty($date1Filer) && isset($date2Filer) && !empty($date2Filer)){
  3087. $date1Filer = strtotime($date1Filer);
  3088. $date2Filer = strtotime($date2Filer);
  3089. $filterCond .= " AND l.createdOn >= ".$date1Filer." and l.createdOn <= ".$date2Filer."";
  3090. }
  3091. if(Yii::app()->session->get('type')=='superadmin'){
  3092. //$sql = "select mobile from lead l where l.leadStatusId=".$leadStatusId." $filterCond ";
  3093. $sql = "select count(l.mobile) as totalunique from lead l where l.leadStatusId=".$leadStatusId." and l.leadStatusId != 10 $filterCond group by l.leadStatusId ";
  3094. } else {
  3095. $impresuser = DashboardController::implodeResult(Yii::app()->session['relationalManager']);
  3096. $sql = "select count(l.mobile) as totalunique from lead l where l.leadStatusId=".$leadStatusId." and l.leadStatusId != 10 and l.currentAllocatedId IN (".@$impresuser.") $filterCond group by l.leadStatusId ";
  3097. }
  3098. //echo $res = Lead::model()->count(array("select"=>"count(distinct mobile) as totalunique","condition"=>" leadStatusId=".$leadStatusId." $filterCond "));
  3099. //$count=Yii::app()->db->createCommand($sql)->queryScalar();
  3100. $count=Yii::app()->db->createCommand($sql)->queryScalar();
  3101. /*$criteria = new CDbCriteria();
  3102. $criteria->select = "mobile";
  3103. $criteria->condition = " leadStatusId=".$leadStatusId."";
  3104. $count=Lead::model()->findAll($criteria);*/
  3105. //echo count($count);
  3106. echo @$count?@$count:0;
  3107. } else {
  3108. echo 0;
  3109. }
  3110. //echo Lead::model()->count(array("select"=>'leadid',"condition"=>" leadStatusId = ".@$leadStatusId.""));
  3111. }
  3112. }