PageRenderTime 63ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/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

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

  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->leadStatus

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