PageRenderTime 66ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 1ms

/lms_debug/protected/controllers/CronController.php

https://gitlab.com/badelal143/lms_debug
PHP | 2546 lines | 2025 code | 385 blank | 136 comment | 325 complexity | e2db7cfa969ee7f00d2fd8d19ea249b1 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 CronController 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' ); // perform access control for CRUD operations
  11. }
  12. public function actions()
  13. {
  14. return array(
  15. // captcha action renders the CAPTCHA image displayed on the contact page
  16. 'captcha'=>array(
  17. 'class'=>'CCaptchaAction',
  18. 'backColor'=>0xFFFFFF,
  19. ),
  20. // page action renders "static" pages stored under 'protected/views/site/pages'
  21. // They can be accessed via: index.php?r=site/page&view=FileName
  22. 'page'=>array(
  23. 'class'=>'CViewAction',
  24. ),
  25. );
  26. }
  27. /**
  28. * It calls the actionCreateExcel to generates excel reports'
  29. * when an action is not explicitly requested by users.
  30. */
  31. public function actionExportExcelReport()
  32. {
  33. // It calls the actionCreateExcel to generates excel reports'
  34. @$getName=$_POST['LeadCronReport']['name'];
  35. @$getStatus=$_POST['LeadCronReport']['status'];
  36. @$getStage=$_POST['LeadCronReport']['stage'];
  37. @$date1=$_POST['LeadCronReport']['period1'];
  38. @$date2=$_POST['LeadCronReport']['period2'];
  39. @$getleadSourceId=$_POST['LeadCronReport']['leadSourceId'];
  40. @$getleadStatusId=$_POST['leadStatusId'];
  41. @$datetype=@$_POST['LeadCronReport']['datetype'];
  42. if(isset($datetype) && !empty($datetype)){
  43. $datetype=$datetype;
  44. } else {
  45. $datetype='updatedOn';
  46. }
  47. $isjunk = @$_REQUEST['isJunk'];
  48. $isjunk = $isjunk?$isjunk:'no';
  49. $this->actionCreateExcel($getName,$getStatus,$getStage,$date1,$date2,$getleadSourceId,$getleadStatusId,$datetype,$isjunk);
  50. }
  51. public function actionreports() {
  52. // renders the view file 'protected/views/site/index.php'
  53. // using the default layout 'protected/views/layouts/main.php'
  54. $model=new LeadCronReport('search');
  55. $model->scenario = 'LeadCronReport';
  56. $teamId = '';
  57. $teamUserId = '';
  58. if(@$_POST['LeadCronReport'] !='' && isset($_POST['LeadCronReport'])){
  59. @$primaryLeadStatus = @$_POST['leadStatusId'];
  60. if(count($primaryLeadStatus) > 0){
  61. $primaryLeadStatus = implode(",",$primaryLeadStatus);
  62. $primaryDisposition=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId IN (".@$primaryLeadStatus.") ")->queryAll();
  63. if(count($primaryDisposition) > 0){
  64. for($w=0;$w<count($primaryDisposition);$w++){
  65. @$PrimaryDispositionIds[] = @$primaryDisposition[$w]['leadStatusId'];
  66. }
  67. } else {
  68. @$PrimaryDispositionIds[] = '';
  69. }
  70. @$PrimaryDispositionIds = implode(",",@$PrimaryDispositionIds);
  71. } else {
  72. @$PrimaryDispositionIds = '';
  73. }
  74. $teamId = @$_POST['Team']['teamId'];
  75. $teamUserId = @$_POST['Team']['teamMemberId'];
  76. if($teamUserId=='' or empty($teamUserId)){
  77. $teamUsers=Yii::app()->db->createCommand("select userId from teamUserMapping where teamId = '".@$teamId."' ")->queryAll();
  78. $reportsteamUsersIds = array();
  79. foreach($teamUsers as $key=>$value){
  80. $reportsteamUsersIds[] = $value['userId'];
  81. }
  82. } else {
  83. $reportsteamUsersIds[] = $teamUserId;
  84. }
  85. $name=@$_POST['LeadCronReport']['name'];
  86. $status=@$_POST['LeadCronReport']['status'];
  87. $stage=@$_POST['LeadCronReport']['stage'];
  88. /*$utmCode=@$_POST['LeadCronReport']['utmCode'];
  89. $teleCaller=@$_POST['LeadCronReport']['teleCaller'];*/
  90. $period1=@$_POST['LeadCronReport']['period1'];
  91. $period2=@$_POST['LeadCronReport']['period2'];
  92. $leadSourceId=@$_POST['LeadCronReport']['leadSourceId'];
  93. $ws_agentid=@$_POST['LeadCronReport']['ws_agentid'];
  94. $datetype=@$_POST['LeadCronReport']['datetype'];
  95. $isjunk = @$_REQUEST['isJunk'];
  96. $isjunk = $isjunk?$isjunk:'no';
  97. if(isset($datetype) && !empty($datetype)){
  98. $datetype=$datetype;
  99. } else {
  100. $datetype='updatedOn';
  101. }
  102. //echo $datetype; die;
  103. $criteria = new CDbCriteria;
  104. $criteria->select = 't.*,`city`.`city`,`state`.`state`, `leadSourceMaster`.`leadSourceTitle`, `leadStageMaster`.`leadStage`,`leadStatus`.`leadStatus`,`customerTypeMaster`.`customerType`,`productMaster`.`productName`,`policyTypeMaster`.`policyType`,`planTypeMaster`.`planType`,`campaign`.`campaignName`';
  105. $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)';
  106. $criteria->order='leadId DESC';
  107. if(count($reportsteamUsersIds) > 0){
  108. $comd = implode(',',$reportsteamUsersIds);
  109. $criteria->addCondition("t.currentAllocatedId IN (".$comd.") ");
  110. }
  111. if(isset($name) && !empty($name))
  112. {/*LIKE '$this->time_up%'";*/
  113. $criteria->addCondition("t.name like '%".$name."'");
  114. }
  115. if(isset($status) && !empty($status))
  116. {
  117. $criteria->addCondition("t.leadStatusId =".$status);
  118. }
  119. if(isset($PrimaryDispositionIds) && !empty($PrimaryDispositionIds))
  120. {
  121. $criteria->addCondition("t.leadStatusId IN (".@$PrimaryDispositionIds.") ");
  122. }
  123. if(isset($stage) && !empty($stage))
  124. {
  125. $criteria->addCondition("t.leadStageId =".$stage);
  126. }
  127. if(isset($leadSourceId) && !empty($leadSourceId))
  128. {
  129. $criteria->addCondition("t.leadSourceId =".$leadSourceId);
  130. }
  131. if(isset($isjunk) && !empty($isjunk) && $isjunk=='yes' )
  132. {
  133. $criteria->addCondition("t.leadStatusId !=36");
  134. }
  135. if(isset($ws_agentid) && !empty($ws_agentid))
  136. {
  137. $criteria->addCondition("t.ws_agentid='".$ws_agentid."'");
  138. }
  139. if((isset($period1) && !empty($period1)) && (isset($period2) && !empty($period2)))
  140. {
  141. $period1=strtotime($period1);
  142. $period2=strtotime($period2)+86399;
  143. // echo date('d m y :: h: i: s: A',$period2); die;
  144. $criteria->addCondition('t.'.$datetype.' >= '.$period1.' AND t.'.$datetype.' <= '.$period2.'');
  145. // $criteria->addBetweenCondition('t.'.$datetype,$period1,$period2,'');
  146. }
  147. /*echo "<pre>";
  148. print_r($criteria);
  149. die();*/
  150. $model->set_name=@$_POST['LeadCronReport']['name'];
  151. $model->set_stage=@$_POST['LeadCronReport']['stage'];
  152. $model->set_status=@$_POST['LeadCronReport']['status'];
  153. $model->set_period1=@$_POST['LeadCronReport']['period1'];
  154. $model->set_period2=@$_POST['LeadCronReport']['period2'];
  155. $model->set_leadStatusId=@$_POST['leadStatusId'];
  156. $model->set_leadSourceId=@$_POST['LeadCronReport']['leadSourceId'];
  157. $model->set_ws_agentid=@$_POST['LeadCronReport']['ws_agentid'];
  158. $criteria->order='leadId DESC';
  159. $dataProvider=new CActiveDataProvider('LeadCronReport', array('criteria'=>$criteria,'pagination'=>array(
  160. 'pageSize'=>20,
  161. 'params' => array('period1' =>@$period1?date("d-m-Y",@$period1):'','period2' =>@$period2?date("d-m-Y",@$period2):''),
  162. ),));
  163. $this->render('reports',array('model'=>$model,'dataProvider'=>$dataProvider,'teamId'=>$teamId,'teamUserId'=>$teamUserId));
  164. }else{
  165. $criteria = new CDbCriteria;
  166. $criteria->select = 't.*';
  167. $criteria->order='leadId DESC';
  168. $dataProvider=new CActiveDataProvider('LeadCronReport', array('criteria'=>$criteria,));
  169. $this->render('reports',array('model'=>$model,'dataProvider'=>$dataProvider,'teamId'=>$teamId,'teamUserId'=>$teamUserId));
  170. }
  171. }
  172. /**
  173. * This function is used to get column name from number of column
  174. * calls from 'actionCreateExcel' function.
  175. */
  176. public function getNameFromNumber($num) {
  177. $numeric = $num % 26;
  178. $letter = chr(65 + $numeric);
  179. $num2 = intval($num / 26);
  180. if ($num2 > 0) {
  181. return getNameFromNumber($num2 - 1) . $letter;
  182. } else {
  183. return $letter;
  184. }
  185. }
  186. public function getPageType()
  187. {
  188. return "Reports";
  189. }
  190. /**
  191. * This function is used to create excel file
  192. * calls from 'actionreports' function.
  193. */
  194. public function actionCreateExcel($getName,$getStatus,$getStage,$date1,$date2,$getleadSourceId,$getleadStatusId,$datetype,$isjunk){
  195. $paginationExcelValue = @$_POST['fetchrecordsBydropdown'];
  196. if(isset($paginationExcelValue) && !empty($paginationExcelValue)){
  197. $explodedpaginationValue = explode('-',$paginationExcelValue);
  198. $startLimit = $explodedpaginationValue[0];
  199. $endLimit = 10000;
  200. } else {
  201. $startLimit = '';
  202. $endLimit = '';
  203. }
  204. if(isset($startLimit) && isset($endLimit) && !empty($endLimit)){
  205. $limitCond = " limit $startLimit , $endLimit";
  206. } else {
  207. $limitCond = '';
  208. }
  209. //Here is the code to set conditions for fetch records from database
  210. $condfilter = '';
  211. if((isset($getName)&& (!empty($getName))) || (isset($getStatus)&& (!empty($getStatus))) || (isset($getStage)&& (!empty($getStage)))|| (isset($date1)&& (!empty($date1))) || (isset($date2)&& (!empty($date2))))
  212. {
  213. if(isset($getName) && !empty($getName))
  214. {
  215. $condfilter .= "t.name like '%".$getName."' AND ";
  216. }
  217. if(isset($getStatus) && !empty($getStatus))
  218. {
  219. $condfilter .= "t.leadStatusId =".$getStatus." AND ";
  220. }
  221. if(isset($getStage) && !empty($getStage))
  222. {
  223. $condfilter .= "t.leadStageId =".$getStage." AND ";
  224. }
  225. if(isset($getleadSourceId) && !empty($getleadSourceId))
  226. {
  227. $condfilter .= "t.leadSourceId =".$getleadSourceId." AND ";
  228. }
  229. if(isset($isjunk) && !empty($isjunk))
  230. {
  231. $condfilter .= "t.leadStatusId != 36 AND ";
  232. }
  233. if((isset($date1) && !empty($date1)) && (isset($date2) && !empty($date2)))
  234. {
  235. $date1=strtotime($date1);
  236. $date2=strtotime($date2)+86399;
  237. $condfilter .= "t.".$datetype." >=".$date1." AND t.".$datetype." <= ".$date2." AND ";
  238. }
  239. if(isset($condfilter) && !empty($condfilter)){
  240. $wherecon = "WHERE ";
  241. } else {
  242. $wherecon = "";
  243. }
  244. $data=Yii::app()->db->createCommand("select t.leadId,t.name,t.mobile,t.email,t.members,t.premium,t.productDetails,t.ws_agentid,t.status,t.isJunk,t.leadDescription,t.currentAllocatedId,t.createdBy,t.updatedOn,t.jsonAllData from leads_cron as t $wherecon $condfilter t.leadId > 0 order by t.leadId DESC $limitCond")->queryAll();
  245. }else{
  246. if(isset($getleadSourceId) && !empty($getleadSourceId))
  247. {
  248. $condfilter .= "t.leadSourceId =".$getleadSourceId." AND";
  249. }
  250. if(count($getleadStatusId) > 0){
  251. $getleadStatusId = implode(",",$getleadStatusId);
  252. $primaryDisposition=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId IN (".@$getleadStatusId.") ")->queryAll();
  253. if(count($primaryDisposition) > 0){
  254. for($w=0;$w<count($primaryDisposition);$w++){
  255. @$PrimaryDispositionIds[] = @$primaryDisposition[$w]['leadStatusId'];
  256. }
  257. } else {
  258. @$PrimaryDispositionIds[] = '';
  259. }
  260. @$PrimaryDispositionIds = implode(",",@$PrimaryDispositionIds);
  261. } else {
  262. @$PrimaryDispositionIds = '';
  263. }
  264. if(isset($PrimaryDispositionIds) && !empty($PrimaryDispositionIds))
  265. {
  266. $condfilter .= "t.leadStatusId IN (".@$PrimaryDispositionIds.") AND ";
  267. }
  268. if(isset($condfilter) && !empty($condfilter)){
  269. $wherecon = "WHERE ";
  270. } else {
  271. $wherecon = "";
  272. }
  273. $data=Yii::app()->db->createCommand("select t.leadId,t.name,t.mobile,t.email,t.members,t.premium,t.productDetails,t.ws_agentid,t.status,t.isJunk,t.leadDescription,t.currentAllocatedId,t.createdBy,t.updatedOn,t.jsonAllData from leads_cron as t $wherecon $condfilter t.leadId > 0 order by t.leadId DESC $limitCond ")->queryAll();
  274. }
  275. if(count($data)>0){
  276. $file_name = "lms" . "_" . date("Y-m-d_H-i", time()) . ".csv";
  277. header('Content-Type: text/html; charset=utf-8');
  278. header("Content-type: application/octet-stream");
  279. header("Content-Disposition: attachment; filename=\"$file_name\"");
  280. header("Cache-Control: cache, must-revalidate");
  281. header("Pragma: public");
  282. $col = array(
  283. 'SNO.','Name','Mobile Number',' Email Id','Address','City','State','Members','Premium','Product Details','Lead Status','Status','isJunk','Lead Source','Lead Stage','Lead Description','Activity Description','Customer Type','Product Name','Policy Type','Plan Type','Campaign Name','UTM Code','Owner','Last Modified Date','Agent-Id');
  284. foreach ($col as $key => $value) {
  285. echo $value . ",";
  286. }
  287. echo "\n";
  288. $i=1;
  289. foreach ($data as $key => $value) {
  290. $jsonArray = json_decode($value['jsonAllData']);
  291. $state = $jsonArray->state;
  292. $city = $jsonArray->city;
  293. $product = $jsonArray->product;
  294. $leadStatus = $jsonArray->leadStatus;
  295. $leadSource = $jsonArray->leadSource;
  296. $leadStage = $jsonArray->leadStage;
  297. $ActivityDescription = $jsonArray->ActivityDescription;
  298. $owner = $jsonArray->owner;
  299. $customerType = $jsonArray->customerType;
  300. $policyType = $jsonArray->policyType;
  301. $planType = $jsonArray->planType;
  302. $campaign = $jsonArray->campaign;
  303. // $sqlDesc = "select group_concat(description) as ActivityDescription from leadFollowup where leadId=".@$value["leadId"]." ";
  304. // $dataDesc=Yii::app()->db->createCommand($sqlDesc)->queryAll();
  305. // $leadActivity = @$dataDesc[0]['ActivityDescription']?str_replace(",","/",@$dataDesc[0]['ActivityDescription']):'';
  306. if($value['currentAllocatedId']==$value['createdBy']){
  307. $owner = $owner."(C)";
  308. } else {
  309. $owner = $owner;
  310. }
  311. $lastModifieddate = date("d-M-Y H-i-s A",$value['updatedOn']);
  312. echo $i++ . ",";
  313. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["name"])) . ",";
  314. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["mobile"])) . ",";
  315. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["email"])) . ",";
  316. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["address"])) . ",";
  317. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$city)) . ",";
  318. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$state)) . ",";
  319. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["members"])) . ",";
  320. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["premium"])) . ",";
  321. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value['productDetails'])) . ",";
  322. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$leadStatus)) . ",";
  323. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["status"])) . ",";
  324. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["isJunk"])) . ",";
  325. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$leadSource)) . ",";
  326. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$leadStage)) . ",";
  327. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$value["leadDescription"])) . ",";
  328. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$ActivityDescription)) . ",";
  329. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$customerType)) . ",";
  330. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$product)) . ",";
  331. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$policyType)) . ",";
  332. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$planType)) . ",";
  333. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$campaign)) . ",";
  334. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["leadSourceCode"])) . ",";
  335. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$owner)) . ",";
  336. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9@._\'-]|'$/", " ",@$lastModifieddate)) . ",";
  337. echo stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ",@$value["ws_agentid"])) . ",";
  338. echo "\n";
  339. }
  340. }
  341. else{
  342. $this->redirect('index.php?r=reports/reports');
  343. //$dataProvider=new CActiveDataProvider('LeadCronReport', array('criteria'=>@$criteria,));
  344. //$this->render('reports',array('model'=>$model,'dataProvider'=>$dataProvider));
  345. }
  346. }
  347. public function getLeadDescription($leadId){
  348. $records=Yii::app()->db->createCommand("select leadDescription from lead where leadId='".@$leadId."' ")->queryAll();
  349. if(count($records) > 0) {
  350. for($i=0;$i<count($records);$i++){
  351. $record[] = @$records[$i]['leadDescription'];
  352. }
  353. } else {
  354. echo "";
  355. }
  356. if( count(@$record) > 1){
  357. echo "<label title='".implode(',',$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
  358. } else if( count(@$record) == 1) {
  359. echo "<label title='".implode(',',@$record)."'><a href='#'>".implode(',',$record)."</a></label>";
  360. } else {
  361. echo "";
  362. }
  363. //echo explode(',',$agentId);
  364. }
  365. public function getLeadActivityDescription($leadId){
  366. $records=Yii::app()->db->createCommand("select description from leadFollowup where leadId='".@$leadId."' ")->queryAll();
  367. if(count($records) > 0) {
  368. for($i=0;$i<count($records);$i++){
  369. $record[] = @$records[$i]['description'];
  370. }
  371. } else {
  372. echo "";
  373. }
  374. if( count(@$record) > 1){
  375. echo "<label title='".implode(',',$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
  376. } else if( count(@$record) == 1) {
  377. echo "<label title='".implode(',',@$record)."'><a href='#'>".substr(implode(',',$record),0,5)."...</a></label>";
  378. } else {
  379. echo "";
  380. }
  381. //echo explode(',',$agentId);
  382. }
  383. public function getLeadActivityDescriptionExcel($leadId){
  384. $records=Yii::app()->db->createCommand("select description from leadFollowup where leadId='".@$leadId."' ")->queryAll();
  385. if(count($records) > 0) {
  386. for($i=0;$i<count($records);$i++){
  387. $record[] = @$records[$i]['description'];
  388. }
  389. } else {
  390. echo "";
  391. }
  392. if( count(@$record) > 1){
  393. echo implode(',',$record);
  394. } else if( count(@$record) == 1) {
  395. echo implode(',',$record);
  396. } else {
  397. echo "";
  398. }
  399. //echo explode(',',$agentId);
  400. }
  401. public function actionCheckanddelete(){
  402. $reportmodel=Lead::model()->findAll();
  403. print_r($reportmodel);
  404. die;
  405. }
  406. function actioncroneJobForReport(){
  407. ini_set('max_input_time', 1200);
  408. ini_set('max_execution_time', 1200);
  409. $sourcewiseDetails=Yii::app()->db->createCommand("select * from leads_cron_history where id='lead_updated_on' ")->queryAll();
  410. $sourcewiseDetails[0]['updatedOn'];
  411. $queryUpdatedOn = "select t.*,`user`.`id`,`user`.`firstName`,`user`.`lastName`,`city`.`city`, `state`.`state`, `leadSourceMaster`.`leadSourceTitle`,`leadSourceMaster`.`leadSourceCode`,`leadStageMaster`.`leadStage`,`leadStatus`.`leadStatus`, `customerTypeMaster`.`customerType`,`productMaster`.`productName`,`policyTypeMaster`.`policyType`,`planTypeMaster`.`planType`,`campaign`.`campaignName` from lead as t 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) LEFT JOIN user ON (user.id=t.currentAllocatedId) where (t.updatedOn > ".@$sourcewiseDetails[0]['updatedOn']." || t.createdOn > ".@$sourcewiseDetails[0]['updatedOn']." ) order by t.leadId DESC ";
  412. $dataUpdatedOn=Yii::app()->db->createCommand($queryUpdatedOn)->queryAll();
  413. $updateleads_cron_history = " update leads_cron_history set updated_ts = '".date('Y-m-d H:i:s')."',updatedOn = '".time()."' where id='lead_updated_on' ";
  414. $executeQueryder=Yii::app()->db->createCommand($updateleads_cron_history)->execute();
  415. //$queryCreatedOn = "select t.leadId,t.name,t.mobile,t.email,t.members,t.premium,t.productDetails,t.ws_agentid,t.status,t.isJunk,t.leadDescription,t.currentAllocatedId,t.createdBy,t.updatedOn,`user`.`id`,`user`.`firstName`,`user`.`lastName`,`city`.`city`, `state`.`state`, `leadSourceMaster`.`leadSourceTitle`,`leadSourceMaster`.`leadSourceCode`,`leadStageMaster`.`leadStage`,`leadStatus`.`leadStatus`, `customerTypeMaster`.`customerType`,`productMaster`.`productName`,`policyTypeMaster`.`policyType`,`planTypeMaster`.`planType`,`campaign`.`campaignName` from lead as t 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) LEFT JOIN user ON (user.id=t.currentAllocatedId) where t.leadId <= 2 and createdOn > ".@$sourcewiseDetails[0]['updatedOn']." order by t.leadId DESC ";
  416. //$dataCreatedOn=Yii::app()->db->createCommand($queryCreatedOn)->queryAll();
  417. $insertcount=0;
  418. $updatecount=0;
  419. if(count($dataUpdatedOn) > 0){
  420. foreach ($dataUpdatedOn as $key => $value) {
  421. $owner = @$value['firstName']?(@$value['firstName']." ".@$value['lastName']):"NA";
  422. $sqlDesc = "select group_concat(description) as ActivityDescription from renewalleadFollowup where leadId=".@$value["leadId"]." ";
  423. $dataDesc=Yii::app()->db->createCommand($sqlDesc)->queryAll();
  424. $leadActivity = @$dataDesc[0]['ActivityDescription']?str_replace(",",":",@$dataDesc[0]['ActivityDescription']):'';
  425. $state = @$value["state"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["state"])):'NA';
  426. $city = @$value["city"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["city"])):'NA';
  427. $customerType = @$value["customerType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["customerType"])):'NA';
  428. $productName = @$value["productName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["productName"])):'NA';
  429. $policyType = @$value["policyType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["policyType"])):'NA';
  430. $planType = @$value["planType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["planType"])):'NA';
  431. $campaignName = @$value["campaignName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["campaignName"])):'NA';
  432. $leadSourceTitle = @$value["leadSourceTitle"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadSourceTitle"])):'NA';
  433. $leadStatus = @$value["leadStatus"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadStatus"])):'NA';
  434. $leadStage = @$value["leadStage"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadStage"])):'NA';
  435. $owner = @$owner?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$owner)):'NA';
  436. $agntName = @$value["agntName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["agntName"])):'NA';
  437. $leadActivity = @$leadActivity?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$leadActivity)):'NA';
  438. $newarray = array(
  439. 'state' => $state,
  440. 'city' => $city,
  441. 'customerType' => $customerType,
  442. 'product' => $productName,
  443. 'policyType' => $policyType,
  444. 'planType' => $planType,
  445. 'campaign' => $campaignName,
  446. 'leadSource' => $leadSourceTitle,
  447. 'leadStatus' => $leadStatus,
  448. 'leadStage' => $leadStage,
  449. 'owner' => addslashes($owner),
  450. 'agntName' => $agntName,
  451. 'ActivityDescription' => str_replace("'","`",$leadActivity)
  452. );
  453. $jsonData = json_encode($newarray);
  454. //$insertQuery = " insert into leads_cron (leadId,name,email,emailOptOut,mobile,mobileOptOut,address,stateId,cityId,customerTypeId,productId,policyTypeId,planTypeId,campaignId,members,si,premium,productDetails,ageGroup,children,leadSourceId,leadStatusId,leadStageId,isJunk,currentAllocatedId,currentAllocatedDate,isDuplicate,duplicateLeadId,age,dateonSubmit,fileName,leadDescription,isRead,status,ipaddress,agentId,createdOn,createdBy,updatedOn,updatedBy,ws_sourcecode,ws_subject,ws_telephone,ws_plan,ws_product,ws_quoteid,ws_proposalid,ws_leadstage,ws_agentid,ws_noofyears,ws_orgnaizationName,utmsource,isBulkImport,salesClosedUpdatedOn,jsonAllData,jsonDataUpdatedOn,jsonDataUpdatedBy) values (".$value['leadId'].",".$value['name'].",".$value['email'].",".$value['emailOptOut'].",".$value['mobile'].",".$value['mobileOptOut'].",".$value['address'].",".$value['stateId'].",".$value['cityId'].",".$value['customerTypeId'].",".$value['productId'].",".$value['policyTypeId'].",".$value['planTypeId'].",".$value['campaignId'].",".$value['members'].",".$value['si'].",".$value['premium'].",".$value['productDetails'].",".$value['ageGroup'].",".$value['children'].",".$value['leadSourceId'].",".$value['leadStatusId'].",".$value['leadStageId'].",".$value['isJunk'].",".$value['currentAllocatedId'].",".$value['currentAllocatedDate'].",".$value['isDuplicate'].",".$value['duplicateLeadId'].",".$value['age'].",".$value['dateonSubmit'].",".$value['fileName'].",".$value['leadDescription'].",".$value['isRead'].",".$value['status'].",".$value['ipaddress'].",".$value['agentId'].",".$value['createdOn'].",".$value['createdBy'].",".$value['updatedOn'].",".$value['updatedBy'].",".$value['ws_sourcecode'].",".$value['ws_subject'].",".$value['ws_telephone'].",".$value['ws_plan'].",".$value['ws_product'].",".$value['ws_quoteid'].",".$value['ws_proposalid'].",".$value['ws_leadstage'].",".$value['ws_agentid'].",".$value['ws_noofyears'].",".$value['ws_orgnaizationName'].",".$value['utmsource'].",".$value['isBulkImport'].",".$value['salesClosedUpdatedOn'].",'".$jsonData."',".$value['jsonDataUpdatedOn'].",".$value['jsonDataUpdatedBy'].") ";
  455. if($value['createdOn'] >= $sourcewiseDetails[0]['updatedOn']){
  456. $insertQuery = " insert into leads_cron (leadId,name,email,emailOptOut,mobile,mobileOptOut,address,stateId,cityId,customerTypeId,productId,policyTypeId,planTypeId,campaignId,members,si,premium,productDetails,ageGroup,children,leadSourceId,leadStatusId,leadStageId,isJunk,currentAllocatedId,currentAllocatedDate,isDuplicate,duplicateLeadId,age,dateonSubmit,fileName,leadDescription,isRead,status,ipaddress,agentId,createdOn,createdBy,updatedOn,updatedBy,ws_sourcecode,ws_subject,ws_telephone,ws_plan,ws_product,ws_quoteid,ws_proposalid,ws_leadstage,ws_agentid,ws_noofyears,ws_orgnaizationName,utmsource,isBulkImport,salesClosedUpdatedOn,jsonAllData,jsonDataUpdatedOn,jsonDataUpdatedBy) values ('".$value['leadId']."','".addslashes($value['name'])."','".$value['email']."','".$value['emailOptOut']."','".$value['mobile']."','".$value['mobileOptOut']."','".addslashes($value['address'])."','".$value['stateId']."','".$value['cityId']."','".$value['customerTypeId']."','".$value['productId']."','".$value['policyTypeId']."','".$value['planTypeId']."','".$value['campaignId']."','".addslashes($value['members'])."','".addslashes($value['si'])."','".addslashes($value['premium'])."','".addslashes($value['productDetails'])."','".$value['ageGroup']."','".$value['children']."','".$value['leadSourceId']."','".$value['leadStatusId']."','".$value['leadStageId']."','".$value['isJunk']."','".$value['currentAllocatedId']."','".$value['currentAllocatedDate']."','".$value['isDuplicate']."','".$value['duplicateLeadId']."','".$value['age']."','".$value['dateonSubmit']."','".$value['fileName']."','".addslashes($value['leadDescription'])."','".$value['isRead']."','".$value['status']."','".$value['ipaddress']."','".$value['agentId']."','".$value['createdOn']."','".$value['createdBy']."','".$value['updatedOn']."','".$value['updatedBy']."','".$value['ws_sourcecode']."','".$value['ws_subject']."','".$value['ws_telephone']."','".$value['ws_plan']."','".$value['ws_product']."','".$value['ws_quoteid']."','".$value['ws_proposalid']."','".$value['ws_leadstage']."','".$value['ws_agentid']."','".$value['ws_noofyears']."','".$value['ws_orgnaizationName']."','".$value['utmsource']."','".$value['isBulkImport']."','".$value['salesClosedUpdatedOn']."','".$jsonData."','".time()."','amit') ";
  457. $executeQuery4=Yii::app()->db->createCommand($insertQuery)->execute();
  458. //echo "<br><br>" .$insertQuery;
  459. $insertcount++;
  460. } else if($value['updatedOn'] >= $sourcewiseDetails[0]['updatedOn']){
  461. $updateQuery = " update leads_cron set leadId='".$value['leadId']."',name='".addslashes($value['name'])."',email='".$value['email']."',emailOptOut='".$value['emailOptOut']."',mobile='".$value['mobile']."',mobileOptOut='".$value['mobileOptOut']."',address='".addslashes($value['address'])."',stateId='".$value['stateId']."',cityId='".$value['cityId']."',customerTypeId='".$value['customerTypeId']."',productId='".$value['productId']."',policyTypeId='".$value['policyTypeId']."',planTypeId='".$value['planTypeId']."',campaignId='".$value['campaignId']."',members='".addslashes($value['members'])."',si='".addslashes($value['si'])."',premium='".addslashes($value['premium'])."',productDetails='".addslashes($value['productDetails'])."',ageGroup='".$value['ageGroup']."',children='".$value['children']."',leadSourceId='".$value['leadSourceId']."',leadStatusId='".$value['leadStatusId']."',leadStageId='".$value['leadStageId']."',isJunk='".$value['isJunk']."',currentAllocatedId='".$value['currentAllocatedId']."',currentAllocatedDate='".$value['currentAllocatedDate']."',isDuplicate='".$value['isDuplicate']."',duplicateLeadId='".$value['duplicateLeadId']."',age='".$value['age']."',dateonSubmit='".$value['dateonSubmit']."',fileName='".$value['fileName']."',leadDescription='".addslashes($value['leadDescription'])."',isRead='".$value['isRead']."',status='".$value['status']."',ipaddress='".$value['ipaddress']."',agentId='".$value['agentId']."',createdOn='".$value['createdOn']."',createdBy='".$value['createdBy']."',updatedOn='".$value['updatedOn']."',updatedBy='".$value['updatedBy']."',ws_sourcecode='".$value['ws_sourcecode']."',ws_subject='".$value['ws_subject']."',ws_telephone='".$value['ws_telephone']."',ws_plan='".$value['ws_plan']."',ws_product='".$value['ws_product']."',ws_quoteid='".$value['ws_quoteid']."',ws_proposalid='".$value['ws_proposalid']."',ws_leadstage='".$value['ws_leadstage']."',ws_agentid='".$value['ws_agentid']."',ws_noofyears='".$value['ws_noofyears']."',ws_orgnaizationName='".$value['ws_orgnaizationName']."',utmsource='".$value['utmsource']."',isBulkImport='".$value['isBulkImport']."',salesClosedUpdatedOn='".$value['salesClosedUpdatedOn']."',jsonAllData='".$jsonData."',jsonDataUpdatedOn='".time()."',jsonDataUpdatedBy='amit' where leadId = ".@$value['leadId']." ";
  462. $executeQuery2=Yii::app()->db->createCommand($updateQuery)->execute();
  463. //echo "<br><br>" .$updateQuery;
  464. $updatecount++;
  465. }
  466. }
  467. }
  468. echo "insert count=".$insertcount." and update count=".$updatecount;
  469. }
  470. function actioncroneFirstTime(){
  471. $startId = @$_REQUEST['startId'];
  472. $endId = @$_REQUEST['endId'];
  473. if(empty($startId) || empty($endId)){
  474. echo "parameter missing";
  475. die;
  476. }
  477. if($startId > $endId){
  478. echo "start Limit can not be greater or equal to end Limit";
  479. die;
  480. }
  481. $query = "select t.*,`user`.`id`,`user`.`firstName`,`user`.`lastName`,`city`.`city`, `state`.`state`, `leadSourceMaster`.`leadSourceTitle`,`leadSourceMaster`.`leadSourceCode`,`leadStageMaster`.`leadStage`,`leadStatus`.`leadStatus`, `customerTypeMaster`.`customerType`,`productMaster`.`productName`,`policyTypeMaster`.`policyType`,`planTypeMaster`.`planType`,`campaign`.`campaignName` from lead as t 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) LEFT JOIN user ON (user.id=t.currentAllocatedId) where t.leadId >= $startId and t.leadId <= $endId ";
  482. $data=Yii::app()->db->createCommand($query)->queryAll();
  483. $updateleads_cron_history = " update leads_cron_history set updated_ts = '".date('Y-m-d H:i:s')."',updatedOn = '".time()."' where id='lead_updated_on' ";
  484. $executeQuery=Yii::app()->db->createCommand($updateleads_cron_history)->execute();
  485. //$r=0;
  486. foreach ($data as $key => $value) {
  487. $owner = @$value['firstName']?(@$value['firstName']." ".@$value['lastName']):"NA";
  488. $sqlDesc = "select group_concat(description) as ActivityDescription from renewalleadFollowup where leadId=".@$value["leadId"]." ";
  489. $dataDesc=Yii::app()->db->createCommand($sqlDesc)->queryAll();
  490. $leadActivity = @$dataDesc[0]['ActivityDescription']?str_replace(",",":",@$dataDesc[0]['ActivityDescription']):'';
  491. $state = @$value["state"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["state"])):'NA';
  492. $city = @$value["city"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["city"])):'NA';
  493. $customerType = @$value["customerType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["customerType"])):'NA';
  494. $productName = @$value["productName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["productName"])):'NA';
  495. $policyType = @$value["policyType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["policyType"])):'NA';
  496. $planType = @$value["planType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["planType"])):'NA';
  497. $campaignName = @$value["campaignName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["campaignName"])):'NA';
  498. $leadSourceTitle = @$value["leadSourceTitle"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadSourceTitle"])):'NA';
  499. $leadStatus = @$value["leadStatus"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadStatus"])):'NA';
  500. $leadStage = @$value["leadStage"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadStage"])):'NA';
  501. $owner = @$owner?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$owner)):'NA';
  502. $agntName = @$value["agntName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["agntName"])):'NA';
  503. $leadActivity = @$leadActivity?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$leadActivity)):'NA';
  504. $newarray = array(
  505. 'state' => $state,
  506. 'city' => $city,
  507. 'customerType' => addslashes($customerType),
  508. 'product' => addslashes($productName),
  509. 'policyType' => addslashes($policyType),
  510. 'planType' => addslashes($planType),
  511. 'campaign' => addslashes($campaignName),
  512. 'leadSource' => addslashes($leadSourceTitle),
  513. 'leadStatus' => addslashes($leadStatus),
  514. 'leadStage' => addslashes($leadStage),
  515. 'owner' => addslashes($owner),
  516. 'agntName' => addslashes($agntName),
  517. 'ActivityDescription' => str_replace("'","`",$leadActivity)
  518. );
  519. $jsonData = json_encode($newarray);
  520. $insertQuery = " insert into leads_cron (leadId,name,email,emailOptOut,mobile,mobileOptOut,address,stateId,cityId,customerTypeId,productId,policyTypeId,planTypeId,campaignId,members,si,premium,productDetails,ageGroup,children,leadSourceId,leadStatusId,leadStageId,isJunk,currentAllocatedId,currentAllocatedDate,isDuplicate,duplicateLeadId,age,dateonSubmit,fileName,leadDescription,isRead,status,ipaddress,agentId,createdOn,createdBy,updatedOn,updatedBy,ws_sourcecode,ws_subject,ws_telephone,ws_plan,ws_product,ws_quoteid,ws_proposalid,ws_leadstage,ws_agentid,ws_noofyears,ws_orgnaizationName,utmsource,isBulkImport,salesClosedUpdatedOn,jsonAllData,jsonDataUpdatedOn,jsonDataUpdatedBy) values ('".$value['leadId']."','".addslashes($value['name'])."','".$value['email']."','".$value['emailOptOut']."','".$value['mobile']."','".$value['mobileOptOut']."','".addslashes($value['address'])."','".$value['stateId']."','".$value['cityId']."','".$value['customerTypeId']."','".$value['productId']."','".$value['policyTypeId']."','".$value['planTypeId']."','".$value['campaignId']."','".addslashes($value['members'])."','".addslashes($value['si'])."','".addslashes($value['premium'])."','".addslashes($value['productDetails'])."','".$value['ageGroup']."','".$value['children']."','".$value['leadSourceId']."','".$value['leadStatusId']."','".$value['leadStageId']."','".$value['isJunk']."','".$value['currentAllocatedId']."','".$value['currentAllocatedDate']."','".$value['isDuplicate']."','".$value['duplicateLeadId']."','".$value['age']."','".$value['dateonSubmit']."','".$value['fileName']."','".addslashes($value['leadDescription'])."','".$value['isRead']."','".$value['status']."','".$value['ipaddress']."','".$value['agentId']."','".$value['createdOn']."','".$value['createdBy']."','".$value['updatedOn']."','".$value['updatedBy']."','".$value['ws_sourcecode']."','".$value['ws_subject']."','".$value['ws_telephone']."','".$value['ws_plan']."','".$value['ws_product']."','".$value['ws_quoteid']."','".$value['ws_proposalid']."','".$value['ws_leadstage']."','".$value['ws_agentid']."','".$value['ws_noofyears']."','".$value['ws_orgnaizationName']."','".$value['utmsource']."','".$value['isBulkImport']."','".$value['salesClosedUpdatedOn']."','".$jsonData."','".time()."','amit') ";
  521. $executeQuerys=Yii::app()->db->createCommand($insertQuery)->execute();
  522. //echo $value['leadId']."<br>";
  523. // $r++;
  524. }
  525. }
  526. public function actionagentwisetotalcalls(){
  527. ini_set('max_input_time', 1200);
  528. ini_set('max_execution_time', 1200);
  529. $time = time();
  530. $parser = new CHtmlPurifier();
  531. $afterMonth = $parser->purify(intval(@$_REQUEST['month']));
  532. $afterDate = $parser->purify(intval(@$_REQUEST['date']));
  533. $afterYear = $parser->purify(intval(@$_REQUEST['year']));
  534. if(isset($afterMonth) && !empty($afterMonth) && isset($afterDate) && !empty($afterDate) && isset($afterYear) && !empty($afterYear)){
  535. $start = mktime(0, 0, 0,$afterMonth,$afterDate,$afterYear);
  536. $end = mktime(23, 59, 59,$afterMonth,$afterDate,$afterYear);
  537. } else {
  538. $start = mktime(0, 0, 0);
  539. $end = mktime(23, 59, 59);
  540. }
  541. $date = date('d_M_Y',$start)."_";
  542. $host = '10.216.6.59'; // MYSQL database host adress
  543. $db = 'lms'; // MYSQL database name
  544. $user = 'root'; // Mysql Datbase user
  545. $pass = '0kwp6aNR'; // Mysql Datbase password
  546. $link=mysql_connect($host,$user,$pass);
  547. mysql_select_db($db,$link);
  548. $table='report_agentwisetotalcalls';
  549. $filename = "filesystem/".$date.$table.'.csv';
  550. $csv_terminated = "\n";
  551. $csv_separator = ",";
  552. $csv_enclosed = '"';
  553. $csv_escaped = "\\";
  554. mysql_query("insert into report_info (id,type,filename,createdOn,createdBy,updatedOn,updatedBy) values('','agentwisetotalcalls','".@$filename."','".@$time."','0','".@$time."','0')");
  555. $totalleadstatusids = array(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,33,26,37,38,39,42,43);
  556. $chktableExist = mysql_query('DROP TABLE IF EXISTS '.$table.' ') or die(mysql_error());
  557. $tableres ='create table IF NOT EXISTS '.$table.' as SELECT
  558. user.userName as `Caller Name`,
  559. SUM(CASE WHEN lead.currentAllocatedId=user.id THEN 1 ELSE 0 END) AS `Total Diposed`,
  560. SUM(CASE WHEN LS.`leadStatusId` = 7 THEN 1 ELSE 0 END) AS `Sale Done`,
  561. SUM(CASE WHEN LS.`leadStatusId` = 8 THEN 1 ELSE 0 END) AS `Follow Up`,
  562. SUM(CASE WHEN LS.`leadStatusId` = 9 THEN 1 ELSE 0 END) AS `Do Not Call - Will Buy self on Website`,
  563. SUM(CASE WHEN LS.`leadStatusId` = 10 THEN 1 ELSE 0 END) AS `Duplicate - Already In Talk With Team`,
  564. SUM(CASE WHEN LS.`leadStatusId` = 37 THEN 1 ELSE 0 END) AS `In Contact with Oflline Agent`,
  565. SUM(CASE WHEN LS.`leadStatusId` = 38 THEN 1 ELSE 0 END) AS `In Touch With Other Partner`,
  566. SUM(CASE WHEN LS.`leadStatusId` = 11 THEN 1 ELSE 0 END) AS `Short Hangup`,
  567. SUM(CASE WHEN LS.`leadStatusId` = 12 THEN 1 ELSE 0 END) AS `Call Later`,
  568. SUM(CASE WHEN LS.`leadStatusId` = 42 THEN 1 ELSE 0 END) AS `Ringing Less Than Five Tries`,
  569. SUM(CASE WHEN LS.`leadStatusId` = 43 THEN 1 ELSE 0 END) AS `Switched Off Less than Five Tries`,
  570. SUM(CASE WHEN LS.`leadStatusId` = 13 THEN 1 ELSE 0 END) AS `Not Interested - Fund Problem`,
  571. SUM(CASE WHEN LS.`leadStatusId` = 14 THEN 1 ELSE 0 END) AS `Just Checking Website`,
  572. SUM(CASE WHEN LS.`leadStatusId` = 15 THEN 1 ELSE 0 END) AS `Not Interested - Insured From Employer`,
  573. SUM(CASE WHEN LS.`leadStatusId` = 16 THEN 1 ELSE 0 END) AS `Not Interested - High Premium`,
  574. SUM(CASE WHEN LS.`leadStatusId` = 17 THEN 1 ELSE 0 END) AS `Under Age`,
  575. SUM(CASE WHEN LS.`leadStatusId` = 18 THEN 1 ELSE 0 END) AS `Not Visited Website`,
  576. SUM(CASE WHEN LS.`leadStatusId` = 19 THEN 1 ELSE 0 END) AS `Do Not Call`,
  577. SUM(CASE WHEN LS.`leadStatusId` = 20 THEN 1 ELSE 0 END) AS `Not Interested - General`,
  578. SUM(CASE WHEN LS.`leadStatusId` = 21 THEN 1 ELSE 0 END) AS `Over Age`,
  579. SUM(CASE WHEN LS.`leadStatusId` = 22 THEN 1 ELSE 0 END) AS `Not Interested - Already Insured`,
  580. SUM(CASE WHEN LS.`leadStatusId` = 23 THEN 1 ELSE 0 END) AS `Duplicate Data - Not Interested`,
  581. SUM(CASE WHEN LS.`leadStatusId` = 24 THEN 1 ELSE 0 END) AS `Not Eligible - PED`,
  582. SUM(CASE WHEN LS.`leadStatusId` = 25 THEN 1 ELSE 0 END) AS `Not Interested - Govt. Employee`,
  583. SUM(CASE WHEN LS.`leadStatusId` = 26 THEN 1 ELSE 0 END) AS `Not Interested - Senior Citizen`,
  584. SUM(CASE WHEN LS.`leadStatusId` = 27 THEN 1 ELSE 0 END) AS `Wrong Number`,
  585. SUM(CASE WHEN LS.`leadStatusId` = 28 THEN 1 ELSE 0 END) AS `Customer Not Available`,
  586. SUM(CASE WHEN LS.`leadStatusId` = 29 THEN 1 ELSE 0 END) AS `Language Barrier`,
  587. SUM(CASE WHEN LS.`leadStatusId` = 30 THEN 1 ELSE 0 END) AS `No Response`,
  588. SUM(CASE WHEN LS.`leadStatusId` = 33 THEN 1 ELSE 0 END) AS `Invalid Number`,
  589. SUM(CASE WHEN LS.`leadStatusId` = 36 THEN 1 ELSE 0 END) AS `Junk`,
  590. SUM(CASE WHEN LS.`leadStatusId` = 39 THEN 1 ELSE 0 END) AS `Ringing no response after five tries`,
  591. SUM(CASE WHEN LS.`leadStatusId` = 43 THEN 1 ELSE 0 END) AS `Switched Off/ Not Reachable after 5 tries`
  592. FROM `lead` join user on user.id=lead.currentAllocatedId left join leadStatus LS on LS.leadStatusId=lead.leadStatusId where lead.updatedOn >= "'.@$start.'" and lead.updatedOn <= "'.@$end.'" group by lead.currentAllocatedId';
  593. $esx = mysql_query($tableres) or die(mysql_error());
  594. $queryforinsert = "Insert into ".$table." (`Total Diposed`,`Sale Done`,`Follow Up`,`Do Not Call - Will Buy self on Website`,`Duplicate - Already In Talk With Team`,`In Contact with Oflline Agent`,`In Touch With Other Partner`,`Short Hangup`,`Call Later`,`Ringing Less Than Five Tries`,`Switched Off Less than Five Tries`,`Not Interested - Fund Problem`,`Just Checking Website`,`Not Interested - Insured From Employer`,`Not Interested - High Premium`,`Under Age`,`Not Visited Website`,`Do Not Call`,`Not Interested - General`,`Over Age`,`Not Interested - Already Insured`,`Duplicate Data - Not Interested`,`Not Eligible - PED`,`Not Interested - Govt. Employee`,`Not Interested - Senior Citizen`,`Wrong Number`,`Customer Not Available`,`Language Barrier`,`No Response`,`Invalid Number`,`Junk`,`Ringing no response after five tries`,`Switched Off/ Not Reachable after 5 tries`)
  595. select SUM(`Total Diposed`), SUM(`Sale Done`), SUM(`Follow Up`), SUM(`Do Not Call - Will Buy self on Website`), SUM(`Duplicate - Already In Talk With Team`), SUM(`In Contact with Oflline Agent`), SUM(`In Touch With Other Partner`), SUM(`Short Hangup`), SUM(`Call Later`), SUM(`Ringing Less Than Five Tries`), SUM(`Switched Off Less than Five Tries`), SUM(`Not Interested - Fund Problem`), SUM(`Just Checking Website`), SUM(`Not Interested - Insured From Employer`), SUM(`Not Interested - High Premium`), SUM(`Under Age`), SUM(`Not Visited Website`), SUM(`Do Not Call`), SUM(`Not Interested - General`), SUM(`Over Age`), SUM(`Not Interested - Already Insured`), SUM(`Duplicate Data - Not Interested`), SUM(`Not Eligible - PED`), SUM(`Not Interested - Govt. Employee`), SUM(`Not Interested - Senior Citizen`), SUM(`Wrong Number`), SUM(`Customer Not Available`), SUM(`Language Barrier`), SUM(`No Response`), SUM(`Invalid Number`), SUM(`Junk`), SUM(`Ringing no response after five tries`), SUM(`Switched Off/ Not Reachable after 5 tries`) from ".$table."";
  596. mysql_query($queryforinsert);
  597. $sql_query = "select * from $table";
  598. // Gets the data from the database
  599. $result = mysql_query($sql_query) or die(mysql_error());
  600. $fields_cnt = mysql_num_fields($result);
  601. $schema_insert = '';
  602. for ($i = 0; $i < $fields_cnt; $i++)
  603. {
  604. $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
  605. stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;
  606. $schema_insert .= $l;
  607. $schema_insert .= $csv_separator;
  608. } // end for
  609. $out = trim(substr($schema_insert, 0, -1));
  610. $out .= $csv_terminated;
  611. // Format the data
  612. while ($row = mysql_fetch_array($result))
  613. {
  614. $schema_insert = '';
  615. for ($j = 0; $j < $fields_cnt; $j++)
  616. {
  617. if ($row[$j] == '0' || $row[$j] != '')
  618. {
  619. if ($csv_enclosed == '')
  620. {
  621. $schema_insert .= $row[$j];
  622. } else
  623. {
  624. $schema_insert .= $csv_enclosed .
  625. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
  626. }
  627. } else
  628. {
  629. $schema_insert .= '';
  630. }
  631. if ($j < $fields_cnt - 1)
  632. {
  633. $schema_insert .= $csv_separator;
  634. }
  635. } // end for
  636. $out .= $schema_insert;
  637. $out .= $csv_terminated;
  638. } // end while
  639. /// header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  640. //header("Content-Length: " . strlen($out));
  641. // Output to browser with appropriate mime type, you choose ;)
  642. // header("Content-Disposition: attachment; filename=$filename");
  643. //header("Content-type: text/x-csv");
  644. $fd = fopen ($filename, "w");
  645. fputs($fd, $out);
  646. fclose($fd);
  647. echo "success";
  648. //header("Content-type: text/csv");
  649. //header("Content-type: application/csv");
  650. //echo $out;
  651. exit;
  652. }
  653. public function actionagentfreshleadsdisposition(){
  654. /* $date = date('d_M_Y')."_";
  655. $start = mktime(0, 0, 0);
  656. $end = mktime(23, 59, 59);
  657. */
  658. ini_set('max_input_time', 2400);
  659. ini_set('max_execution_time', 2400);
  660. $parser = new CHtmlPurifier();
  661. $afterMonth = $parser->purify(intval(@$_REQUEST['month']));
  662. $afterDate = $parser->purify(intval(@$_REQUEST['date']));
  663. $afterYear = $parser->purify(intval(@$_REQUEST['year']));
  664. if(isset($afterMonth) && !empty($afterMonth) && isset($afterDate) && !empty($afterDate) && isset($afterYear) && !empty($afterYear)){
  665. $start = mktime(0, 0, 0,$afterMonth,$afterDate,$afterYear);
  666. $end = mktime(23, 59, 59,$afterMonth,$afterDate,$afterYear);
  667. } else {
  668. $start = mktime(0, 0, 0);
  669. $end = mktime(23, 59, 59);
  670. }
  671. $time = time();
  672. $date = date('d_M_Y',$start).'_';
  673. $host = '10.216.6.59'; // MYSQL database host adress
  674. $db = 'lms'; // MYSQL database name
  675. $user = 'root'; // Mysql Datbase user
  676. $pass = '0kwp6aNR'; // Mysql Datbase password
  677. $link=mysql_connect($host,$user,$pass);
  678. mysql_select_db($db,$link);
  679. $table='report_agentfreshleadsdisposition';
  680. $filename = "filesystem/".$date.$table.'.csv';
  681. $csv_terminated = "\n";
  682. $csv_separator = ",";
  683. $csv_enclosed = '"';
  684. $csv_escaped = "\\";
  685. $time = time();
  686. mysql_query("insert into report_info (id,type,filename,createdOn,createdBy,updatedOn,updatedBy) values('','agentfreshleadsdisposition','".@$filename."','".@$time."','".@$_SESSION['id']."','".@$time."','".@$_SESSION['id']."')");
  687. $totalleadstatusids = '7,8,9,10,37,38,11,12,42,43,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,33,39,43';
  688. $chktableExist = mysql_query('DROP TABLE IF EXISTS '.$table.' ') or die(mysql_error());
  689. $tableres ='create table IF NOT EXISTS '.$table.' as SELECT
  690. user.userName as `Caller Name`,
  691. SUM(CASE WHEN lead.currentAllocatedId=user.id THEN 1 ELSE 0 END) AS `Total Assigned`,
  692. SUM(CASE WHEN lead.currentAllocatedId=user.id AND lead.leadStatusId NOT IN ('.@$totalleadstatusids.') THEN 1 ELSE 0 END) AS `No Update`,
  693. SUM(CASE WHEN lead.currentAllocatedId=user.id AND lead.leadStatusId IN ('.@$t…

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