Dynamic report with dynamic dates (SLDS)

 


--------------------------- Visualforce page--------------------------------------

<apex:page controller="LeadNotesDispCtrl" id="myPage" contentType="{!renderAsExcel}" sidebar="false" showHeader="false" readOnly="true" >

 
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<link rel="stylesheet" href="/resources/demos/style.css"/>


 <style>
 
 .top-right {
    position: absolute;
    top: 22px;
    right: 16px;
}
.spinner {
  margin: 100px auto 0;
  width: 70px;
  text-align: center;
}

.spinner > div {
  width: 18px;
  height: 18px;
  background-color: #a81727;;
  z-index: 2;
  border-radius: 100%;
 display: inline-block;

  -webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
  animation: sk-bouncedelay 1.4s infinite ease-in-out both;
  overflow: auto;
 
  
  
}
.spinner .bounce1 {
  -webkit-animation-delay: -0.32s;
  animation-delay: -0.32s;
}

.spinner .bounce2 {
  -webkit-animation-delay: -0.16s;
  animation-delay: -0.16s;
}

@-webkit-keyframes sk-bouncedelay {
  0%, 80%, 100% { -webkit-transform: scale(0) }
  40% { -webkit-transform: scale(1.0) }
}

@keyframes sk-bouncedelay {
  0%, 80%, 100% { 
    -webkit-transform: scale(0);
    transform: scale(0);
  } 40% { 
    -webkit-transform: scale(1.0);
    transform: scale(1.0);
  }
}

 </style>
 <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">

 
 
 <head>
            <meta charset="utf-8" />
            <meta http-equiv="x-ua-compatible" content="ie=edge" />
            <meta name="viewport" content="width=device-width, initial-scale=1"/> 
            <apex:slds /> 
                  
            
 </head>
 
 
   <body class="slds-scope">  
        

<apex:form id="Form"> 
<script type="text/javascript">

var j$ = jQuery.noConflict();

 j$(function() {
    j$( ".datepicker" ).datepicker({ dateFormat: 'yy-mm-dd',maxDate: new Date() });
  });

function sendDateToCtrl(){

var j$ = jQuery.noConflict();

var date1 = j$("#date1").datepicker({ dateFormat: 'dd,MM,yyyy' }).val();
var date2 = j$("#date2").datepicker({ dateFormat: 'dd,MM,yyyy' }).val();


if (date1 == ''){

document.getElementById('date1err').style.visibility = 'visible';

}else if(date2 == ''){

  document.getElementById('date2err').style.visibility = 'visible';

}else{

submitActionFunction(date1,date2);
}

}

function hideErr1(){

document.getElementById('date1err').style.visibility = 'hidden';

}
function hideErr2(){

document.getElementById('date2err').style.visibility = 'hidden';

}
 </script>
 
 <apex:actionStatus id="mySaveStatus">  
 <apex:facet name="stop">
 <apex:actionFunction name="submitActionFunction" action="{!runReport}" reRender="pb" status="mySaveStatus">
            <apex:param name="date1" assignTo="{!dateVal1}" value="" />
            <apex:param name="date2" assignTo="{!dateVal2}" value="" />
            <apex:param name="QTy" id="QTy" assignTo="{!qryType}" value="" />
            
  </apex:actionFunction> 
  </apex:facet>
    
      <apex:facet name="start"> 
            <apex:outputPanel >
              <div style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; opacity: 0.75; z-index: 1000; background-color: grey;"> </div>
               <div class="spinner"  id ="spinner" style="position: fixed; left: 0; top: 0; bottom: 0; right: 0; z-index: 1001; margin: 22% 42%">
                  <div class="bounce1"></div>
                  <div class="bounce2"></div>
                  <div class="bounce3"></div>
                </div>
               
            </apex:outputPanel>
      
      </apex:facet>
  
   </apex:actionStatus>
   
 <apex:pageBlock >
   <h1 style="font-size: 25px; font-family:verdana;color: #b30000;text-align:center;font-weight:bold;"><u>Notes Report</u></h1><br/>
   <div class="container slds-text-align--center">
   <span style="color:#000066;font-size:15px;font-family:verdana;font-weight:bold;">Query Type </span> <apex:inputField id="QTy" value="{!ll.Query_Type__c}" />    
  
   <span style="color:#000066;font-size:15px;font-family:verdana;font-weight:bold;">Lead Record Type </span> <apex:inputField value="{!ll.recordtypeId}"/>
   <br/><br/>

   <span style="color:#000066;font-size:15px;font-family:verdana;font-weight:bold;">From:</span> <input id="date1" class="datepicker" onclick="hideErr1();"></input>      
   <span style="color:#000066;font-size:15px;font-family:verdana;font-weight:bold;">To:</span> <input id="date2" class="datepicker" onclick="hideErr2();"/>
    <br/>
    
     
    <span class="errorMsg" style="display:inline;visibility:hidden;" id="date1err"><strong>Error:</strong> You must enter a value</span>
    <span class="errorMsg" style="display:inline;margin-left:70px;visibility:hidden" id="date2err"><strong>Error:</strong> You must enter a value</span>
    </div>
      <br/>
   
  

