PageRenderTime 35ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/lms_debug/protected/controllers/ReportsController_23rdApr15.php

https://gitlab.com/badelal143/lms_debug
PHP | 1810 lines | 1456 code | 250 blank | 104 comment | 242 complexity | b0d5c579e08d11125233839a3a2ab865 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0
  1. <?php
  2. class ReportsController 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. $sourcewiseDetails=Yii::app()->db->createCommand("select * from leads_cron_history where id='lead_updated_on' ")->queryAll();
  408. $sourcewiseDetails[0]['updatedOn'];
  409. $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 ";
  410. $dataUpdatedOn=Yii::app()->db->createCommand($queryUpdatedOn)->queryAll();
  411. $updateleads_cron_history = " update leads_cron_history set updated_ts = '".date('Y-m-d H:i:s')."',updatedOn = '".time()."' where id='lead_updated_on' ";
  412. $executeQueryder=Yii::app()->db->createCommand($updateleads_cron_history)->execute();
  413. //$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 ";
  414. //$dataCreatedOn=Yii::app()->db->createCommand($queryCreatedOn)->queryAll();
  415. $insertcount=0;
  416. $updatecount=0;
  417. if(count($dataUpdatedOn) > 0){
  418. foreach ($dataUpdatedOn as $key => $value) {
  419. $owner = @$value['firstName']?(@$value['firstName']." ".@$value['lastName']):"NA";
  420. $sqlDesc = "select group_concat(description) as ActivityDescription from renewalleadFollowup where leadId=".@$value["leadId"]." ";
  421. $dataDesc=Yii::app()->db->createCommand($sqlDesc)->queryAll();
  422. $leadActivity = @$dataDesc[0]['ActivityDescription']?str_replace(",",":",@$dataDesc[0]['ActivityDescription']):'';
  423. $state = @$value["state"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["state"])):'NA';
  424. $city = @$value["city"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["city"])):'NA';
  425. $customerType = @$value["customerType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["customerType"])):'NA';
  426. $productName = @$value["productName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["productName"])):'NA';
  427. $policyType = @$value["policyType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["policyType"])):'NA';
  428. $planType = @$value["planType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["planType"])):'NA';
  429. $campaignName = @$value["campaignName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["campaignName"])):'NA';
  430. $leadSourceTitle = @$value["leadSourceTitle"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadSourceTitle"])):'NA';
  431. $leadStatus = @$value["leadStatus"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadStatus"])):'NA';
  432. $leadStage = @$value["leadStage"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadStage"])):'NA';
  433. $owner = @$owner?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$owner)):'NA';
  434. $agntName = @$value["agntName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["agntName"])):'NA';
  435. $leadActivity = @$leadActivity?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$leadActivity)):'NA';
  436. $newarray = array(
  437. 'state' => $state,
  438. 'city' => $city,
  439. 'customerType' => $customerType,
  440. 'product' => $productName,
  441. 'policyType' => $policyType,
  442. 'planType' => $planType,
  443. 'campaign' => $campaignName,
  444. 'leadSource' => $leadSourceTitle,
  445. 'leadStatus' => $leadStatus,
  446. 'leadStage' => $leadStage,
  447. 'owner' => addslashes($owner),
  448. 'agntName' => $agntName,
  449. 'ActivityDescription' => str_replace("'","`",$leadActivity)
  450. );
  451. $jsonData = json_encode($newarray);
  452. //$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'].") ";
  453. if($value['createdOn'] >= $sourcewiseDetails[0]['updatedOn']){
  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']."','".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') ";
  455. $executeQuery4=Yii::app()->db->createCommand($insertQuery)->execute();
  456. //echo "<br><br>" .$insertQuery;
  457. $insertcount++;
  458. } else if($value['updatedOn'] >= $sourcewiseDetails[0]['updatedOn']){
  459. $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']." ";
  460. $executeQuery2=Yii::app()->db->createCommand($updateQuery)->execute();
  461. //echo "<br><br>" .$updateQuery;
  462. $updatecount++;
  463. }
  464. }
  465. }
  466. echo "insert count=".$insertcount." and update count=".$updatecount;
  467. }
  468. function actioncroneFirstTime(){
  469. $startId = @$_REQUEST['startId'];
  470. $endId = @$_REQUEST['endId'];
  471. if(empty($startId) || empty($endId)){
  472. echo "parameter missing";
  473. die;
  474. }
  475. if($startId > $endId){
  476. echo "start Limit can not be greater or equal to end Limit";
  477. die;
  478. }
  479. $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 ";
  480. $data=Yii::app()->db->createCommand($query)->queryAll();
  481. $updateleads_cron_history = " update leads_cron_history set updated_ts = '".date('Y-m-d H:i:s')."',updatedOn = '".time()."' where id='lead_updated_on' ";
  482. $executeQuery=Yii::app()->db->createCommand($updateleads_cron_history)->execute();
  483. //$r=0;
  484. foreach ($data as $key => $value) {
  485. $owner = @$value['firstName']?(@$value['firstName']." ".@$value['lastName']):"NA";
  486. $sqlDesc = "select group_concat(description) as ActivityDescription from renewalleadFollowup where leadId=".@$value["leadId"]." ";
  487. $dataDesc=Yii::app()->db->createCommand($sqlDesc)->queryAll();
  488. $leadActivity = @$dataDesc[0]['ActivityDescription']?str_replace(",",":",@$dataDesc[0]['ActivityDescription']):'';
  489. $state = @$value["state"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["state"])):'NA';
  490. $city = @$value["city"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["city"])):'NA';
  491. $customerType = @$value["customerType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["customerType"])):'NA';
  492. $productName = @$value["productName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["productName"])):'NA';
  493. $policyType = @$value["policyType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["policyType"])):'NA';
  494. $planType = @$value["planType"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["planType"])):'NA';
  495. $campaignName = @$value["campaignName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["campaignName"])):'NA';
  496. $leadSourceTitle = @$value["leadSourceTitle"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadSourceTitle"])):'NA';
  497. $leadStatus = @$value["leadStatus"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadStatus"])):'NA';
  498. $leadStage = @$value["leadStage"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["leadStage"])):'NA';
  499. $owner = @$owner?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$owner)):'NA';
  500. $agntName = @$value["agntName"]?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$value["agntName"])):'NA';
  501. $leadActivity = @$leadActivity?stripslashes(preg_replace("/^'|[^A-Za-z0-9\'-]|'$/", " ", @$leadActivity)):'NA';
  502. $newarray = array(
  503. 'state' => $state,
  504. 'city' => $city,
  505. 'customerType' => addslashes($customerType),
  506. 'product' => addslashes($productName),
  507. 'policyType' => addslashes($policyType),
  508. 'planType' => addslashes($planType),
  509. 'campaign' => addslashes($campaignName),
  510. 'leadSource' => addslashes($leadSourceTitle),
  511. 'leadStatus' => addslashes($leadStatus),
  512. 'leadStage' => addslashes($leadStage),
  513. 'owner' => addslashes($owner),
  514. 'agntName' => addslashes($agntName),
  515. 'ActivityDescription' => str_replace("'","`",$leadActivity)
  516. );
  517. $jsonData = json_encode($newarray);
  518. $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') ";
  519. $executeQuerys=Yii::app()->db->createCommand($insertQuery)->execute();
  520. //echo $value['leadId']."<br>";
  521. // $r++;
  522. }
  523. }
  524. public function actionagentwisetotalcalls(){
  525. $time = time();
  526. $parser = new CHtmlPurifier();
  527. $afterMonth = $parser->purify(intval(@$_REQUEST['month']));
  528. $afterDate = $parser->purify(intval(@$_REQUEST['date']));
  529. $afterYear = $parser->purify(intval(@$_REQUEST['year']));
  530. if(isset($afterMonth) && !empty($afterMonth) && isset($afterDate) && !empty($afterDate) && isset($afterYear) && !empty($afterYear)){
  531. $start = mktime(0, 0, 0,$afterMonth,$afterDate,$afterYear);
  532. $end = mktime(23, 59, 59,$afterMonth,$afterDate,$afterYear);
  533. } else {
  534. $start = mktime(0, 0, 0);
  535. $end = mktime(23, 59, 59);
  536. }
  537. $date = date('d_M_Y',$start)."_";
  538. $host = '10.216.6.59'; // MYSQL database host adress
  539. $db = 'lms'; // MYSQL database name
  540. $user = 'root'; // Mysql Datbase user
  541. $pass = '0kwp6aNR'; // Mysql Datbase password
  542. $link=mysql_connect($host,$user,$pass);
  543. mysql_select_db($db,$link);
  544. $table='report_agentwisetotalcalls';
  545. $filename = "filesystem/".$date.$table.'.csv';
  546. $csv_terminated = "\n";
  547. $csv_separator = ",";
  548. $csv_enclosed = '"';
  549. $csv_escaped = "\\";
  550. $totalleadstatusids = '7,8,9,10,37,38,11,12,42,43,13,14,15,16,17,18,19,30,21,22,23,24,25,26,27,28,29,30,33,39,43';
  551. mysql_query("insert into report_info (id,type,filename,createdOn,createdBy,updatedOn,updatedBy) values('','agentwisetotalcalls','".@$filename."','".@$time."','".@$_SESSION['id']."','".@$time."','".@$_SESSION['id']."')");
  552. $chktableExist = mysql_query('DROP TABLE IF EXISTS '.$table.' ') or die(mysql_error());
  553. $tableres ='create table IF NOT EXISTS '.$table.' as SELECT
  554. user.userName as `Caller Name`,
  555. SUM(CASE WHEN lead.currentAllocatedId=user.id AND lead.leadStatusId IN ('.@$totalleadstatusids.') THEN 1 ELSE 0 END) AS `Total Diposed`,
  556. SUM(CASE WHEN LS.`leadStatusId` = 7 THEN 1 ELSE 0 END) AS `Sale Done`,
  557. SUM(CASE WHEN LS.`leadStatusId` = 8 THEN 1 ELSE 0 END) AS `Follow Up`,
  558. SUM(CASE WHEN LS.`leadStatusId` = 9 THEN 1 ELSE 0 END) AS `Do Not Call - Will Buy self on Website`,
  559. SUM(CASE WHEN LS.`leadStatusId` = 10 THEN 1 ELSE 0 END) AS `Duplicate - Already In Talk With Team`,
  560. SUM(CASE WHEN LS.`leadStatusId` = 37 THEN 1 ELSE 0 END) AS `In Contact with Oflline Agent`,
  561. SUM(CASE WHEN LS.`leadStatusId` = 38 THEN 1 ELSE 0 END) AS `In Touch With Other Partner`,
  562. SUM(CASE WHEN LS.`leadStatusId` = 11 THEN 1 ELSE 0 END) AS `Short Hangup`,
  563. SUM(CASE WHEN LS.`leadStatusId` = 12 THEN 1 ELSE 0 END) AS `Call Later`,
  564. SUM(CASE WHEN LS.`leadStatusId` = 42 THEN 1 ELSE 0 END) AS `Ringing Less Than Five Tries`,
  565. SUM(CASE WHEN LS.`leadStatusId` = 43 THEN 1 ELSE 0 END) AS `Switched Off Less than Five Tries`,
  566. SUM(CASE WHEN LS.`leadStatusId` = 13 THEN 1 ELSE 0 END) AS `Not Interested - Fund Problem`,
  567. SUM(CASE WHEN LS.`leadStatusId` = 14 THEN 1 ELSE 0 END) AS `Just Checking Website`,
  568. SUM(CASE WHEN LS.`leadStatusId` = 15 THEN 1 ELSE 0 END) AS `Not Interested - Insured From Employer`,
  569. SUM(CASE WHEN LS.`leadStatusId` = 16 THEN 1 ELSE 0 END) AS `Not Interested - High Premium`,
  570. SUM(CASE WHEN LS.`leadStatusId` = 17 THEN 1 ELSE 0 END) AS `Under Age`,
  571. SUM(CASE WHEN LS.`leadStatusId` = 18 THEN 1 ELSE 0 END) AS `Not Visited Website`,
  572. SUM(CASE WHEN LS.`leadStatusId` = 19 THEN 1 ELSE 0 END) AS `Do Not Call`,
  573. SUM(CASE WHEN LS.`leadStatusId` = 20 THEN 1 ELSE 0 END) AS `Not Interested - General`,
  574. SUM(CASE WHEN LS.`leadStatusId` = 21 THEN 1 ELSE 0 END) AS `Over Age`,
  575. SUM(CASE WHEN LS.`leadStatusId` = 22 THEN 1 ELSE 0 END) AS `Not Interested - Already Insured`,
  576. SUM(CASE WHEN LS.`leadStatusId` = 23 THEN 1 ELSE 0 END) AS `Duplicate Data - Not Interested`,
  577. SUM(CASE WHEN LS.`leadStatusId` = 24 THEN 1 ELSE 0 END) AS `Not Eligible - PED`,
  578. SUM(CASE WHEN LS.`leadStatusId` = 25 THEN 1 ELSE 0 END) AS `Not Interested - Govt. Employee`,
  579. SUM(CASE WHEN LS.`leadStatusId` = 26 THEN 1 ELSE 0 END) AS `Not Interested - Senior Citizen`,
  580. SUM(CASE WHEN LS.`leadStatusId` = 27 THEN 1 ELSE 0 END) AS `Wrong Number`,
  581. SUM(CASE WHEN LS.`leadStatusId` = 28 THEN 1 ELSE 0 END) AS `Customer Not Available`,
  582. SUM(CASE WHEN LS.`leadStatusId` = 29 THEN 1 ELSE 0 END) AS `Language Barrier`,
  583. SUM(CASE WHEN LS.`leadStatusId` = 30 THEN 1 ELSE 0 END) AS `No Response`,
  584. SUM(CASE WHEN LS.`leadStatusId` = 33 THEN 1 ELSE 0 END) AS `Invalid Number`,
  585. SUM(CASE WHEN LS.`leadStatusId` = 36 THEN 1 ELSE 0 END) AS `Junk`,
  586. SUM(CASE WHEN LS.`leadStatusId` = 39 THEN 1 ELSE 0 END) AS `Ringing no response after five tries`,
  587. SUM(CASE WHEN LS.`leadStatusId` = 43 THEN 1 ELSE 0 END) AS `Switched Off/ Not Reachable after 5 tries`
  588. FROM `lead` join user on user.id=lead.currentAllocatedId left join leadStatus LS on LS.leadStatusId=lead.leadStatusId where lead.leadStatusId !=36 AND lead.updatedOn >= "'.@$start.'" and lead.updatedOn <= "'.@$end.'" group by lead.currentAllocatedId';
  589. $esx = mysql_query($tableres) or die(mysql_error());
  590. $queryforinsert = "Insert into ".$table." (`Caller Name`,`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`)
  591. select 'Total',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."";
  592. mysql_query($queryforinsert);
  593. $sql_query = "select * from $table";
  594. // Gets the data from the database
  595. $result = mysql_query($sql_query) or die(mysql_error());
  596. $fields_cnt = mysql_num_fields($result);
  597. $schema_insert = '';
  598. for ($i = 0; $i < $fields_cnt; $i++)
  599. {
  600. $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
  601. stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;
  602. $schema_insert .= $l;
  603. $schema_insert .= $csv_separator;
  604. } // end for
  605. $out = trim(substr($schema_insert, 0, -1));
  606. $out .= $csv_terminated;
  607. // Format the data
  608. while ($row = mysql_fetch_array($result))
  609. {
  610. $schema_insert = '';
  611. for ($j = 0; $j < $fields_cnt; $j++)
  612. {
  613. if ($row[$j] == '0' || $row[$j] != '')
  614. {
  615. if ($csv_enclosed == '')
  616. {
  617. $schema_insert .= $row[$j];
  618. } else
  619. {
  620. $schema_insert .= $csv_enclosed .
  621. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
  622. }
  623. } else
  624. {
  625. $schema_insert .= '';
  626. }
  627. if ($j < $fields_cnt - 1)
  628. {
  629. $schema_insert .= $csv_separator;
  630. }
  631. } // end for
  632. $out .= $schema_insert;
  633. $out .= $csv_terminated;
  634. } // end while
  635. /// header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  636. //header("Content-Length: " . strlen($out));
  637. // Output to browser with appropriate mime type, you choose ;)
  638. // header("Content-Disposition: attachment; filename=$filename");
  639. //header("Content-type: text/x-csv");
  640. $fd = fopen ($filename, "w");
  641. fputs($fd, $out);
  642. fclose($fd);
  643. echo "success";
  644. //header("Content-type: text/csv");
  645. //header("Content-type: application/csv");
  646. //echo $out;
  647. exit;
  648. }
  649. public function actionagentfreshleadsdisposition(){
  650. /* $date = date('d_M_Y')."_";
  651. $start = mktime(0, 0, 0);
  652. $end = mktime(23, 59, 59);
  653. */
  654. ini_set('max_input_time', 2400);
  655. ini_set('max_execution_time', 2400);
  656. $parser = new CHtmlPurifier();
  657. $afterMonth = $parser->purify(intval(@$_REQUEST['month']));
  658. $afterDate = $parser->purify(intval(@$_REQUEST['date']));
  659. $afterYear = $parser->purify(intval(@$_REQUEST['year']));
  660. if(isset($afterMonth) && !empty($afterMonth) && isset($afterDate) && !empty($afterDate) && isset($afterYear) && !empty($afterYear)){
  661. $start = mktime(0, 0, 0,$afterMonth,$afterDate,$afterYear);
  662. $end = mktime(23, 59, 59,$afterMonth,$afterDate,$afterYear);
  663. } else {
  664. $start = mktime(0, 0, 0);
  665. $end = mktime(23, 59, 59);
  666. }
  667. $time = time();
  668. $date = date('d_M_Y',$start).'_';
  669. $host = '10.216.6.59'; // MYSQL database host adress
  670. $db = 'lms'; // MYSQL database name
  671. $user = 'root'; // Mysql Datbase user
  672. $pass = '0kwp6aNR'; // Mysql Datbase password
  673. $link=mysql_connect($host,$user,$pass);
  674. mysql_select_db($db,$link);
  675. $table='report_agentfreshleadsdisposition';
  676. $filename = "filesystem/".$date.$table.'.csv';
  677. $csv_terminated = "\n";
  678. $csv_separator = ",";
  679. $csv_enclosed = '"';
  680. $csv_escaped = "\\";
  681. $time = time();
  682. mysql_query("insert into report_info (id,type,filename,createdOn,createdBy,updatedOn,updatedBy) values('','agentfreshleadsdisposition','".@$filename."','".@$time."','".@$_SESSION['id']."','".@$time."','".@$_SESSION['id']."')");
  683. $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';
  684. $chktableExist = mysql_query('DROP TABLE IF EXISTS '.$table.' ') or die(mysql_error());
  685. $tableres ='create table IF NOT EXISTS '.$table.' as SELECT
  686. user.userName as `Caller Name`,
  687. SUM(CASE WHEN lead.currentAllocatedId=user.id THEN 1 ELSE 0 END) AS `Total Assigned`,
  688. SUM(CASE WHEN lead.currentAllocatedId=user.id AND lead.leadStatusId NOT IN ('.@$totalleadstatusids.') THEN 1 ELSE 0 END) AS `No Update`,
  689. SUM(CASE WHEN lead.currentAllocatedId=user.id AND lead.leadStatusId IN ('.@$totalleadstatusids.') THEN 1 ELSE 0 END) AS `Total Diposed`,
  690. SUM(CASE WHEN LS.`leadStatusId` = 7 THEN 1 ELSE 0 END) AS `Sale Done`,
  691. SUM(CASE WHEN LS.`leadStatusId` = 8 THEN 1 ELSE 0 END) AS `Follow Up`,
  692. SUM(CASE WHEN LS.`leadStatusId` = 9 THEN 1 ELSE 0 END) AS `Do Not Call - Will Buy self on Website`,
  693. SUM(CASE WHEN LS.`leadStatusId` = 10 THEN 1 ELSE 0 END) AS `Duplicate - Already In Talk With Team`,
  694. SUM(CASE WHEN LS.`leadStatusId` = 37 THEN 1 ELSE 0 END) AS `In Contact with Oflline Agent`,
  695. SUM(CASE WHEN LS.`leadStatusId` = 38 THEN 1 ELSE 0 END) AS `In Touch With Other Partner`,
  696. SUM(CASE WHEN LS.`leadStatusId` = 11 THEN 1 ELSE 0 END) AS `Short Hangup`,
  697. SUM(CASE WHEN LS.`leadStatusId` = 12 THEN 1 ELSE 0 END) AS `Call Later`,
  698. SUM(CASE WHEN LS.`leadStatusId` = 42 THEN 1 ELSE 0 END) AS `Ringing Less Than Five Tries`,
  699. SUM(CASE WHEN LS.`leadStatusId` = 43 THEN 1 ELSE 0 END) AS `Switched Off Less than Five Tries`,
  700. SUM(CASE WHEN LS.`leadStatusId` = 13 THEN 1 ELSE 0 END) AS `Not Interested - Fund Problem`,
  701. SUM(CASE WHEN LS.`leadStatusId` = 14 THEN 1 ELSE 0 END) AS `Just Checking Website`,
  702. SUM(CASE WHEN LS.`leadStatusId` = 15 THEN 1 ELSE 0 END) AS `Not Interested - Insured From Employer`,
  703. SUM(CASE WHEN LS.`leadStatusId` = 16 THEN 1 ELSE 0 END) AS `Not Interested - High Premium`,
  704. SUM(CASE WHEN LS.`leadStatusId` = 17 THEN 1 ELSE 0 END) AS `Under Age`,
  705. SUM(CASE WHEN LS.`leadStatusId` = 18 THEN 1 ELSE 0 END) AS `Not Visited Website`,
  706. SUM(CASE WHEN LS.`leadStatusId` = 19 THEN 1 ELSE 0 END) AS `Do Not Call`,
  707. SUM(CASE WHEN LS.`leadStatusId` = 20 THEN 1 ELSE 0 END) AS `Not Interested - General`,
  708. SUM(CASE WHEN LS.`leadStatusId` = 21 THEN 1 ELSE 0 END) AS `Over Age`,
  709. SUM(CASE WHEN LS.`leadStatusId` = 22 THEN 1 ELSE 0 END) AS `Not Interested - Already Insured`,
  710. SUM(CASE WHEN LS.`leadStatusId` = 23 THEN 1 ELSE 0 END) AS `Duplicate Data - Not Interested`,
  711. SUM(CASE WHEN LS.`leadStatusId` = 24 THEN 1 ELSE 0 END) AS `Not Eligible - PED`,
  712. SUM(CASE WHEN LS.`leadStatusId` = 25 THEN 1 ELSE 0 END) AS `Not Interested - Govt. Employee`,
  713. SUM(CASE WHEN LS.`leadStatusId` = 26 THEN 1 ELSE 0 END) AS `Not Interested - Senior Citizen`,
  714. SUM(CASE WHEN LS.`leadStatusId` = 27 THEN 1 ELSE 0 END) AS `Wrong Number`,
  715. SUM(CASE WHEN LS.`leadStatusId` = 28 THEN 1 ELSE 0 END) AS `Customer Not Available`,
  716. SUM(CASE WHEN LS.`leadStatusId` = 29 THEN 1 ELSE 0 END) AS `Language Barrier`,
  717. SUM(CASE WHEN LS.`leadStatusId` = 30 THEN 1 ELSE 0 END) AS `No Response`,
  718. SUM(CASE WHEN LS.`leadStatusId` = 33 THEN 1 ELSE 0 END) AS `Invalid Number`,
  719. SUM(CASE WHEN LS.`leadStatusId` = 36 THEN 1 ELSE 0 END) AS `Junk`,
  720. SUM(CASE WHEN LS.`leadStatusId` = 39 THEN 1 ELSE 0 END) AS `Ringing no response after five tries`,
  721. SUM(CASE WHEN LS.`leadStatusId` = 43 THEN 1 ELSE 0 END) AS `Switched Off/ Not Reachable after 5 tries`
  722. FROM `lead` join user on user.id=lead.currentAllocatedId left join leadStatus LS on LS.leadStatusId=lead.leadStatusId where lead.leadStatusId !=36 AND lead.currentAllocatedDate >= "'.@$start.'" and lead.currentAllocatedDate <= "'.@$end.'" AND lead.leadId IN(select leadId from lead where lead.updatedOn >= "'.@$start.'" and lead.updatedOn <= "'.@$end.'" and lead.currentAllocatedDate >= "'.@$start.'" and lead.currentAllocatedDate <= "'.@$end.'" ) group by lead.currentAllocatedId';
  723. $esx = mysql_query($tableres) or die(mysql_error());
  724. $queryforinsert = "Insert into ".$table." (`Caller Name`,`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`)
  725. select 'Total',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."";
  726. mysql_query($queryforinsert);
  727. $sql_query = "select * from $table";
  728. // Gets the data from the database
  729. $result = mysql_query($sql_query);
  730. $fields_cnt = mysql_num_fields($result);
  731. $schema_insert = '';
  732. for ($i = 0; $i < $fields_cnt; $i++)
  733. {
  734. $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
  735. stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;
  736. $schema_insert .= $l;
  737. $schema_insert .= $csv_separator;
  738. } // end for
  739. $out = trim(substr($schema_insert, 0, -1));
  740. $out .= $csv_terminated;
  741. // Format the data
  742. while ($row = mysql_fetch_array($result))
  743. {
  744. $schema_insert = '';
  745. for ($j = 0; $j < $fields_cnt; $j++)
  746. {
  747. if ($row[$j] == '0' || $row[$j] != '')
  748. {
  749. if ($csv_enclosed == '')
  750. {
  751. $schema_insert .= $row[$j];
  752. } else
  753. {
  754. $schema_insert .= $csv_enclosed .
  755. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
  756. }
  757. } else
  758. {
  759. $schema_insert .= '';
  760. }
  761. if ($j < $fields_cnt - 1)
  762. {
  763. $schema_insert .= $csv_separator;
  764. }
  765. } // end for
  766. $out .= $schema_insert;
  767. $out .= $csv_terminated;
  768. } // end while
  769. $fd = fopen ($filename, "w");
  770. fputs($fd, $out);
  771. fclose($fd);
  772. echo "success";
  773. //header("Content-type: text/csv");
  774. //header("Content-type: application/csv");
  775. //echo $out;
  776. exit;
  777. }
  778. public function actioncampaignwisedispositiondaily(){
  779. $time = time();
  780. $parser = new CHtmlPurifier();
  781. $afterMonth = $parser->purify(intval(@$_REQUEST['month']));
  782. $afterDate = $parser->purify(intval(@$_REQUEST['date']));
  783. $afterYear = $parser->purify(intval(@$_REQUEST['year']));
  784. if(isset($afterMonth) && !empty($afterMonth) && isset($afterDate) && !empty($afterDate) && isset($afterYear) && !empty($afterYear)){
  785. $start = mktime(0, 0, 0,$afterMonth,$afterDate,$afterYear);
  786. $end = mktime(23, 59, 59,$afterMonth,$afterDate,$afterYear);
  787. } else {
  788. $start = mktime(0, 0, 0);
  789. $end = mktime(23, 59, 59);
  790. }
  791. $date = date('d_M_Y',$start)."_";
  792. $host = '10.216.6.59'; // MYSQL database host adress
  793. $db = 'lms'; // MYSQL database name
  794. $user = 'root'; // Mysql Datbase user
  795. $pass = '0kwp6aNR'; // Mysql Datbase password
  796. $link=mysql_connect($host,$user,$pass);
  797. mysql_select_db($db,$link);
  798. $table='report_campaignwisedispositiondaily';
  799. $filename = "filesystem/".$date.$table.'.csv';
  800. $csv_terminated = "\n";
  801. $csv_separator = ",";
  802. $csv_enclosed = '"';
  803. $csv_escaped = "\\";
  804. mysql_query("insert into report_info (id,type,filename,createdOn,createdBy,updatedOn,updatedBy) values('','campaignwisedispositiondaily','".@$filename."','".@$time."','".@$_SESSION['id']."','".@$time."','".@$_SESSION['id']."')");
  805. $chktableExist = mysql_query('DROP TABLE IF EXISTS '.$table.' ') or die(mysql_error());
  806. $tableres ='create table IF NOT EXISTS '.$table.' as SELECT LS.leadSourceCode as `Agent Code`,LS.leadSourceTitle as `Name`,count(L.ws_agentid) as `Total Diposed`,
  807. SUM(CASE WHEN L.`leadStatusId` = 7 THEN 1 ELSE 0 END) AS `Sale Done`,
  808. SUM(CASE WHEN L.`leadStatusId` = 8 THEN 1 ELSE 0 END) AS `Follow Up`,
  809. SUM(CASE WHEN L.`leadStatusId` = 9 THEN 1 ELSE 0 END) AS `Do Not Call - Will Buy self on Website`,
  810. SUM(CASE WHEN L.`leadStatusId` = 10 THEN 1 ELSE 0 END) AS `Duplicate - Already In Talk With Team`,
  811. SUM(CASE WHEN L.`leadStatusId` = 37 THEN 1 ELSE 0 END) AS `In Contact with Oflline Agent`,
  812. SUM(CASE WHEN L.`leadStatusId` = 38 THEN 1 ELSE 0 END) AS `In Touch With Other Partner`,
  813. SUM(CASE WHEN L.`leadStatusId` = 11 THEN 1 ELSE 0 END) AS `Short Hangup`,
  814. SUM(CASE WHEN L.`leadStatusId` = 12 THEN 1 ELSE 0 END) AS `Call Later`,
  815. SUM(CASE WHEN L.`leadStatusId` = 42 THEN 1 ELSE 0 END) AS `Ringing Less Than Five Tries`,
  816. SUM(CASE WHEN L.`leadStatusId` = 43 THEN 1 ELSE 0 END) AS `Switched Off Less than Five Tries`,
  817. SUM(CASE WHEN L.`leadStatusId` = 13 THEN 1 ELSE 0 END) AS `Not Interested - Fund Problem`,
  818. SUM(CASE WHEN L.`leadStatusId` = 14 THEN 1 ELSE 0 END) AS `Just Checking Website`,
  819. SUM(CASE WHEN L.`leadStatusId` = 15 THEN 1 ELSE 0 END) AS `Not Interested - Insured From Employer`,
  820. SUM(CASE WHEN L.`leadStatusId` = 16 THEN 1 ELSE 0 END) AS `Not Interested - High Premium`,
  821. SUM(CASE WHEN L.`leadStatusId` = 17 THEN 1 ELSE 0 END) AS `Under Age`,
  822. SUM(CASE WHEN L.`leadStatusId` = 18 THEN 1 ELSE 0 END) AS `Not Visited Website`,
  823. SUM(CASE WHEN L.`leadStatusId` = 19 THEN 1 ELSE 0 END) AS `Do Not Call`,
  824. SUM(CASE WHEN L.`leadStatusId` = 20 THEN 1 ELSE 0 END) AS `Not Interested - General`,
  825. SUM(CASE WHEN L.`leadStatusId` = 21 THEN 1 ELSE 0 END) AS `Over Age`,
  826. SUM(CASE WHEN L.`leadStatusId` = 22 THEN 1 ELSE 0 END) AS `Not Interested - Already Insured`,
  827. SUM(CASE WHEN L.`leadStatusId` = 23 THEN 1 ELSE 0 END) AS `Duplicate Data - Not Interested`,
  828. SUM(CASE WHEN L.`leadStatusId` = 24 THEN 1 ELSE 0 END) AS `Not Eligible - PED`,
  829. SUM(CASE WHEN L.`leadStatusId` = 25 THEN 1 ELSE 0 END) AS `Not Interested - Govt. Employee`,
  830. SUM(CASE WHEN L.`leadStatusId` = 26 THEN 1 ELSE 0 END) AS `Not Interested - Senior Citizen`,
  831. SUM(CASE WHEN L.`leadStatusId` = 27 THEN 1 ELSE 0 END) AS `Wrong Number`,
  832. SUM(CASE WHEN L.`leadStatusId` = 28 THEN 1 ELSE 0 END) AS `Customer Not Available`,
  833. SUM(CASE WHEN L.`leadStatusId` = 29 THEN 1 ELSE 0 END) AS `Language Barrier`,
  834. SUM(CASE WHEN L.`leadStatusId` = 30 THEN 1 ELSE 0 END) AS `No Response`,
  835. SUM(CASE WHEN L.`leadStatusId` = 33 THEN 1 ELSE 0 END) AS `Invalid Number`,
  836. SUM(CASE WHEN L.`leadStatusId` = 36 THEN 1 ELSE 0 END) AS `Junk`,
  837. SUM(CASE WHEN L.`leadStatusId` = 39 THEN 1 ELSE 0 END) AS `Ringing no response after five tries`,
  838. SUM(CASE WHEN L.`leadStatusId` = 43 THEN 1 ELSE 0 END) AS `Switched Off/ Not Reachable after 5 tries`
  839. from leadSourceMaster LS left join lead L on L.ws_agentid=LS.leadSourceCode where L.leadStatusId !=36 AND L.updatedOn >= "'.@$start.'" and L.updatedOn <= "'.@$end.'" group by L.leadStatusId,LS.leadSourceCode';
  840. $esx = mysql_query($tableres) or die(mysql_error());
  841. $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`)
  842. 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."";
  843. mysql_query($queryforinsert);
  844. $sql_query = "select * from ".$table."";
  845. // Gets the data from the database
  846. $result = mysql_query($sql_query);
  847. $fields_cnt = mysql_num_fields($result);
  848. $schema_insert = '';
  849. for ($i = 0; $i < $fields_cnt; $i++)
  850. {
  851. $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
  852. stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;
  853. $schema_insert .= $l;
  854. $schema_insert .= $csv_separator;
  855. } // end for
  856. $out = trim(substr($schema_insert, 0, -1));
  857. $out .= $csv_terminated;
  858. // Format the data
  859. while ($row = mysql_fetch_array($result))
  860. {
  861. $schema_insert = '';
  862. for ($j = 0; $j < $fields_cnt; $j++)
  863. {
  864. if ($row[$j] == '0' || $row[$j] != '')
  865. {
  866. if ($csv_enclosed == '')
  867. {
  868. $schema_insert .= $row[$j];
  869. } else
  870. {
  871. $schema_insert .= $csv_enclosed .
  872. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
  873. }
  874. } else
  875. {
  876. $schema_insert .= '';
  877. }
  878. if ($j < $fields_cnt - 1)
  879. {
  880. $schema_insert .= $csv_separator;
  881. }
  882. } // end for
  883. $out .= $schema_insert;
  884. $out .= $csv_terminated;
  885. } // end while
  886. $fd = fopen ($filename, "w");
  887. fputs($fd, $out);
  888. fclose($fd);
  889. echo "success";
  890. //header("Content-type: text/csv");
  891. //header("Content-type: application/csv");
  892. //echo $out;
  893. exit;
  894. }
  895. public function actiondatadumpsameday(){
  896. ini_set('max_input_time', 1200);
  897. ini_set('max_execution_time', 1200);
  898. $parser = new CHtmlPurifier();
  899. $afterMonth = $parser->purify(intval(@$_REQUEST['month']));
  900. $afterDate = $parser->purify(intval(@$_REQUEST['date']));
  901. $afterYear = $parser->purify(intval(@$_REQUEST['year']));
  902. if(isset($afterMonth) && !empty($afterMonth) && isset($afterDate) && !empty($afterDate) && isset($afterYear) && !empty($afterYear)){
  903. $start = mktime(0, 0, 0,$afterMonth,$afterDate,$afterYear);
  904. $end = mktime(23, 59, 59,$afterMonth,$afterDate,$afterYear);
  905. } else {
  906. $start = mktime(0, 0, 0);
  907. $end = mktime(23, 59, 59);
  908. }
  909. $time = time();
  910. $date = date('d_M_Y',$start).'_';
  911. $host = '10.216.6.59'; // MYSQL database host adress
  912. $db = 'lms'; // MYSQL database name
  913. $user = 'root'; // Mysql Datbase user
  914. $pass = '0kwp6aNR'; // Mysql Datbase password
  915. $link=mysql_connect($host,$user,$pass);
  916. mysql_select_db($db,$link);
  917. $table='report_datadumpsameday';
  918. $filename = "filesystem/".$date.$table.'.csv';
  919. $csv_terminated = "\n";
  920. $csv_separator = ",";
  921. $csv_enclosed = '"';
  922. $csv_escaped = "\\";
  923. mysql_query("insert into report_info (id,type,filename,createdOn,createdBy,updatedOn,updatedBy) values('','datadumpsameday','".@$filename."','".@$time."','".@$_SESSION['id']."','".@$time."','".@$_SESSION['id']."')");
  924. $chktableExist = mysql_query('DROP TABLE IF EXISTS '.$table.' ') or die(mysql_error());
  925. mysql_query('set @a:=0');
  926. $tableres ="create table IF NOT EXISTS ".$table." as select @a:=@a+1 `Sr.no`,L.mobile as `mobile`,from_unixtime(L.createdOn, '%Y/%m/%d') as `Lead Creat Date`,from_unixtime(L.createdOn, '%h:%i:%s %p') as `Lead created Time`,IF((L.currentAllocatedDate='' or L.currentAllocatedDate=0),0,from_unixtime(L.currentAllocatedDate, '%Y/%m/%d')) as `Lead Assign Date`,IF((L.currentAllocatedDate='' or L.currentAllocatedDate=0),0,from_unixtime(L.currentAllocatedDate, '%h:%i:%s %p')) as `Lead Assign Time`,LS.LeadsourceTitle as `Agent Name`,L.ws_agentId as `Agent Code`,CG.campaignName as `Campagin Name`,LSS.leadStatus as `Disposition`,L.leadDescription as `Remarks` from lead L left join leadSourceMaster LS on LS.leadSourceCode=L.ws_agentid left join campaign CG on CG.campaignId=L.campaignId left join leadStatus LSS on LSS.leadstatusId=L.leadStatusId where L.leadStatusId !=36 AND L.createdOn >= '".@$start."' and L.createdOn <= '".@$end."'";
  927. $esx = mysql_query($tableres) or die(mysql_error());
  928. $sql_query = "select * from $table";
  929. // Gets the data from the database
  930. $result = mysql_query($sql_query);
  931. $fields_cnt = mysql_num_fields($result);
  932. $schema_insert = '';
  933. for ($i = 0; $i < $fields_cnt; $i++)
  934. {
  935. $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
  936. stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;
  937. $schema_insert .= $l;
  938. $schema_insert .= $csv_separator;
  939. } // end for
  940. $out = trim(substr($schema_insert, 0, -1));
  941. $out .= $csv_terminated;
  942. // Format the data
  943. while ($row = mysql_fetch_array($result))
  944. {
  945. $schema_insert = '';
  946. for ($j = 0; $j < $fields_cnt; $j++)
  947. {
  948. if ($row[$j] == '0' || $row[$j] != '')
  949. {
  950. if ($csv_enclosed == '')
  951. {
  952. $schema_insert .= $row[$j];
  953. } else
  954. {
  955. $schema_insert .= $csv_enclosed .
  956. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
  957. }
  958. } else
  959. {
  960. $schema_insert .= '';
  961. }
  962. if ($j < $fields_cnt - 1)
  963. {
  964. $schema_insert .= $csv_separator;
  965. }
  966. } // end for
  967. $out .= $schema_insert;
  968. $out .= $csv_terminated;
  969. } // end while
  970. $fd = fopen ($filename, "w");
  971. fputs($fd, $out);
  972. fclose($fd);
  973. echo "success";
  974. //header("Content-type: text/csv");
  975. //header("Content-type: application/csv");
  976. //echo $out;
  977. exit;
  978. }
  979. public function actiondatadumpmtd(){
  980. ini_set('max_input_time', 1200);
  981. ini_set('max_execution_time', 1200);
  982. $parser = new CHtmlPurifier();
  983. $afterMonth = $parser->purify(intval(@$_REQUEST['month']));
  984. $afterYear = $parser->purify(intval(@$_REQUEST['year']));
  985. if(isset($afterMonth) && !empty($afterMonth) && isset($afterYear) && !empty($afterYear)){
  986. $start =mktime(0, 0, 0, $afterMonth, 1,$afterYear);
  987. $end = mktime(23, 59, 0, $afterMonth, date('t', $start),$afterYear);
  988. } else {
  989. $start = strtotime('first day of this month', time());
  990. $end = strtotime('last day of this month', time());
  991. }
  992. $date = date('d_M_Y',$start).'_';
  993. $host = '10.216.6.59'; // MYSQL database host adress
  994. $db = 'lms'; // MYSQL database name
  995. $user = 'root'; // Mysql Datbase user
  996. $pass = '0kwp6aNR'; // Mysql Datbase password
  997. $link=mysql_connect($host,$user,$pass);
  998. mysql_select_db($db,$link);
  999. $table='report_datadumpmtd';
  1000. $filename = "filesystem/".$date.$table.'.csv';
  1001. $csv_terminated = "\n";
  1002. $csv_separator = ",";
  1003. $csv_enclosed = '"';
  1004. $csv_escaped = "\\";
  1005. $time = time();
  1006. mysql_query("insert into report_info (id,type,filename,createdOn,createdBy,updatedOn,updatedBy) values('','datadumpmtd','".@$filename."','".@$time."','".@$_SESSION['id']."','".@$time."','".@$_SESSION['id']."')");
  1007. $chktableExist = mysql_query('DROP TABLE IF EXISTS '.$table.' ') or die(mysql_error());
  1008. // $start = strtotime('first day of this month', time());
  1009. // $end = strtotime('last day of this month', time());
  1010. mysql_query('set @a:=0');
  1011. $tableres ="create table IF NOT EXISTS ".$table." as select @a:=@a+1 `Sr.no`,L.mobile as `mobile`,from_unixtime(L.createdOn, '%Y/%m/%d') as `Lead Creat Date`,from_unixtime(L.createdOn, '%h:%i:%s %p') as `Lead created Time`,IF(L.currentAllocatedDate='',0,from_unixtime(L.currentAllocatedDate, '%Y/%m/%d')) as `Lead Assign Date`,IF(L.currentAllocatedDate='',0,from_unixtime(L.currentAllocatedDate, '%h:%i:%s %p')) as `Lead Assign Time`,LS.LeadsourceTitle as `Agent Name`,L.ws_agentId as `Agent Code`,CG.campaignName as `Campagin Name`,LSS.leadStatus as `Disposition`,L.leadDescription as `Remarks` from lead L left join leadSourceMaster LS on LS.leadSourceCode=L.ws_agentid left join campaign CG on CG.campaignId=L.campaignId left join leadStatus LSS on LSS.leadstatusId=L.leadStatusId where L.leadStatusId !=36 AND L.updatedOn >= '".@$start."' and L.updatedOn <= '".@$end."'";
  1012. $esx = mysql_query($tableres) or die(mysql_error());
  1013. $sql_query = "select * from $table";
  1014. // Gets the data from the database
  1015. $result = mysql_query($sql_query);
  1016. $fields_cnt = mysql_num_fields($result);
  1017. $schema_insert = '';
  1018. for ($i = 0; $i < $fields_cnt; $i++)
  1019. {
  1020. $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
  1021. stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;
  1022. $schema_insert .= $l;
  1023. $schema_insert .= $csv_separator;
  1024. } // end for
  1025. $out = trim(substr($schema_insert, 0, -1));
  1026. $out .= $csv_terminated;
  1027. // Format the data
  1028. while ($row = mysql_fetch_array($result))
  1029. {
  1030. $schema_insert = '';
  1031. for ($j = 0; $j < $fields_cnt; $j++)
  1032. {
  1033. if ($row[$j] == '0' || $row[$j] != '')
  1034. {
  1035. if ($csv_enclosed == '')
  1036. {
  1037. $schema_insert .= $row[$j];
  1038. } else
  1039. {
  1040. $schema_insert .= $csv_enclosed .
  1041. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
  1042. }
  1043. } else
  1044. {
  1045. $schema_insert .= '';
  1046. }
  1047. if ($j < $fields_cnt - 1)
  1048. {
  1049. $schema_insert .= $csv_separator;
  1050. }
  1051. } // end for
  1052. $out .= $schema_insert;
  1053. $out .= $csv_terminated;
  1054. } // end while
  1055. $fd = fopen ($filename, "w");
  1056. fputs($fd, $out);
  1057. fclose($fd);
  1058. echo "success";
  1059. //header("Content-type: text/csv");
  1060. //header("Content-type: application/csv");
  1061. //echo $out;
  1062. exit;
  1063. }
  1064. public function actionreporttest(){
  1065. $maxDays=date('t');
  1066. $date = date('d_M_Y').'_';
  1067. $host = '10.216.6.59'; // MYSQL database host adress
  1068. $db = 'lms'; // MYSQL database name
  1069. $user = 'root'; // Mysql Datbase user
  1070. $pass = '0kwp6aNR'; // Mysql Datbase password
  1071. $link=mysql_connect($host,$user,$pass);
  1072. mysql_select_db($db,$link);
  1073. $table='report_datadumpmtd';
  1074. $query = mysql_query("select leadSourceCode,leadSourceTitle from leadSourceMaster") ;
  1075. $columnName = array();
  1076. $l=0;
  1077. while($l= mysql_fetch_array($query)){
  1078. $columnName[] = $l['leadSourceCode'];
  1079. $columnNameData[] = $l['leadSourceCode'];
  1080. $leadSourceName[] = $l['leadSourceTitle'];
  1081. $l++;
  1082. }
  1083. $columnName=implode(',',$columnName);
  1084. $leadSourceName=implode(',',$leadSourceName);
  1085. if(count($l)>0){
  1086. $file_name = "lms" . "_" . date("Y-m-d_H-i", time()) . ".csv";
  1087. header('Content-Type: text/html; charset=utf-8');
  1088. header("Content-type: application/octet-stream");
  1089. header("Content-Disposition: attachment; filename=\"$file_name\"");
  1090. header("Cache-Control: cache, must-revalidate");
  1091. header("Pragma: public");
  1092. $col = array(
  1093. 'Agent Code','Total',$columnName);
  1094. foreach ($col as $key => $value) {
  1095. echo $value . ",";
  1096. }
  1097. echo "\n";
  1098. $col2 = array(
  1099. 'Agent Name','',$leadSourceName);
  1100. foreach ($col2 as $key => $value) {
  1101. echo $value . ",";
  1102. }
  1103. echo "\n";
  1104. $i=2;
  1105. $col3 = array($columnNameData);
  1106. $f=0;
  1107. $neresult = 0;
  1108. for($y=1;$y<=$maxDays;$y++) {
  1109. $date = $y.date('/m/Y');
  1110. $explodedDate = explode('/',$date);
  1111. $time = strtotime($explodedDate[0]."-".$explodedDate[1]."-".$explodedDate[2]);
  1112. $timePm = strtotime($explodedDate[0]."-".$explodedDate[1]."-".$explodedDate[2])+86399;
  1113. echo $y.date('/M/Y'). ",";
  1114. $quert = mysql_query('select count(*) as total from lead where ws_agentId IN( "'.@$value[0].'","'.@$value[1].'") and updatedOn >= "'.@$time.'" and updatedOn <= "'.@$timePm.'"');
  1115. $resT = mysql_fetch_array($quert);
  1116. $neresult =$neresult+$resT[0];
  1117. echo $resT[0] . ",";
  1118. foreach ($col3 as $key => $value) {
  1119. $quer = mysql_query('select count(*) as total from lead where ws_agentId = "'.@$value[0].'" and updatedOn >= "'.@$time.'" and updatedOn <= "'.@$timePm.'"');
  1120. $res = mysql_fetch_array($quer);
  1121. $quer1 = mysql_query('select count(*) as total from lead where ws_agentId = "'.@$value[1].'" and updatedOn >= "'.@$time.'" and updatedOn <= "'.@$timePm.'"');
  1122. $res1 = mysql_fetch_array($quer1);
  1123. echo $res[0] . ",";
  1124. echo $res1[0] . ",";
  1125. // echo date('d:m:y::h:i:s A',$time) . ",";
  1126. $f++;
  1127. }
  1128. echo "\n";
  1129. }
  1130. echo 'total data'. ",";
  1131. echo $neresult. ",";
  1132. echo "\n";
  1133. }
  1134. }
  1135. public function actiondatamis_old(){
  1136. ini_set('max_input_time', 300);
  1137. ini_set('max_execution_time', 300);
  1138. $host = '10.216.6.59'; // MYSQL database host adress
  1139. $db = 'lms'; // MYSQL database name
  1140. $user = 'root'; // Mysql Datbase user
  1141. $pass = '0kwp6aNR'; // Mysql Datbase password
  1142. $link=mysql_connect($host,$user,$pass);
  1143. mysql_select_db($db,$link);
  1144. $table='report_datamis';
  1145. $chktableExist = mysql_query('DROP TABLE IF EXISTS '.$table.' ') or die(mysql_error());
  1146. $parser = new CHtmlPurifier();
  1147. $afterMonth = $parser->purify(intval(@$_REQUEST['month']));
  1148. $afterYear = $parser->purify(intval(@$_REQUEST['year']));
  1149. if(isset($afterMonth) && !empty($afterMonth) && isset($afterYear) && !empty($afterYear)){
  1150. $start =mktime(0, 0, 0, $afterMonth, 1,$afterYear);
  1151. $end = mktime(23, 59, 0, $afterMonth, date('t', $start),$afterYear);
  1152. } else {
  1153. $start = strtotime('first day of this month', time());
  1154. $end = strtotime('last day of this month', time());
  1155. }
  1156. mysql_query("UPDATE `leadSourceMaster` SET leadSourceTitleReport=REPLACE(leadSourceTitle,' ','')");
  1157. mysql_query("SELECT
  1158. CONCAT(
  1159. 'CREATE TABLE ".$table." (',
  1160. GROUP_CONCAT(DISTINCT
  1161. CONCAT(leadSourceTitleReport, ' VARCHAR(50)')
  1162. SEPARATOR ','),
  1163. ');')
  1164. FROM
  1165. leadSourceMaster
  1166. INTO @sql") or die(mysql_error());
  1167. mysql_query("PREPARE stmt FROM @sql");
  1168. mysql_query("EXECUTE stmt");
  1169. mysql_query("ALTER TABLE ".$table." ADD `AgentName` VARCHAR( 150 ) NOT NULL FIRST ,
  1170. ADD `Total` VARCHAR( 50 ) NOT NULL AFTER `AgentName`");
  1171. $sourcecode = mysql_query("select distinct leadSourceTitleReport as leadSourceTitle,leadsourceCode from leadSourceMaster group by leadSourceTitleReport");
  1172. $row=0;
  1173. $arraymerger = array();
  1174. // $start = strtotime('first day of this month', time());
  1175. // $end = strtotime('last day of this month', time());
  1176. $totalsourcewise = array();
  1177. $totalsourcewisesales = array();
  1178. $totalcontactable = array();
  1179. $conversionpercentage = array();
  1180. $salesIds = '36';
  1181. $contactableids = '7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22';
  1182. $noncontactableids = '27,28,42,43';
  1183. while ($row = mysql_fetch_array($sourcecode)){
  1184. //echo $row['leadsourceCode'];
  1185. $arraymerger[$row['leadsourceCode']] = $row['leadSourceTitle'] ;
  1186. //echo 'select SUM(CASE WHEN ws_agentId = "'.@$row['leadsourceCode'].'" THEN 1 ELSE 0 END) AS total from lead'; die;
  1187. $quersum = mysql_query('select SUM(CASE WHEN ws_agentId = "'.@$row['leadsourceCode'].'" and updatedOn >= "'.@$start.'" and updatedOn <= "'.@$end.'" AND leadStatusId !=36 THEN 1 ELSE 0 END) AS total from lead');
  1188. $querressum = mysql_fetch_assoc($quersum);
  1189. $totalsourcewise[] = $querressum['total'];
  1190. $quersumsales = mysql_query('select SUM(CASE WHEN ws_agentId = "'.@$row['leadsourceCode'].'" and updatedOn >= "'.@$start.'" and updatedOn <= "'.@$end.'" AND leadStatusId !=36 and leadStatusId IN('.@$salesIds.') THEN 1 ELSE 0 END) AS total from lead');
  1191. $querressumsales = mysql_fetch_assoc($quersumsales);
  1192. $totalsourcewisesales[] = $querressumsales['total'];
  1193. $conversionpercentage[$querressumsales['total']] = $querressum['total'];
  1194. $quersumcontactable = mysql_query('select SUM(CASE WHEN ws_agentId = "'.@$row['leadsourceCode'].'" and updatedOn >= "'.@$start.'" and updatedOn <= "'.@$end.'" AND leadStatusId !=36 and leadStatusId IN('.@$contactableids.') THEN 1 ELSE 0 END) AS total from lead');
  1195. $querressumcontactable = mysql_fetch_assoc($quersumcontactable);
  1196. $totalcontactable[] = $querressumcontactable['total'];
  1197. $row++; }
  1198. $keys = (implode(",",array_keys($arraymerger)));
  1199. $values = (implode(",",array_values($arraymerger)));
  1200. $q="replace into ".$table." (AgentName,".$values.") values ('AgentCode',".$keys.")";
  1201. mysql_query($q) or die(mysql_error());
  1202. $maxDays=date('t');
  1203. $totalData = 0;
  1204. $totalDatasales = 0;
  1205. $totalDatacontactable = 0;
  1206. for($y=1;$y<=$maxDays;$y++) {
  1207. $date = $y.date('/m/Y');
  1208. $explodedDate = explode('/',$date);
  1209. $time = strtotime($explodedDate[0]."-".$explodedDate[1]."-".$explodedDate[2]);
  1210. $timePm = strtotime($explodedDate[0]."-".$explodedDate[1]."-".$explodedDate[2])+86399;
  1211. $totalcountcode = array();
  1212. $totalcountsales = array();
  1213. $totalcountcontact = array();
  1214. $totalcountcoderes=0;
  1215. foreach($arraymerger as $key=>$values1){
  1216. $quer = mysql_query('select count(*) as total from lead where ws_agentId = "'.@$key.'" and updatedOn >= "'.@$time.'" AND leadStatusId !=36 and updatedOn <= "'.@$timePm.'"');
  1217. $querres = mysql_fetch_assoc($quer);
  1218. $totalcountcode[] = $querres['total'];
  1219. $totalcountcoderes =$querres['total'];
  1220. $salesquery = mysql_query('select SUM(CASE WHEN ws_agentId = "'.@$key.'" and updatedOn >= "'.@$time.'" AND leadStatusId !=36 and updatedOn <= "'.@$timePm.'" and leadStatusId IN('.@$salesIds.') THEN 1 ELSE 0 END) as total from lead ');
  1221. $salesqueryres = mysql_fetch_array($salesquery);
  1222. $totalcountsales[] = $salesqueryres['total'];
  1223. $contactquery = mysql_query('select SUM(CASE WHEN ws_agentId = "'.@$key.'" and updatedOn >= "'.@$time.'" AND leadStatusId !=36 and updatedOn <= "'.@$timePm.'" and leadStatusId IN('.@$contactableids.') THEN 1 ELSE 0 END) as total from lead ');
  1224. $contactqueryres = mysql_fetch_array($contactquery);
  1225. $totalcountcontact[] = $contactqueryres['total'];
  1226. }
  1227. $totalsumres = array_sum($totalcountcode);
  1228. $totalsumresales = array_sum($totalcountsales);
  1229. $totalcountcontact = array_sum($totalcountcontact);
  1230. $implodedcountcode = implode(",",$totalcountcode);
  1231. $totalData = $totalData+intval($totalsumres);
  1232. $totalDatasales = $totalDatasales+intval($totalsumresales);
  1233. $totalDatacontactable = $totalDatacontactable+intval($totalcountcontact);
  1234. intval($totalcountcoderes);
  1235. $totalsumsales = array_sum($totalcountsales);
  1236. //print_r($totalcountsales);
  1237. $datequery = "insert into ".$table."(`AgentName`,`Total`,".$values.") values('".$y.date('/M/Y')."',".$totalsumres.",".$implodedcountcode.")";
  1238. mysql_query($datequery);
  1239. }
  1240. $contactper = $totalcontactable;
  1241. $datacontper = $totalsourcewise;
  1242. $datacontpertest = $totalsourcewisesales;
  1243. $totalsourcewise = implode(",",$totalsourcewise);
  1244. $totalsourcewisesales = implode(",",$totalsourcewisesales);
  1245. $totalcontactable = implode(",",$totalcontactable);
  1246. if(@$totalDatacontactable > 0){
  1247. $contactperc = ($totalDatacontactable*100)/$totalData;
  1248. } else {
  1249. $contactperc = '0';
  1250. }
  1251. $contactpervalu =array();
  1252. foreach($contactper as $key2=>$value2){
  1253. if($datacontper[$key2] > 0){
  1254. $contactpervalu[] = '"'.($value2*100)/$datacontper[$key2].'%"';
  1255. } else {
  1256. $contactpervalu[] = "'0%'";
  1257. }
  1258. // $contactpervalu[] = '"'.($value2*100)/$totalDatacontactable.'%"';
  1259. }
  1260. $contactpervalu = implode(",",$contactpervalu);
  1261. if(@$totalData > 0){
  1262. $Datacontributionprec = '100';
  1263. } else {
  1264. $Datacontributionprec = '0';
  1265. }
  1266. $datacontpervalu =array();
  1267. foreach($datacontper as $key4=>$value4){
  1268. if($totalData > 0){
  1269. $datacontpervalu[] = '"'.($value4*100)/$totalData.'%"';
  1270. } else {
  1271. $datacontpervalu[] = "'0%'";
  1272. }
  1273. }
  1274. $datacontpervalu = implode(",",$datacontpervalu);
  1275. $conversionPerkeys = array_keys($conversionpercentage);
  1276. $conversionPervalue = array_values($conversionpercentage);
  1277. $conversionnetres = array();
  1278. for($r=0;$r<count($datacontper);$r++){
  1279. if($datacontper[$r] > 0){
  1280. $conversionnetres[$r] = ($datacontpertest[$r]/$datacontper[$r]).'%"';
  1281. } else {
  1282. $conversionnetres[$r] = "'0%'";
  1283. }
  1284. }
  1285. $conversionpercentagevalu = implode(",",$conversionnetres);
  1286. if($totalData > 0){
  1287. $dataconversionrationtotal = ($totalDatasales/$totalData);
  1288. } else {
  1289. $dataconversionrationtotal = 0;
  1290. }
  1291. //echo "insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Conatctable%','".@$contactperc."%',".@$contactpervalu.")"; die;
  1292. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('TotalData','".@$totalData."',".@$totalsourcewise.")");
  1293. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Sale','".@$totalDatasales."',".@$totalsourcewisesales.")");
  1294. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Conatctabledata','".@$totalDatacontactable."',".@$totalcontactable.")");
  1295. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Conatctable%','".@$contactperc."%',".@$contactpervalu.")");
  1296. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Datacontribution%','".@$Datacontributionprec."%',".@$datacontpervalu.")");
  1297. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Conversion%','".@$dataconversionrationtotal."%',".@$conversionpercentagevalu.")");
  1298. // $tableres ="create table IF NOT EXISTS ".$table." as select leadSourceCode,leadSourceTitle from leadSourceMaster";
  1299. //$esx = mysql_query($tableres) or die(mysql_error());
  1300. $this->actiondatamis_download($start);
  1301. }
  1302. public function actiondatamis(){
  1303. ini_set('max_input_time', 19200);
  1304. ini_set('max_execution_time', 19200);
  1305. $host = '10.216.6.59'; // MYSQL database host adress
  1306. $db = 'lms'; // MYSQL database name
  1307. $user = 'root'; // Mysql Datbase user
  1308. $pass = '0kwp6aNR'; // Mysql Datbase password
  1309. $link=mysql_connect($host,$user,$pass);
  1310. mysql_select_db($db,$link);
  1311. $table='report_datamis';
  1312. $chktableExist = mysql_query('DROP TABLE IF EXISTS '.$table.' ') or die(mysql_error());
  1313. $parser = new CHtmlPurifier();
  1314. $afterMonth = $parser->purify(intval(@$_REQUEST['month']));
  1315. $afterYear = $parser->purify(intval(@$_REQUEST['year']));
  1316. if(isset($afterMonth) && !empty($afterMonth) && isset($afterYear) && !empty($afterYear)){
  1317. $start =mktime(0, 0, 0, $afterMonth, 1,$afterYear);
  1318. $end = mktime(23, 59, 0, $afterMonth, date('t', $start),$afterYear);
  1319. } else {
  1320. $start = strtotime('first day of this month', time());
  1321. $end = strtotime('last day of this month', time());
  1322. }
  1323. mysql_query("UPDATE `leadSourceMaster` SET leadSourceTitleReport=REPLACE(REPLACE(REPLACE(leadSourceTitle,' ',''),'-','_'),'.','')");
  1324. $resnews = mysql_query("SELECT group_concat(CONCAT(`leadSourceTitleReport`)) as res FROM `leadSourceMaster`");
  1325. $netres = mysql_fetch_array($resnews);
  1326. $strg = $netres['res'];
  1327. $replacedstr = str_replace(',',' varchar(50) ,',$strg)." varchar(50)";
  1328. $createsql = "CREATE TABLE IF NOT EXISTS ".$table." (
  1329. ".$replacedstr."
  1330. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  1331. ";
  1332. mysql_query($createsql) or die(mysql_error());
  1333. mysql_query("ALTER TABLE ".$table." ADD `AgentName` VARCHAR( 150 ) NOT NULL FIRST ,
  1334. ADD `Total` VARCHAR( 50 ) NOT NULL AFTER `AgentName`");
  1335. $sourcecode = mysql_query("select distinct leadSourceTitleReport as leadSourceTitle,leadsourceCode from leadSourceMaster group by leadSourceTitleReport");
  1336. $row=0;
  1337. $arraymerger = array();
  1338. // $start = strtotime('first day of this month', time());
  1339. // $end = strtotime('last day of this month', time());
  1340. $totalsourcewise = array();
  1341. $totalsourcewisesales = array();
  1342. $totalcontactable = array();
  1343. $conversionpercentage = array();
  1344. $salesIds = '7';
  1345. $contactableids = '7,8,9,37,38,11,12,13,14,15,16,17,22,23,24,25,26';
  1346. $noncontactableids = '39,40,27,28,29,30,33,42,43';
  1347. while ($row = mysql_fetch_array($sourcecode)){
  1348. //echo $row['leadsourceCode'];
  1349. $arraymerger[$row['leadsourceCode']] = $row['leadSourceTitle'] ;
  1350. //echo 'select SUM(CASE WHEN ws_agentId = "'.@$row['leadsourceCode'].'" THEN 1 ELSE 0 END) AS total from lead'; die;
  1351. $quersum = mysql_query('select SUM(CASE WHEN ws_agentId = "'.@$row['leadsourceCode'].'" and createdOn >= "'.@$start.'" and createdOn <= "'.@$end.'" AND leadStatusId !=36 AND leadStatusId !=10 THEN 1 ELSE 0 END) AS total from lead');
  1352. $querressum = mysql_fetch_assoc($quersum);
  1353. $totalsourcewise[] = $querressum['total'];
  1354. $quersumsales = mysql_query('select SUM(CASE WHEN ws_agentId = "'.@$row['leadsourceCode'].'" and createdOn >= "'.@$start.'" and createdOn <= "'.@$end.'" AND leadStatusId !=36 AND leadStatusId !=10 and leadStatusId IN('.@$salesIds.') THEN 1 ELSE 0 END) AS total from lead');
  1355. $querressumsales = mysql_fetch_assoc($quersumsales);
  1356. $totalsourcewisesales[] = $querressumsales['total'];
  1357. $conversionpercentage[$querressumsales['total']] = $querressum['total'];
  1358. $quersumcontactable = mysql_query('select SUM(CASE WHEN ws_agentId = "'.@$row['leadsourceCode'].'" and createdOn >= "'.@$start.'" and createdOn <= "'.@$end.'" AND leadStatusId !=36 AND leadStatusId !=10 and leadStatusId IN('.@$contactableids.') THEN 1 ELSE 0 END) AS total from lead');
  1359. $querressumcontactable = mysql_fetch_assoc($quersumcontactable);
  1360. $totalcontactable[] = $querressumcontactable['total'];
  1361. $row++; }
  1362. $keys = (implode(",",array_keys($arraymerger)));
  1363. $values = (implode(",",array_values($arraymerger)));
  1364. $q="replace into ".$table." (AgentName,".$values.") values ('AgentCode',".$keys.")";
  1365. mysql_query($q) or die(mysql_error());
  1366. // $maxDays=date('t');
  1367. $maxDays=date('d');
  1368. $totalData = 0;
  1369. $totalDatasales = 0;
  1370. $totalDatacontactable = 0;
  1371. for($y=1;$y<=$maxDays;$y++) {
  1372. $date = $y.date('/m/Y');
  1373. $explodedDate = explode('/',$date);
  1374. $time = strtotime($explodedDate[0]."-".$explodedDate[1]."-".$explodedDate[2]);
  1375. $timePm = strtotime($explodedDate[0]."-".$explodedDate[1]."-".$explodedDate[2])+86399;
  1376. $totalcountcode = array();
  1377. $totalcountsales = array();
  1378. $totalcountcontact = array();
  1379. $totalcountcoderes=0;
  1380. foreach($arraymerger as $key=>$values1){
  1381. $quer = mysql_query('select count(*) as total from lead where ws_agentId = "'.@$key.'" and createdOn >= "'.@$time.'" AND leadStatusId !=36 AND leadStatusId !=10 and createdOn <= "'.@$timePm.'"');
  1382. $querres = mysql_fetch_assoc($quer);
  1383. $totalcountcode[] = $querres['total'];
  1384. $totalcountcoderes =$querres['total'];
  1385. $salesquery = mysql_query('select SUM(CASE WHEN ws_agentId = "'.@$key.'" and createdOn >= "'.@$time.'" AND leadStatusId !=36 AND leadStatusId !=10 and createdOn <= "'.@$timePm.'" and leadStatusId IN('.@$salesIds.') THEN 1 ELSE 0 END) as total from lead ');
  1386. $salesqueryres = mysql_fetch_array($salesquery);
  1387. $totalcountsales[] = $salesqueryres['total'];
  1388. $contactquery = mysql_query('select SUM(CASE WHEN ws_agentId = "'.@$key.'" and createdOn >= "'.@$time.'" AND leadStatusId !=36 AND leadStatusId !=10 and createdOn <= "'.@$timePm.'" and leadStatusId IN('.@$contactableids.') THEN 1 ELSE 0 END) as total from lead ');
  1389. $contactqueryres = mysql_fetch_array($contactquery);
  1390. $totalcountcontact[] = $contactqueryres['total'];
  1391. }
  1392. $totalsumres = array_sum($totalcountcode);
  1393. $totalsumresales = array_sum($totalcountsales);
  1394. $totalcountcontact = array_sum($totalcountcontact);
  1395. $implodedcountcode = implode(",",$totalcountcode);
  1396. $totalData = $totalData+intval($totalsumres);
  1397. $totalDatasales = $totalDatasales+intval($totalsumresales);
  1398. $totalDatacontactable = $totalDatacontactable+intval($totalcountcontact);
  1399. intval($totalcountcoderes);
  1400. $totalsumsales = array_sum($totalcountsales);
  1401. //print_r($totalcountsales);
  1402. $datequery = "insert into ".$table."(`AgentName`,`Total`,".$values.") values('".$y.date('/M/Y')."',".$totalsumres.",".$implodedcountcode.")";
  1403. mysql_query($datequery);
  1404. }
  1405. $contactper = $totalcontactable;
  1406. $datacontper = $totalsourcewise;
  1407. $datacontpertest = $totalsourcewisesales;
  1408. $totalsourcewise = implode(",",$totalsourcewise);
  1409. $totalsourcewisesales = implode(",",$totalsourcewisesales);
  1410. $totalcontactable = implode(",",$totalcontactable);
  1411. if(@$totalDatacontactable > 0){
  1412. //$contactperc = ($totalDatacontactable*100)/$totalData;
  1413. $contactperc = ($totalDatasales*100)/$totalData;
  1414. } else {
  1415. $contactperc = '0';
  1416. }
  1417. $contactpervalu =array();
  1418. foreach($contactper as $key2=>$value2){
  1419. if($datacontper[$key2] > 0){
  1420. $contactpervalu[] = '"'.($value2*100)/$datacontper[$key2].'%"';
  1421. } else {
  1422. $contactpervalu[] = "'0%'";
  1423. }
  1424. // $contactpervalu[] = '"'.($value2*100)/$totalDatacontactable.'%"';
  1425. }
  1426. $contactpervalu = implode(",",$contactpervalu);
  1427. if(@$totalData > 0){
  1428. $Datacontributionprec = '100';
  1429. } else {
  1430. $Datacontributionprec = '0';
  1431. }
  1432. $datacontpervalu =array();
  1433. foreach($datacontper as $key4=>$value4){
  1434. if($totalData > 0){
  1435. $datacontpervalu[] = '"'.($value4*100)/$totalData.'%"';
  1436. } else {
  1437. $datacontpervalu[] = "'0%'";
  1438. }
  1439. }
  1440. $datacontpervalu = implode(",",$datacontpervalu);
  1441. $conversionPerkeys = array_keys($conversionpercentage);
  1442. $conversionPervalue = array_values($conversionpercentage);
  1443. $conversionnetres = array();
  1444. for($r=0;$r<count($datacontper);$r++){
  1445. if($datacontper[$r] > 0){
  1446. $conversionnetres[$r] = ($datacontpertest[$r]/$datacontper[$r]).'%"';
  1447. } else {
  1448. $conversionnetres[$r] = "'0%'";
  1449. }
  1450. }
  1451. $conversionpercentagevalu = implode(",",$conversionnetres);
  1452. if($totalData > 0){
  1453. $dataconversionrationtotal = ($totalDatasales/$totalData);
  1454. } else {
  1455. $dataconversionrationtotal = 0;
  1456. }
  1457. //echo "insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Conatctable%','".@$contactperc."%',".@$contactpervalu.")"; die;
  1458. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('TotalData','".@$totalData."',".@$totalsourcewise.")");
  1459. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Sale','".@$totalDatasales."',".@$totalsourcewisesales.")");
  1460. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Conatctabledata','".@$totalDatacontactable."',".@$totalcontactable.")");
  1461. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Conatctable%','".@$contactperc."%',".@$contactpervalu.")");
  1462. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Datacontribution%','".@$Datacontributionprec."%',".@$datacontpervalu.")");
  1463. mysql_query("insert into ".$table."(`AgentName`,`Total`,".@$values.") values('Conversion%','".@$dataconversionrationtotal."%',".@$conversionpercentagevalu.")");
  1464. // $tableres ="create table IF NOT EXISTS ".$table." as select leadSourceCode,leadSourceTitle from leadSourceMaster";
  1465. //$esx = mysql_query($tableres) or die(mysql_error());
  1466. $this->actiondatamis_download($start);
  1467. }
  1468. public function actiondatamis_download($start){
  1469. ini_set('max_input_time', 300);
  1470. ini_set('max_execution_time', 300);
  1471. $date = date('d_M_Y').'_';
  1472. $host = '10.216.6.59'; // MYSQL database host adress
  1473. $db = 'lms'; // MYSQL database name
  1474. $user = 'root'; // Mysql Datbase user
  1475. $pass = '0kwp6aNR'; // Mysql Datbase password
  1476. $link=mysql_connect($host,$user,$pass);
  1477. mysql_select_db($db,$link);
  1478. $table='report_datamis';
  1479. $filename = "filesystem/".$date.$table.'.csv';
  1480. $csv_terminated = "\n";
  1481. $csv_separator = ",";
  1482. $csv_enclosed = '"';
  1483. $csv_escaped = "\\";
  1484. $time = time();
  1485. mysql_query("insert into report_info (id,type,filename,createdOn,createdBy,updatedOn,updatedBy) values('','datadumpmis','".@$filename."','".@$time."','".@$_SESSION['id']."','".@$time."','".@$_SESSION['id']."')");
  1486. $sql_query = "select * from ".$table."";
  1487. // Gets the data from the database
  1488. $result = mysql_query($sql_query);
  1489. $fields_cnt = mysql_num_fields($result);
  1490. $schema_insert = '';
  1491. for ($i = 0; $i < $fields_cnt; $i++)
  1492. {
  1493. $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
  1494. stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;
  1495. $schema_insert .= $l;
  1496. $schema_insert .= $csv_separator;
  1497. } // end for
  1498. $out = trim(substr($schema_insert, 0, -1));
  1499. $out .= $csv_terminated;
  1500. // Format the data
  1501. while ($row = mysql_fetch_array($result))
  1502. {
  1503. $schema_insert = '';
  1504. for ($j = 0; $j < $fields_cnt; $j++)
  1505. {
  1506. if ($row[$j] == '0' || $row[$j] != '')
  1507. {
  1508. if ($csv_enclosed == '')
  1509. {
  1510. $schema_insert .= $row[$j];
  1511. } else
  1512. {
  1513. $schema_insert .= $csv_enclosed .
  1514. str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
  1515. }
  1516. } else
  1517. {
  1518. $schema_insert .= '';
  1519. }
  1520. if ($j < $fields_cnt - 1)
  1521. {
  1522. $schema_insert .= $csv_separator;
  1523. }
  1524. } // end for
  1525. $out .= $schema_insert;
  1526. $out .= $csv_terminated;
  1527. } // end while
  1528. $fd = fopen($filename, "w");
  1529. fputs($fd, $out);
  1530. fclose($fd);
  1531. echo "success";
  1532. //header("Content-type: text/csv");
  1533. //header("Content-type: application/csv");
  1534. //echo $out;
  1535. exit;
  1536. }
  1537. public function actiondownloadallreports(){
  1538. $this->render('downloadallreports');
  1539. }
  1540. }
  1541. ?>