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

/lms_debug/protected/controllers/LeadsController_24_feb_2014.php

https://gitlab.com/badelal143/lms_debug
PHP | 2890 lines | 2422 code | 215 blank | 253 comment | 403 complexity | 87137fca7de43a13e119048ab3b3ff12 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. class LeadsController extends Controller
  3. {
  4. const SHARED_TITLE = "Admin Panel";
  5. /**
  6. * Declares class-based actions.
  7. */
  8. public function filters()
  9. {
  10. return array( 'accessControl',array(
  11. 'CHttpCacheFilter + view',
  12. 'cacheControl' => " max-age=604800, must-revalidate",
  13. ) ); // perform access control for CRUD operations
  14. }
  15. public function actions()
  16. {
  17. return array(
  18. // captcha action renders the CAPTCHA image displayed on the contact page
  19. 'captcha'=>
  20. array(
  21. 'class'=>'CCaptchaAction',
  22. 'backColor'=>0xFFFFFF,
  23. ),
  24. // page action renders "static" pages stored under 'protected/views/site/pages'
  25. // They can be accessed via: index.php?r=site/page&view=FileName
  26. 'page'=>array(
  27. 'class'=>'CViewAction',
  28. ),
  29. );
  30. }
  31. /**
  32. * This is the 'roles' action that is invoked
  33. * when an action is not explicitly requested by users.
  34. */
  35. public function actionlead_welcome()
  36. {
  37. $model = new WelcomeMaster();
  38. $model = WelcomeMaster::model()->find("moduleId = '1' ");
  39. $this->render('lead_welcome',array('model'=>$model));
  40. }
  41. /**
  42. * This is the 'roles' action that is invoked
  43. * when an action is not explicitly requested by users.
  44. */
  45. public function actionlead_list()
  46. {
  47. $relationManager = $_SESSION['relationalManager'];
  48. $managerMemberId = implode(",",array_unique(@$relationManager));
  49. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  50. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
  51. } else {
  52. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  53. }
  54. //$modelLead = Lead::model()->findAll(" $querycondition ");
  55. $this->render('lead_list');
  56. }
  57. /**
  58. * This is the 'lead_list_allocator' action that is invoked
  59. * when an action is not explicitly requested by users.
  60. */
  61. public function actionlead_list_allocator()
  62. {
  63. // renders the view file 'protected/views/site/index.php'
  64. // using the default layout 'protected/views/layouts/main.php'
  65. $this->render('lead_list_allocator');
  66. }
  67. /**
  68. * This is the 'lead_list_allocator' action that is invoked
  69. * when an action is not explicitly requested by users.
  70. */
  71. public function actionfollowup_lead_list()
  72. {
  73. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  74. $relationManager = $_SESSION['relationalManager'];
  75. $managerMemberId = implode(",",array_unique(@$relationManager));
  76. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  77. $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
  78. } else {
  79. $querycondition = " startDate = '".@$today12PM."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  80. }
  81. //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
  82. $this->render('followup_lead_list');
  83. }
  84. public function actionfollowup_overall_lead_list()
  85. {
  86. $relationManager = $_SESSION['relationalManager'];
  87. $managerMemberId = implode(",",array_unique(@$relationManager));
  88. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  89. $querycondition = ' status="Pending" ';
  90. } else {
  91. $querycondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  92. }
  93. //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
  94. $this->render('followup_overall_lead_list');
  95. }
  96. /**
  97. * This is the 'lead_list_allocator' action that is invoked
  98. * when an action is not explicitly requested by users.
  99. */
  100. public function actionlead_list_tc()
  101. {
  102. // renders the view file 'protected/views/site/index.php'
  103. // using the default layout 'protected/views/layouts/main.php'
  104. $this->render('lead_list_tc');
  105. }
  106. /**
  107. * This is the 'lead_list_allocator' action that is invoked
  108. * when an action is not explicitly requested by users.
  109. */
  110. public function actionjunk_lead_list()
  111. {
  112. //$modelLead = Lead::model()->findAll(" leadStatusId = '36' ");
  113. $this->render('junk_lead_list');
  114. }
  115. /**
  116. * This is the 'lead_list_allocator' action that is invoked
  117. * when an action is not explicitly requested by users.
  118. */
  119. public function actionduplicate_lead_list()
  120. {
  121. //$modelLead = Lead::model()->findAll(" leadStatusId = '10' ");
  122. $this->render('duplicate_lead_list');
  123. }
  124. public function actionclose_lead_list()
  125. {
  126. //$modelLead = Lead::model()->findAll(" leadStatusId = '7' ");
  127. $this->render('close_lead_list');
  128. }
  129. /**
  130. * This is the 'lead_list_allocator' action that is invoked
  131. * when an action is not explicitly requested by users.
  132. */
  133. public function actionallocated_lead_list()
  134. {
  135. $relationManager = $_SESSION['relationalManager'];
  136. $managerMemberId = implode(",",array_unique(@$relationManager));
  137. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  138. $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
  139. } else {
  140. $querycondition = " currentAllocatedId >0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  141. }
  142. //$modelLead = Lead::model()->findAll(" $querycondition ");
  143. $this->render('allocated_lead_list');
  144. }
  145. /**
  146. * This is the 'lead_list_allocator' action that is invoked
  147. * when an action is not explicitly requested by users.
  148. */
  149. public function actionleads_details()
  150. {
  151. // renders the view file 'protected/views/site/index.php'
  152. // using the default layout 'protected/views/layouts/main.php'
  153. //for follow up
  154. if(isset($_POST['LeadFollowup'])){
  155. if(isset($_POST['LeadFollowup']['chkActionValid']) && @$_POST['LeadFollowup']['chkActionValid']==1){
  156. $res = $this->actionlead_followup(@$_POST['LeadFollowup'],@$_POST['Lead']['leadStatusId']);
  157. $decodeRes = json_decode($res);
  158. if(@$decodeRes->status == 'success'){
  159. echo CJSON::encode(array(
  160. 'status'=>'success'
  161. ));
  162. } else {
  163. echo $res;
  164. }
  165. }
  166. }
  167. // end of for follow ups
  168. $leadId = @$_GET['leadId'];
  169. $actionId = @$_REQUEST['actionId'];
  170. $actionmodel=LeadFollowup::model()->findByPk($actionId);
  171. $model = new Lead();
  172. $this->performAjaxValidation($model);
  173. $model->scenario = 'Lead';
  174. $managerMemberId = implode(",",$_SESSION['relationalManager']);
  175. $chkAllocatedLeads = $managerMemberId?Lead::model()->findAll(array("select"=>" leadId","condition"=>" leadStatusId != '26' AND leadStatusId != '25' AND currentAllocatedId IN (".@$managerMemberId.") ")):'0';
  176. $allocatedArr=array();
  177. foreach($chkAllocatedLeads as $key=>$value){
  178. $allocatedArr[]=$chkAllocatedLeads[$key]->leadId;
  179. }
  180. //print_r($allocatedArr);
  181. //die;
  182. /*if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin'){
  183. if(!in_array($leadId,$allocatedArr)){
  184. $this->redirect(array('leads/lead_list'));
  185. }
  186. }*/
  187. if(!empty($leadId)){
  188. $model=Lead::model()->findByPk($leadId);
  189. $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
  190. if(count($chkrecentlyViewed) == 0){
  191. $recentlyViewed = new recentlyViewed;
  192. $recentlyViewed->setAttributes(array(
  193. 'userId' => Yii::app()->session->get('id'),
  194. 'leadId' => $leadId,
  195. 'moduleId' => 0,
  196. 'updatedOn' => $_SESSION['id'],
  197. 'updatedBy' => $_SESSION['id'],
  198. ));
  199. $recentlyViewed->save(false);
  200. }
  201. }
  202. if(isset($_POST['Lead']))
  203. {
  204. $model->setAttributes(array(
  205. 'updatedOn' => time(), //additional
  206. 'updatedBy' => $_SESSION['id'], //additional
  207. 'status' => 'Active', //additional //additional
  208. ));
  209. $prevLeadStatusId=$model->leadStatusId;
  210. foreach($_POST['Lead'] as $name=>$value)
  211. {
  212. if($model->leadStatusId==''){
  213. $model->leadStatusId=$model->leadStatusParentId;
  214. }
  215. if($model->email=='Email'){
  216. $model->email='';
  217. }
  218. if($model->name=='Name'){
  219. $model->name='';
  220. }
  221. if($model->address=='Address'){
  222. $model->address='';
  223. }
  224. if($model->children=="Children (Less than 25 Yrs)"){
  225. $model->children='';
  226. }
  227. if($model->ageGroup=="Age of eldest member"){
  228. $model->ageGroup='';
  229. }
  230. if($model->leadStatusId==''){
  231. $model->leadStatusId=$prevLeadStatusId;
  232. }
  233. if(@$leadId!='' && $model->leadStatusId!='34' && @$model->leadStatusId!='35'){
  234. $model->isRead='yes';
  235. }
  236. $model->$name=$value;
  237. }
  238. if(@$leadId!='' && $model->leadStatusId!='34'){
  239. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  240. }
  241. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
  242. if(count($chkStatusMandatoryOrNot) > 0){
  243. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  244. if($condMandatory == 'No'){
  245. if($model->validate(array('mobile'))){
  246. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  247. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  248. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  249. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  250. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  251. $modelHistory = new LeadHistory();
  252. $modelHistory->scenario = 'LeadHistory';
  253. $modelHistory->setAttributes(array(
  254. 'leadId' => @$leadId, //additional data you want to insert
  255. 'updatedOn' => time(), //additional
  256. 'updatedBy' => $_SESSION['id'], //additional
  257. 'status' => 'Active', //additional
  258. ));
  259. foreach($_POST['Lead'] as $name1=>$value1)
  260. {
  261. if($modelHistory->leadStatusId==''){
  262. $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
  263. }
  264. if($model->leadStatusId==''){
  265. $model->leadStatusId=2;
  266. }
  267. $modelHistory->$name1=$value1;
  268. }
  269. $model->save(false);
  270. $modelHistory->save();
  271. CJSON::encode(array(
  272. 'status'=>'success'
  273. ));
  274. Yii::app()->end();
  275. }
  276. }
  277. }
  278. $model->save();
  279. if($model->validate()){
  280. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  281. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  282. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  283. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  284. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  285. $modelHistory = new LeadHistory();
  286. $modelHistory->scenario = 'LeadHistory';
  287. $modelHistory->setAttributes(array(
  288. 'leadId' => @$leadId, //additional data you want to insert
  289. 'updatedOn' => time(), //additional
  290. 'updatedBy' => $_SESSION['id'], //additional
  291. 'status' => 'Active', //additional
  292. ));
  293. foreach($_POST['Lead'] as $name1=>$value1)
  294. {
  295. if($modelHistory->leadStatusId==''){
  296. $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
  297. }
  298. if($model->leadStatusId==''){
  299. $model->leadStatusId=2;
  300. }
  301. $modelHistory->$name1=$value1;
  302. }
  303. $modelHistory->save();
  304. echo CJSON::encode(array(
  305. 'status'=>'success'
  306. ));
  307. Yii::app()->end();
  308. //Yii::app()->end();
  309. //die;
  310. //$this->redirect(array('leads/leads_details'));
  311. } else {
  312. $error = CActiveForm::validate($model);
  313. if($error!='[]')
  314. echo $error;
  315. Yii::app()->end();
  316. //$this->render('leads_details',array('model'=>$model));
  317. }
  318. } else {
  319. $this->render('leads_details',array('model'=>@$model,'actionmodel'=>@$actionmodel,'quotesmobile'=>@$model->mobile));
  320. }
  321. }
  322. protected function performAjaxValidation($models)
  323. {
  324. if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')
  325. {
  326. echo CActiveForm::validate($models);
  327. Yii::app()->end();
  328. }
  329. }
  330. /**
  331. * This is the 'lead_list_allocator' action that is invoked
  332. * when an action is not explicitly requested by users.
  333. */
  334. public function actionlead_followup()
  335. {
  336. $actionId = @$_REQUEST['actionId'];
  337. $model = new LeadFollowup();
  338. $model->scenario = 'LeadFollowup';
  339. if(isset($actionId) && !empty($actionId)){
  340. $model=LeadFollowup::model()->findByPk($actionId);
  341. } else {
  342. }
  343. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  344. $model->scenario = 'LeadFollowupTask';
  345. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  346. $model->scenario = 'LeadFollowup';
  347. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  348. $model->scenario = 'LeadFollowup';
  349. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  350. $model->scenario = 'LeadFollowupNotes';
  351. }
  352. $this->performAjaxValidation($model);
  353. if(isset($_POST['LeadFollowup']))
  354. {
  355. $userId = $_POST['LeadFollowup']['userId'];
  356. $model->setAttributes(array(
  357. 'createdOn' => time(), //additional data you want to insert
  358. 'updatedOn' => time(), //additional
  359. 'updatedBy' => @$userId, //additional
  360. 'createdBy' => @$userId, //additional
  361. 'status' => 'Pending', //additional
  362. ));
  363. foreach($_POST['LeadFollowup'] as $name=>$value)
  364. {
  365. $model->$name=$value;
  366. }
  367. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  368. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  369. $prefix=substr(time(),0,5);
  370. $folder = 'siteupload/';
  371. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  372. if($model->notesFile !='')
  373. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  374. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  375. }
  376. if(@$_POST['LeadFollowup']['startDate']!='') {
  377. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  378. $model->startDate=@$startDateVal;
  379. if(@$_POST['LeadFollowup']['hour']!='') {
  380. $model->startDateWithTime=(@$startDateVal-300)+(@$_POST['LeadFollowup']['hour']*3600)+(@$_POST['LeadFollowup']['minutes']*60);
  381. }
  382. }
  383. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  384. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  385. $model->taskDueDate=@$taskDueDateVal;
  386. }
  387. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  388. $model->taskCompleted='yes';
  389. }
  390. if($model->validate()){
  391. $model->save();
  392. $leadId = $_POST['LeadFollowup']['leadId'];
  393. return CJSON::encode(array(
  394. 'status'=>'success'
  395. ));
  396. Yii::app()->end();
  397. } else {
  398. $error = CActiveForm::validate($model);
  399. if($error!='[]')
  400. return $error;
  401. Yii::app()->end();
  402. }
  403. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  404. }
  405. $this->redirect(array('leads/lead_list'));
  406. }
  407. /**
  408. * This is the 'lead_list_allocator' action that is invoked
  409. * when an action is not explicitly requested by users.
  410. */
  411. public function actionlead_followupcalender()
  412. {
  413. $actionId = @$_REQUEST['actionId'];
  414. $model = new LeadFollowup();
  415. $model->scenario = 'LeadFollowup';
  416. if(isset($actionId) && !empty($actionId)){
  417. $model=LeadFollowup::model()->findByPk($actionId);
  418. } else {
  419. }
  420. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  421. $model->scenario = 'LeadFollowupTask';
  422. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  423. $model->scenario = 'LeadFollowup';
  424. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  425. $model->scenario = 'LeadFollowup';
  426. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  427. $model->scenario = 'LeadFollowupNotes';
  428. }
  429. $this->performAjaxValidation($model);
  430. if(isset($_POST['LeadFollowup']))
  431. {
  432. $userId = $_POST['LeadFollowup']['userId'];
  433. $model->setAttributes(array(
  434. 'createdOn' => time(), //additional data you want to insert
  435. 'updatedOn' => time(), //additional
  436. 'updatedBy' => @$userId, //additional
  437. 'createdBy' => @$userId, //additional
  438. 'status' => 'Pending', //additional
  439. ));
  440. foreach($_POST['LeadFollowup'] as $name=>$value)
  441. {
  442. $model->$name=$value;
  443. }
  444. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  445. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  446. $prefix=substr(time(),0,5);
  447. $folder = 'siteupload/';
  448. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  449. if($model->notesFile !='')
  450. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  451. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  452. }
  453. if(@$_POST['LeadFollowup']['startDate']!='') {
  454. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  455. $model->startDate=@$startDateVal;
  456. }
  457. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  458. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  459. $model->taskDueDate=@$taskDueDateVal;
  460. }
  461. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  462. $model->taskCompleted='yes';
  463. }
  464. if($model->validate()){
  465. $model->save();
  466. $leadId = $_POST['LeadFollowup']['leadId'];
  467. echo CJSON::encode(array(
  468. 'status'=>'success'
  469. ));
  470. Yii::app()->end();
  471. } else {
  472. $error = CActiveForm::validate($model);
  473. if($error!='[]')
  474. return $error;
  475. Yii::app()->end();
  476. }
  477. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  478. }
  479. $this->redirect(array('leads/lead_list'));
  480. }
  481. public function actionlead_contacts()
  482. {
  483. // renders the view file 'protected/views/site/index.php'
  484. // using the default layout 'protected/views/layouts/main.php'
  485. $model = new LeadContacts();
  486. $model->scenario = 'LeadContacts';
  487. $this->performAjaxValidation($model);
  488. if(!empty($_GET['contactId']))
  489. {
  490. $leadContactId=$_GET['leadContactId'];
  491. $model=LeadContacts::model()->findByPk($leadContactId);
  492. }
  493. if(!empty($_POST['LeadContacts']['leadContactId']))
  494. {
  495. $leadContactId=$_POST['LeadContacts']['leadContactId'];
  496. $model=LeadContacts::model()->findByPk($leadContactId);
  497. }
  498. if(isset($_POST['LeadContacts']))
  499. {
  500. $userId = $_POST['LeadContacts']['userId'];
  501. $leadId = $_POST['LeadContacts']['leadId'];
  502. $model->setAttributes(array(
  503. 'createdOn' => time(), //additional data you want to insert
  504. 'updatedOn' => time(), //additional
  505. 'updatedBy' => @$userId, //additional
  506. 'createdBy' => @$userId, //additional
  507. 'status' => 'Active', //additional
  508. ));
  509. foreach($_POST['LeadContacts'] as $name=>$value)
  510. {
  511. $model->$name=$value;
  512. }
  513. if($model->validate()){
  514. $model->save();
  515. echo CJSON::encode(array(
  516. 'status'=>'success'
  517. ));
  518. Yii::app()->end();
  519. } else {
  520. $error = CActiveForm::validate($model);
  521. if($error!='[]')
  522. echo $error;
  523. Yii::app()->end();
  524. }
  525. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  526. }
  527. $this->redirect(array('leads/lead_list'));
  528. }
  529. public function actionChangeContactStatus()
  530. {
  531. $Id=$_REQUEST['contactId'];
  532. $leadId=$_REQUEST['leadId'];
  533. $status=$_REQUEST['status'];
  534. if(isset($status)&&($status=='Inactive')){
  535. $status="Active";
  536. } else {
  537. $status="Inactive";
  538. }
  539. if(!empty($Id))
  540. {
  541. $model=LeadContacts::model()->findByPk($Id);
  542. }
  543. else
  544. {
  545. $model = LeadContacts::model()->findAll();
  546. }
  547. $model->status=$status;
  548. $model->save();
  549. $this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  550. }
  551. /**
  552. * This is the 'roles' action that is invoked
  553. * when an action is not explicitly requested by users.
  554. */
  555. public function actioncreate_lead()
  556. {
  557. $model=new Lead();
  558. $model->scenario = 'Lead';
  559. if(!empty($_GET['leadId']))
  560. {
  561. $leadId=$_GET['leadId'];
  562. $model=Lead::model()->findByPk($leadId);
  563. $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
  564. if(count($chkrecentlyViewed) == 0){
  565. $recentlyViewed = new recentlyViewed;
  566. $recentlyViewed->setAttributes(array(
  567. 'userId' => Yii::app()->session->get('id'),
  568. 'leadId' => $leadId,
  569. 'moduleId' => 0,
  570. 'createdOn' => time(),
  571. 'updatedOn' => time(),
  572. 'updatedBy' => time(),
  573. 'createdBy' => time(),
  574. ));
  575. $recentlyViewed->save(false);
  576. }
  577. }
  578. if(!empty($_POST['Lead']['leadId']))
  579. {
  580. $leadId=$_POST['Lead']['leadId'];
  581. $model=Lead::model()->findByPk($leadId);
  582. }
  583. if(isset($_POST['Lead']))
  584. {
  585. $model->setAttributes(array(
  586. 'createdOn' => time(), //additional data you want to insert
  587. 'updatedOn' => time(), //additional
  588. 'updatedBy' => Yii::app()->session->get('id'), //additional
  589. 'createdBy' => Yii::app()->session->get('id'),
  590. ));
  591. foreach($_POST['Lead'] as $name=>$value)
  592. {
  593. $model->$name=$value;
  594. if($model->leadStatusId==''){
  595. $model->leadStatusId=$model->leadStatusParentId;
  596. }
  597. if($model->leadStatusId==''){
  598. $model->leadStatusId=34;
  599. }
  600. if($model->mobile=='Mobile*'){
  601. $model->mobile='';
  602. }
  603. if($model->email=='Email'){
  604. $model->email='';
  605. }
  606. if($model->name=='Name'){
  607. $model->name='';
  608. }
  609. if($model->address=='Address'){
  610. $model->address='';
  611. }
  612. if($model->children=="Children (Less than 25 Yrs)"){
  613. $model->children='';
  614. }
  615. if($model->ageGroup=="Age of eldest member"){
  616. $model->ageGroup='';
  617. }
  618. }
  619. if($model->leadSourceId=='' or empty($model->leadSourceId)){
  620. $model->leadSourceId = '2';
  621. }
  622. if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin') {
  623. @$model->leadStatusId=35;
  624. @$model->currentAllocatedId=Yii::app()->session->get('id');
  625. }
  626. if(@$leadId!='' && $model->leadStatusId!='34'){
  627. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  628. }
  629. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  630. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  631. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  632. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  633. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  634. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
  635. if(count($chkStatusMandatoryOrNot) > 0){
  636. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  637. if($condMandatory == 'No'){
  638. if($model->validate(array('mobile'))){
  639. $mobileNumber = @$_POST['Lead']['mobile'];
  640. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
  641. if(empty($checkJunkNumber)){
  642. $beforethreemonth = time()-7776000;
  643. $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
  644. if(empty($checkDuplicateNumber)){
  645. $model->save(false);
  646. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  647. } else {
  648. $duplicateLeadId = $checkDuplicateNumber->leadId;
  649. $model->leadStatusId='10';
  650. $model->duplicateLeadId=@$duplicateLeadId;
  651. $model->currentAllocatedId=$checkDuplicateNumber->currentAllocatedId;
  652. $model->save(false);
  653. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  654. }
  655. } else {
  656. $model->leadStatusId='36';
  657. $model->save(false);
  658. Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
  659. }
  660. $this->redirect(array('leads/lead_list'));
  661. // $model->save(false);
  662. // $this->redirect(array('leads/lead_list'));
  663. }
  664. }
  665. }
  666. if($model->leadStatusId==36){
  667. $model->save(false);
  668. $this->redirect(array('leads/lead_list'));
  669. } else {
  670. if($model->validate()){
  671. $mobileNumber = $_POST['Lead']['mobile'];
  672. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
  673. if(empty($checkJunkNumber)){
  674. $beforethreemonth = time()-7776000;
  675. $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
  676. if(empty($checkDuplicateNumber)){
  677. $model->save();
  678. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  679. } else {
  680. $duplicateLeadId = $checkDuplicateNumber->leadId;
  681. $model->leadStatusId='10';
  682. $model->duplicateLeadId=@$duplicateLeadId;
  683. $model->save();
  684. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  685. }
  686. } else {
  687. $model->leadStatusId='36';
  688. $model->save();
  689. Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
  690. }
  691. $this->redirect(array('leads/lead_list'));
  692. } else {
  693. $this->render('create_lead',array('model'=>$model));
  694. }
  695. }
  696. } else {
  697. $this->render('create_lead',array('model'=>$model));
  698. }
  699. }
  700. public function actionAllocateLeads()
  701. {
  702. $Id = $_REQUEST['userids'];
  703. $teamleaderId = $_REQUEST['User']['id'];
  704. $userId = $_REQUEST['Team']['teamMemberId'];
  705. $updatedBy = @$_SESSION['id'];
  706. $temIds = Yii::app()->db->createCommand("select distinct teamId from teamUserMapping where userId='".@$teamleaderId."' and status='Active' order by id desc ")->queryAll();
  707. $teamId = $temIds[0]['teamId'];
  708. foreach($Id as $key=>$value){
  709. $model = new AllocatedLeads();
  710. $model->scenario = 'AllocatedLeads';
  711. $model->setAttributes(array(
  712. 'currentAllocatedDate' => time(), //additional data you want to insert
  713. 'createdOn' => time(), //additional data you want to insert
  714. 'updatedOn' => time(), //additional
  715. 'updatedBy' => @$updatedBy, //additional
  716. 'createdBy' => @$updatedBy, //additional
  717. 'leadStatusId' => '35', //additional //additional
  718. ));
  719. $leadId = @$value;
  720. $model->leadId = @$value;
  721. $model->userId = @$userId;
  722. $model->teamId = @$teamId;
  723. $model->teamLeaderId = @$teamleaderId;
  724. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  725. $model->allocatedId = null;
  726. $model->isNewRecord = true;
  727. $model->save();
  728. $model=new Lead();
  729. $model->scenario = 'Lead';
  730. $updatedOn = time();
  731. Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  732. }
  733. //
  734. //$this->redirect(array('leads/lead_list'));
  735. $this->redirect(array('leads/fresh_leads'));
  736. }
  737. /**
  738. * This is the 'lead_list_allocator' action that is invoked
  739. * when an action is not explicitly requested by users.
  740. */
  741. public function actionlead_assign()
  742. {
  743. $model = new Lead();
  744. $model->scenario = 'Lead';
  745. $leadId = $_REQUEST['AssignLead']['leadId'];
  746. $userId = $_REQUEST['AssignLead']['userId'];
  747. $assign = $_REQUEST['AssignLead']['assign'];
  748. if($leadId!='') {
  749. $updatedOn = time();
  750. $chkleadStatus = Lead::model()->findByPk($leadId);
  751. $existsOrNot = $chkleadStatus['leadStatusId'];
  752. $leadStatusIdUpdate = $existsOrNot?$existsOrNot:'34';
  753. if($leadStatusIdUpdate == 34){
  754. $leadStatusIdUpdate = 35;
  755. } else {
  756. $leadStatusIdUpdate = $leadStatusIdUpdate;
  757. }
  758. if($assign=='open') {
  759. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>'','status'=>'Active','leadStatusId'=>34,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>''));
  760. } elseif($assign=='self'){
  761. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$userId,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  762. } else {
  763. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$assign,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  764. }
  765. echo CJSON::encode(array(
  766. 'status'=>'success'
  767. ));
  768. Yii::app()->end();
  769. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  770. } else {
  771. $this->redirect(array('leads/lead_list'));
  772. }
  773. }
  774. /**
  775. * This is the 'roles' action that is invoked
  776. * when an action is not explicitly requested by users.
  777. */
  778. public function actionarchive_leads()
  779. {
  780. // renders the view file 'protected/views/site/index.php'
  781. // using the default layout 'protected/views/layouts/main.php'
  782. $model=new Lead();
  783. $model=Lead::model()->findAll();
  784. $this->render('archive_leads',array('model'=>$model));
  785. }
  786. /**
  787. * This is the 'roles' action that is invoked
  788. * when an action is not explicitly requested by users.
  789. */
  790. public function actionbulk_import_leads()
  791. {
  792. // renders the view file 'protected/views/site/index.php'
  793. // using the default layout 'protected/views/layouts/main.php'
  794. $model=new Lead();
  795. $this->render('bulk_import_lead',array('model'=>$model));
  796. }
  797. /**
  798. * This is the 'roles' action that is invoked
  799. * when an action is not explicitly requested by users.
  800. */
  801. public function actionjunk_leads()
  802. {
  803. // renders the view file 'protected/views/site/index.php'
  804. // using the default layout 'protected/views/layouts/main.php'
  805. $this->render('junk_leads');
  806. }
  807. /**
  808. * This is the 'module master' action that is invoked
  809. * when an action is not explicitly requested by users.
  810. */
  811. public function actionmodule_master()
  812. {
  813. // renders the view file 'protected/views/site/index.php'
  814. // using the default layout 'protected/views/layouts/main.php'
  815. $model=new ModuleMaster();
  816. $model->scenario = 'ModuleMaster';
  817. if(!empty($_GET['moduleId']))
  818. {
  819. $moduleId=$_GET['moduleId'];
  820. $model=ModuleMaster::model()->findByPk($moduleId);
  821. }
  822. if(!empty($_POST['ModuleMaster']['moduleId']))
  823. {
  824. $moduleId=$_POST['ModuleMaster']['moduleId'];
  825. $model=ModuleMaster::model()->findByPk($moduleId);
  826. }
  827. if(isset($_POST['ModuleMaster']))
  828. {
  829. $model->setAttributes(array(
  830. 'createdOn' => time(), //additional data you want to insert
  831. 'updatedOn' => time(), //additional
  832. 'updatedBy' => time(), //additional
  833. 'createdBy' => time(),
  834. 'status' => 'Activated', //additional //additional
  835. ));
  836. foreach($_POST['ModuleMaster'] as $name=>$value)
  837. {
  838. $model->$name=$value;
  839. }
  840. if($model->validate()){
  841. $model->save();
  842. $model2=ModuleMaster::model()->findAll();
  843. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  844. Yii::app()->user->setFlash('module_master_msg_success','Successfully Inserted');
  845. } else {
  846. Yii::app()->user->setFlash('module_master_msg_error','Please check. error occured');
  847. $this->render('module_master',array('model'=>$model));
  848. }
  849. } else {
  850. $model2=ModuleMaster::model()->findAll();
  851. //Yii::app()->user->setFlash('lead_stage_msg_error','Please check. error occured');
  852. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  853. }
  854. }
  855. /**
  856. * This is the action to handle external exceptions.
  857. */
  858. public function actionError()
  859. {
  860. if($error=Yii::app()->errorHandler->error)
  861. {
  862. if(Yii::app()->request->isAjaxRequest)
  863. echo $error['message'];
  864. else
  865. $this->render('error', $error);
  866. }
  867. }
  868. /**
  869. * Displays the contact page
  870. */
  871. public function actionContact()
  872. {
  873. $model=new ContactForm;
  874. if(isset($_POST['ContactForm']))
  875. {
  876. $model->attributes=$_POST['ContactForm'];
  877. if($model->validate())
  878. {
  879. $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
  880. $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
  881. $headers="From: $name <{$model->email}>\r\n".
  882. "Reply-To: {$model->email}\r\n".
  883. "MIME-Version: 1.0\r\n".
  884. "Content-type: text/plain; charset=UTF-8";
  885. mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
  886. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  887. $this->refresh();
  888. }
  889. }
  890. $this->render('contact',array('model'=>$model));
  891. }
  892. /**
  893. * Displays the login page
  894. */
  895. public function actionLogin()
  896. {
  897. $model=new User;
  898. // if it is ajax validation request
  899. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  900. {
  901. echo CActiveForm::validate($model);
  902. Yii::app()->end();
  903. }
  904. // collect user input data
  905. if(isset($_POST['User']))
  906. {
  907. $model->attributes=$_POST['User'];
  908. // validate user input and redirect to the previous page if valid
  909. if($model->validate() && $model->login()){
  910. $this->redirect(array('masters/dashboard'));
  911. } else {
  912. $this->redirect(Yii::app()->user->returnUrl);
  913. }
  914. }
  915. // display the login form
  916. $this->render('login',array('model'=>$model));
  917. }
  918. /**
  919. * Logs out the current user and redirect to homepage.
  920. */
  921. public function actionLogout()
  922. {
  923. Yii::app()->user->logout();
  924. $this->redirect(Yii::app()->homeUrl);
  925. }
  926. public function getPageType()
  927. {
  928. return "Leads";
  929. }
  930. public function init(){
  931. $obj =new RecentlyViewedController(); // preparing object
  932. $data=$obj->actionUserRoleAccess();
  933. $moduleArray=array();
  934. if(Yii::app()->session->get('type')=='superadmin'){
  935. $moduleArray['read']='yes';
  936. $moduleArray['write']='yes';
  937. $moduleArray['delete']='yes';
  938. }else{
  939. foreach($data as $key=>$value){
  940. if($data[$key]->modules->moduleName=='Leads'){
  941. $moduleArray['moduleName']=$data[$key]->modules->moduleName;
  942. $moduleArray['read']=$data[$key]->read;
  943. $moduleArray['write']=$data[$key]->write;
  944. $moduleArray['delete']=$data[$key]->delete;
  945. }
  946. }
  947. }
  948. return $moduleArray;
  949. }
  950. public function getNameFromNumber($num) {
  951. $numeric = $num % 26;
  952. $letter = chr(65 + $numeric);
  953. $num2 = intval($num / 26);
  954. if ($num2 > 0) {
  955. return getNameFromNumber($num2 - 1) . $letter;
  956. } else {
  957. return $letter;
  958. }
  959. }
  960. /*function actionexportArchiveList()
  961. {
  962. // generate a resultset
  963. $model=new User;
  964. $model=User::model()->findAll();
  965. // render data to xlsx format and echo resultant file back to browser.
  966. ExcelExporter::sendAsXLS($model, true, 'closedLeads.xls');
  967. }*/
  968. public function actionDownloadLeadTemp(){
  969. Yii::import('ext.phpexcel.XPHPExcel');
  970. $objPHPExcel= XPHPExcel::createPHPExcel();
  971. $objPHPExcel->getProperties()->setCreator("LeadTemplate")
  972. ->setLastModifiedBy("LeadTemplate")
  973. ->setTitle("LeadTemplate")
  974. ->setSubject("LeadTemplate")
  975. ->setDescription("LeadTemplate.")
  976. ->setKeywords("LeadTemplate")
  977. ->setCategory("LeadTemplate");
  978. //echo $total_excelColumns=$this->getNameFromNumber(4);
  979. $total_excelColumns='I';
  980. // Rename worksheet
  981. $objPHPExcel->getActiveSheet()->setTitle('ClosedLeads');
  982. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  983. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  984. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
  985. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  986. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  987. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  988. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  989. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  990. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  991. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  992. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
  993. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  994. array(
  995. 'font' => array(
  996. 'name' => 'Times New Roman',
  997. 'bold' => true,
  998. 'italic' => false,
  999. 'size' => 12
  1000. ),
  1001. 'borders' => array(
  1002. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1003. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1004. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1005. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1006. ),
  1007. 'alignment' => array(
  1008. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1009. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1010. 'wrap' => true
  1011. )
  1012. ),
  1013. 'A1:'.$total_excelColumns.'1'
  1014. );
  1015. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1016. // Add some data
  1017. $objPHPExcel->setActiveSheetIndex(0)
  1018. ->setCellValue('A1', 'Name')
  1019. ->setCellValue('B1', 'City')
  1020. ->setCellValue('C1', 'Email')
  1021. ->setCellValue('D1', 'Mobile')
  1022. ->setCellValue('E1', 'Suminsured')
  1023. ->setCellValue('F1', 'Age')
  1024. ->setCellValue('G1', 'No. Of Members')
  1025. ->setCellValue('H1', 'Date on submit')
  1026. ->setCellValue('I1', 'Lead Source');
  1027. // Miscellaneous glyphs, UTF-8
  1028. $objPHPExcel->setActiveSheetIndex(0)
  1029. ->setCellValue('A2', 'Lead Name')
  1030. ->setCellValue('B2', 'city')
  1031. ->setCellValue('C2', 'test@yesk.com')
  1032. ->setCellValue('D2', '9999999999')
  1033. ->setCellValue('E2', '56')
  1034. ->setCellValue('F2', '23')
  1035. ->setCellValue('G2', 'test')
  1036. ->setCellValue('H2', '07-Sep-2013')
  1037. ->setCellValue('I2', 'test');
  1038. //To create new sheet in current file
  1039. /*$objPHPExcel->createSheet(1);
  1040. $objPHPExcel->setActiveSheetIndex(1);
  1041. $objPHPExcel->getActiveSheet()->setTitle('Title');
  1042. */
  1043. // Redirect output to a client’s web browser (Excel5)
  1044. header('Content-Type: application/vnd.ms-excel');
  1045. header('Content-Disposition: attachment;filename="LeadTemplates.xls"');
  1046. header('Cache-Control: max-age=0');
  1047. // If you're serving to IE 9, then the following may be needed
  1048. header('Cache-Control: max-age=1');
  1049. // If you're serving to IE over SSL, then the following may be needed
  1050. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  1051. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1052. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1053. header ('Pragma: public'); // HTTP/1.0
  1054. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1055. $objWriter->save('php://output');
  1056. Yii::app()->end();
  1057. }
  1058. public function actionImportLeadTemplate(){
  1059. $model=new lead();
  1060. $data='';
  1061. $final_arr=@$_POST['final_arr']?@$_POST['final_arr']:'';
  1062. if(isset($_POST['ImportLeads']) && empty($final_arr) && !empty($_FILES['Lead']['name']['import'])){
  1063. Yii::import('ext.phpexcelreader.JPhpExcelReader');
  1064. $model->attributes='import';
  1065. $model->import=CUploadedFile::getInstance($model,'import');
  1066. $prefix=substr(time(),0,5);
  1067. $folder = '/tempdata';
  1068. $model->import->saveAs($folder.$prefix.$model->import);
  1069. $data=new JPhpExcelReader($folder.$prefix.$model->import);
  1070. //$this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
  1071. //$this->redirect(Yii::app()->createUrl('leads/bulk_import_leads'),array('data'=>$data,'model'=>$model));
  1072. $this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
  1073. }
  1074. if(isset($_POST['ImportLeads']) && !empty($final_arr) && isset($final_arr) && empty($_FILES['Lead']['name']['import'])){
  1075. $final_arr = unserialize(urldecode($_POST["final_arr"]));
  1076. $dateTime=time();
  1077. for($i=0;$i<sizeof($final_arr);$i++)
  1078. {
  1079. $junkNumberQuery = Yii::app()->db->createCommand("SELECT `junkLeadNumberId` FROM `junkLeadNumberMaster` WHERE `junkLeadNumber` = '".@$final_arr[$i]['mobile']."' ")->queryAll();
  1080. $junkNumberResult = $junkNumberQuery;
  1081. //$duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' ")->queryAll();(Original, changed below by Baljeet)
  1082. $duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId`,`currentAllocatedId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' ")->queryAll();
  1083. $duplicateResult = ($duplicateQuery);
  1084. if(count($junkNumberResult) > 0){
  1085. $leadStatusId = '36';
  1086. $duplicateLeadId = '';
  1087. } elseif(count($duplicateResult)>0){
  1088. $leadStatusId = '10';
  1089. $duplicateLeadId = @$duplicateResult[0]['leadId'];
  1090. $currentAllocatedId = @$duplicateResult[0]['currentAllocatedId']; //added by baljeet
  1091. } else {
  1092. $leadStatusId = '34';
  1093. $duplicateLeadId = '';
  1094. }
  1095. $model=new lead();
  1096. $model->name=$final_arr[$i]['name'];
  1097. $model->cityId=$final_arr[$i]['cityId'];
  1098. $model->email=$final_arr[$i]['email'];
  1099. $model->mobile=$final_arr[$i]['mobile'];
  1100. $model->si=$final_arr[$i]['suminsured'];
  1101. $model->age=$final_arr[$i]['age'];
  1102. $model->members=$final_arr[$i]['noofmembers'];
  1103. $model->dateonSubmit=$final_arr[$i]['dateonsubmit'];
  1104. $model->leadSourceId=$final_arr[$i]['leadSourceId'];
  1105. $model->leadStatusId=$leadStatusId;
  1106. $model->duplicateLeadId=@$duplicateLeadId;
  1107. $model->currentAllocatedId=@$currentAllocatedId;
  1108. $model->productId='1';
  1109. $model->status='Active';
  1110. $model->createdOn=$dateTime;
  1111. $model->createdBy=Yii::app()->session->get('id');
  1112. $model->updatedOn=$dateTime;
  1113. $model->updatedBy=Yii::app()->session->get('id');
  1114. $model->isNewRecord = true;
  1115. $model->save(false);
  1116. }
  1117. $this->redirect(array('leads/lead_list'));
  1118. }
  1119. if(isset($_POST['ImportLeads']) && empty($final_arr) && empty($_FILES['Lead']['name']['import'])){
  1120. $model->validate();
  1121. $this->render('bulk_import_lead',array('model'=>$model));
  1122. }
  1123. }
  1124. public function actionleadSearch()
  1125. {
  1126. $searched = new Lead();
  1127. $this->render('lead_search',array('searched'=>$searched));
  1128. }
  1129. public function actionExportExcel()
  1130. {
  1131. // It calls the actionCreateExcel to generates excel reports'
  1132. $this->actionCreateExcel();
  1133. }
  1134. public function actionCreateExcel(){
  1135. //Here is the code to set conditions for fetch records from database
  1136. $criteria = new CDbCriteria;
  1137. $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`';
  1138. $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)';
  1139. $criteria->condition='t.status != "Allocated" AND t.leadStatusId != "25" AND t.leadStatusId != "26" ';
  1140. $criteria->order='leadId DESC';
  1141. $model=new LeadReport();
  1142. $model->scenario = 'LeadReport';
  1143. $reportmodel=LeadReport::model()->findAll($criteria);
  1144. $data=array();
  1145. $datas = $reportmodel;
  1146. foreach($datas as $key=>$value){
  1147. $data[$key]=$value;
  1148. }
  1149. if(count($data)>0){
  1150. Yii::import('ext.phpexcel.XPHPExcel');
  1151. $objPHPExcel= XPHPExcel::createPHPExcel();
  1152. $objPHPExcel->getProperties()->setCreator("ReligareLMS")
  1153. ->setLastModifiedBy("ReligareLMS")
  1154. ->setTitle("Office 2007 XLSX Test Document")
  1155. ->setSubject("Office 2007 XLSX Test Document")
  1156. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  1157. ->setKeywords("office 2007 openxml php")
  1158. ->setCategory("Test result file");
  1159. $total_excelColumns=$this->getNameFromNumber(8);
  1160. // Rename worksheet
  1161. $objPHPExcel->getActiveSheet()->setTitle('Sample Excel');
  1162. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1163. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1164. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
  1165. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1166. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1167. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1168. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1169. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1170. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1171. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1172. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1173. array(
  1174. 'font' => array(
  1175. 'name' => 'Times New Roman',
  1176. 'bold' => true,
  1177. 'italic' => false,
  1178. 'size' => 12
  1179. ),
  1180. 'borders' => array(
  1181. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1182. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1183. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1184. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1185. ),
  1186. 'alignment' => array(
  1187. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1188. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1189. 'wrap' => true
  1190. )
  1191. ),
  1192. 'A1:'.$total_excelColumns.'1'
  1193. );
  1194. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1195. // Add some data
  1196. $objPHPExcel->setActiveSheetIndex(0)
  1197. ->setCellValue('A1', 'SNO.')
  1198. ->setCellValue('B1', 'Name')
  1199. ->setCellValue('C1', 'Mobile')
  1200. ->setCellValue('D1', 'Email')
  1201. ->setCellValue('E1', 'Lead Stage')
  1202. ->setCellValue('F1', 'Date and Time')
  1203. ->setCellValue('G1', 'UTM Code')
  1204. ->setCellValue('H1', 'status');
  1205. // Miscellaneous glyphs, UTF-8
  1206. $i=0;
  1207. $k=2;
  1208. $sn=1;
  1209. while($i<count($data)){
  1210. $objPHPExcel->setActiveSheetIndex(0)
  1211. ->setCellValue('A'.$k,$sn)
  1212. ->setCellValue('B'.$k,$data[$i]['name'])
  1213. ->setCellValue('C'.$k,$data[$i]['mobile'])
  1214. ->setCellValue('D'.$k,$data[$i]['email'])
  1215. ->setCellValue('E'.$k,$data[$i]['leadStage'])
  1216. ->setCellValue('F'.$k,date("d/m/y h:i A",$data[$i]['createdOn']))
  1217. ->setCellValue('G'.$k,$data[$i]['leadSourceCode'])
  1218. ->setCellValue('H'.$k,$data[$i]['status']);
  1219. $i++;$k++;$sn++;}
  1220. // Redirect output to a client’s web browser (Excel5)
  1221. header('Content-Type: application/vnd.ms-excel');
  1222. header('Content-Disposition: attachment;filename="lead_report.xls"');
  1223. header('Cache-Control: max-age=0');
  1224. // If you're serving to IE 9, then the fo…

Large files files are truncated, but you can click here to view the full file