<div class="slds-text-align--center">

 <button type="button" class="slds-button slds-button_brand" onclick="sendDateToCtrl();">Submit</button>   
<apex:commandButton value="Download" action="{!downloadReport}" styleClass="slds-button slds-button_brand" status="fetchStatusonApply"></apex:commandButton>

</div>  </apex:pageBlock> <br/>


<apex:pageBlock id="pb" >

 Total no.of records: <b>{!LeadNoteRecs.size}</b>
<table class="slds-table" id="tableId" style="table-layout:fixed;">

            <tr border="0" style="font-weight:bold;">
                <td class="header-table-heading" bgcolor="#C0C0C0" style="width: 100px;">LeadNumber</td>
                <td class="header-table-heading" bgcolor="#C0C0C0" style="width: 481px;">Note</td>
                <td class="header-table-heading" bgcolor="#C0C0C0" style="width: 100px;">Topic</td>
                <td class="header-table-heading" bgcolor="#C0C0C0" style="width: 100px;">NoteTitle</td>
                <td class="header-table-heading" bgcolor="#C0C0C0" style="width: 110px;">Created By</td>
                <td class="header-table-heading" bgcolor="#C0C0C0" style="width: 100px;">Create Date</td>

                
            </tr>

        <tbody>
            <apex:repeat value="{!LeadNoteRecs}" var="qli">
            <tr border="0">
                <td class="header-table-data">{!qli.LeadNumber}</td>
                <td class="header-table-data" style="overflow:hidden;text-overflow:ellipsis;">{!qli.noteBody}</td>
                <td class="header-table-data">{!qli.topic}</td>
                <td class="header-table-data">{!qli.notetitle}</td>
                <td class="header-table-data">{!qli.noteModby}</td>
                <td class="header-table-data">{!qli.noteCreateDate}</td>          
                

                
            </tr>
            </apex:repeat>
        </tbody>
    </table> 
    </apex:pageBlock>
  </apex:form>
 </body>
 </html>
 
</apex:page>


------------------------------ controller class-----------------------------------------------

public class LeadNotesDispCtrl {

    public String renderAsExcel {get;set;}    
    public string dateVal1 {get;set;}
    public string dateVal2 {get;set;}
    public list<note> listNote {get;set;}
    public map<id,string> leadMap;
    public list<id> leadIds;
    public Integer size {get;set;}
    public String noteListSoql;
    public Integer noOfRecords {get;set;}
    Public Lead ll {get;set;}
    public String recType {get;set;}
    public String qryType {get;set;}
    public List<SelectOption> options {get;set;}
    public map<id,string> leadMap1;
        public List<String> recTypeNames;
        
    public LeadNotesDispCtrl (){
    
   
     
     leadMap = new map<id,string>();
     leadIds = new list<id>();  
     leadMap1 = new map<id,string>();
    
    recType ='';
    qryType = '';
    options=new List<SelectOption> ();
    ll = new Lead();
     
            
     listNote = [SELECT LastModifiedBy.name,CreatedDate ,title,ParentId,body,Parent.RecordType.Name FROM Note where Parent.Type='Lead' and CreatedDate =Yesterday order by CreatedDate DESC];
        
     system.debug('listNote+++++++++'+ listNote); 
     
     for(Note n: listNote ){
         
         leadIds.add(n.ParentId);
                
      } 
         
      for(Lead l:[select id,Lead_ID__c,Topic__c  from Lead where id=:leadIds]){
      
                 leadMap.put(l.id,l.Lead_ID__c );
                leadMap1.put(l.id,l.Topic__c );
        } 
   
   } 
    
