PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/lms_debug/protected/controllers/RenewalLeadsController.php

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