    public void runReport(){
    
       
        
    
        if(dateVal1 != '' && dateVal2 !='' ){
        
            leadMap = new map<id,string>();
            leadMap1 = new map<id,string>();
            
            List<String> dateParts = dateVal1.split('-');
            Datetime dateWithTime = (Datetime.newInstance(Integer.valueOf(dateParts[0]), Integer.valueOf(dateParts[1]), Integer.valueOf(dateParts[2]))).AddMinutes(120);
            
            
            
                      
            List<String> dateParts1 = dateVal2.split('-');
            Datetime dateWithTime1 = (Datetime.newInstance(Integer.valueOf(dateParts1[0]), Integer.valueOf(dateParts1[1]), Integer.valueOf(dateParts1[2]))).AddDays(1).AddMinutes(119);
            
            system.debug(dateWithTime1 +'kkkkk'+dateWithTime);
            
            listNote = [SELECT LastModifiedBy.name,CreatedDate,title,Parent.RecordType.Name,ParentId,body FROM Note where Parent.Type='Lead' and CreatedDate > :dateWithTime and CreatedDate <= :dateWithTime1 and Parent.RecordTypeid =:ll.recordtypeId order by CreatedDate DESC];
             
            for(Note n: listNote ){
            
            leadIds.add(n.ParentId);
            
            }   
            
            for(Lead l:[select id,Lead_ID__c,Query_Type__c,Topic__c,RecordType.Name from Lead where id IN :leadIds and Query_Type__c =:ll.Query_Type__c]){
            
            leadMap.put(l.id,l.Lead_ID__c );
            
            leadMap1.put(l.id,l.Topic__c );

            } 
        }
   }
    
  
    public list<LeadNoteValStr> getLeadNoteRecs(){
        
        list<LeadNoteValStr> leadNoteVar = new list<LeadNoteValStr>();        
        
        if(listNote.size()>0 ){
        
       
        
        for(note n:listNote){
        
        Datetime thisDT = n.CreatedDate; 
        DateTime newDateTime = thisDT.addHours(2);
        
        String myDate = newDateTime.format('yyyy-MM-dd HH:mm:ss', 'SAST');
        
        leadNoteVar.add(new LeadNoteValStr(leadMap.get(n.ParentId),n.LastModifiedBy.name,leadMap1.get(n.ParentId),n.title,myDate,n.body ));    
        
        }
        }
        
        return leadNoteVar;
     }
         
        
       public class LeadNoteValStr{
        
        public string LeadNumber { get; set; }  
        public string noteModby { get; set; }  
        public string noteCreateDate { get; set; } 
        public object noteBody { get; set; } 
        public string notetitle{ get; set; } 
        public string topic{ get; set;} 
        
        public LeadNoteValStr(string LeadNumber,string noteModby,string Topic,string notetitle,string noteCreateDate,object noteBody){
        
        this.LeadNumber = LeadNumber;
         
        this.noteModby = noteModby;
        this.topic= topic;
        this.notetitle= notetitle;
        this.noteCreateDate = noteCreateDate;
        this.noteBody  = noteBody ;

        
        }
            
            
        }  
        
    public void downloadReport (){
                renderAsExcel = 'application/vnd.ms-excel#NotesReportData.xls';
    }
        

   

}

-------------------------------Controller test class-------------------------------


@isTest
public class LeadNotesDispCtrlTest {
    
  static testMethod void testMethodLeadNotes(){
      
   RecordType recTypeAcc = [SELECT Id FROM RecordType WHERE Name =: 'Dealership' AND SObjectType =: 'Account'];
      Account acc1 = new Account();
      acc1.Name = 'Test Account11';
      acc1.Dealer_code__c = '123457';
      acc1.RecordTypeId = recTypeAcc.Id;
      acc1.Brand__c = 'Nissan';
      acc1.Date_Dealership_Established__c = System.Today();
      acc1.After_Sales_Zone__c = 'Central';
      acc1.District_Number__c = '123454';
      insert acc1;
      
      lead testLead = new lead ();
      testLead.FirstName = 'Test FirstName';
      testLead.LastName = 'Test LastName';
      testLead.Email = 'email@test.com';
      testLead.Topic__c='test';
      testLead.Preferred_Dealer_Account__c= acc1.id;
      testLead.MobilePhone = '+1234';
      insert testLead;  
        
        note n = new note();
        n.Title ='test';
        n.Body= 'testbody';
        n.ParentId = testLead.id;        
        insert n;
      Datetime DT=Datetime.now().addDays(-1);
      Test.setCreatedDate(n.id, DT);
      
      note n1 = new note();
        n1.Title ='test';
        n1.Body= 'testbody';
        n1.ParentId = testLead.id; 
        n1.CreatedDate=system.today()-1;
        insert n1;
      
         
        test.startTest(); 
        LeadNotesDispCtrl lnd = new LeadNotesDispCtrl();
       
        lnd.dateVal1 = (Datetime.now()-1).AddMinutes(120).format('yyyy-MM-dd');
        lnd.dateVal2 = Datetime.now().AddMinutes(119).format('yyyy-MM-dd');
        lnd.runReport();
        lnd.getLeadNoteRecs();
        lnd.downloadReport();
        string LeadNumber=testLead.id;
        string noteModby=n1.id;
      string Topic=testLead.Topic__c;
      string notetitle=n1.Title;
      string noteCreateDate='2018/11/16';
      object noteBody=n1.Body;
      //LeadNotesDispCtrl.
   //   LeadNotesDispCtrl.LeadNoteValStr(LeadNumber,noteModby,Topic,notetitle,noteCreateDate,noteBody);
        LeadNotesDispCtrl.LeadNoteValStr lndf=new LeadNotesDispCtrl.LeadNoteValStr(LeadNumber,noteModby,Topic,notetitle,noteCreateDate,noteBody); 
        test.stopTest();
        
    }

}




Comments