0

Visualforce Page:

<apex:page sidebar="false" Controller="Invoice_details" showHeader="False" docType="html-5.0" readOnly="true" >
    <html xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink">
  <head> 
      <body>
          <apex:slds />
      <style>


    .displayBlock {
        display:block;
    }

        .placeHolder {

          margin-left : 50 px;
          margin-top : 50 px;
          Width : 50rem;

    }
          .Showall {
          font-style: bold;

          margin-top : 120px;
          width : 100%;

          }

          .space {
          font-style: italic;
          font-size : 25px;
          margin-left : 50px;
          margin-top : 20px;
          }
          .slds-form-element__label slds-m-bottom_none{
          font-size : 2 rem;
          }

          .nishant{
          font.size : 1 rem;
          }

          input.date {
            cursor: pointer;
            font-size: 18px;
            margin: 12px;
            padding: 4px;
            width: auto; 
            text-align: center;
          }
         </style>

     <apex:form title="form" styleClass="Showall" forceSSL="true" id="A" >
         <div class="slds-form-element" >
             <div class="slds-p-left_xx-large">
         <label class="slds-checkbox_toggle slds-grid" >
         <span class="slds-form-element__label slds-m-bottom_none" style = "font-size:.90rem" > Show All </span>
         <input type="checkbox" name="checkbox-toggle-15" value="checkbox-toggle-15" aria-describedby="checkbox-toggle-15" checked=""  />
         <span id="checkbox-toggle-15" class="slds-checkbox_faux_container" aria-live="assertive" style="margin-left:15px" >
         <span class="slds-checkbox_faux"></span>
         <span class="slds-checkbox_on">Enabled</span>
         <span class="slds-checkbox_off">Disabled</span>
    </span>
  </label>
             </div>
</div>
       <div class="slds-grid slds-grid_align-space" >
            <div class="slds-p-top_xx-large" >
            <span >Date From
          <apex:inputfield value="{!InvoiceInfo.kognoz1__Invoice_Date__c}" label="Start Date"  id="datefrom" />
                </span>
            </div>
           <div class="slds-p-top_xx-large" >
               <span >Date To 
                <apex:inputfield value="{!InvoiceInfo.kognoz1__Invoice_Due_Date__c}"  label="End Date" />
            </span>
           </div>
           <div class="slds-p-top_xx-large" >
           <apex:commandButton value="Search" action="{!display}" reRender="B" />
           </div>
           </div>
         <div class="slds-p-top_xx-large">
             <apex:pageBlock >
                 <apex:pageBlockSection showHeader="false" id="B"  columns="1"   >
             <apex:pageblocktable value="{!InvoiceList}" var="rs" id="A" >
             <apex:column >
                 <apex:inputCheckbox value="{!rs.selected}" Id="c" onchange="window.batchDownload()">
                 <apex:actionSupport event="onclick" rerender="A,B"/>
                 </apex:inputCheckbox>
                 </apex:column>
                 <apex:column value="{!rs.KI.kognoz1__Invoice_Date__c}" headerValue="DATE"/>
            <apex:column value="{!rs.KI.kognoz1__Account__c}" headerValue="Account"/>
                <apex:column value="{!rs.KI.kognoz1__Opportunity__c}" headerValue="Opportunity"/>
                <apex:column headerValue="Files" >
               <apex:repeat value="{!rs.KI.attachments}" var="C" >
                    <apex:outputLink value="https://c.cs101.content.force.com/servlet/servlet.FileDownload?file={!C.Id}&operationContext=S1"  target="_blank"
                                   rel="nofollow" >{!C.name}</apex:outputLink> 
                    </apex:repeat>
               </apex:column>
               </apex:pageblocktable>
              </apex:pageBlockSection>
              </apex:pageBlock>
             <apex:panelGrid columns="4" cellspacing="1" cellpadding="1">
                 <apex:commandbutton value="Download" onclick="onSubmit()"  />
            <div class="slds-p-left_xx-large">
                 <apex:commandbutton value="Previous" action="{!previous}" disabled="{!DisablePrevious}" reRender="A,B"  />
            <apex:commandbutton value="Next" action="{!next}"  reRender="A,B" />
                </div>
                  <apex:actionStatus id="status" startText="Loading" />
          </apex:panelGrid>
         </div>
          </apex:form>
          <script type="text/javascript">
          <script src="{!$Resource.FileSaver2}">
              <script src="{!$Resource.jszip}">
                  <script src="{!$Resource.JsZipUtils}">
        window.batchDownload = (function () {
    "use strict";
    return {
        getCheckedValues: function () {
            const checkboxes = document.querySelectorAll('input[type=checkbox]:checked');
            let checkedValues = [];
            for (let i = 0, l = checkboxes.length; i < l; i++) {
                checkedValues.push(checkboxes[i].value);
            }
            return checkedValues;
        },

          onSubmit: function () {
            const zip = new JSZip();
            let promises = [];
            let checkedValues = this.getCheckedValues();
            for (let i = 0, l = checkedValues.length; i < l; i++) {
                const attachmentPath = checkedValues[i];
                // const attachmentFileName = checkedValues[i].replace(/^.*[\\\/]/, '');
                promises.push(new Promise((resolve, reject) => {
                    fetch(attachmentPath)
                        .then((response) => {
                            return response.blob();
                        })
                        .then((blob) => {
                            zip.file(i + '.pdf', blob);
                            resolve();
                        })
                        .catch((err) => reject(err));
                }));
            }
            Promise.all(promises).then(values => {
                zip.generateAsync({type: "blob"}).then(function (content) {
                    saveAs(content, "download.zip");
                });
            });
            return false;
        }
    };
}());
    </script>
       </body>
      <meta http-equiv="X-UA-Compatible" content="IE=8" />
        </head>
       </html>
</apex:page>

Apex Controller:

Public class  Invoice_details {
        public List<VoiceWrapper> InvoiceList {get;set;}
        public kognoz1__Invoice2__c InvoiceInfo { get;set;}
        public static Date StartDate {get;set;}
        public static Date EndDate {get;set;}
        public static string querystr;
        public integer counter = 0; 
        Public integer list_size=20;
        Public integer total_size ;
        static set<Id> ids = New set<Id>();





            Public Invoice_details() { 
                InvoiceInfo = new kognoz1__Invoice2__c();
                InvoiceList = New List<VoiceWrapper>();
                for(kognoz1__Invoice2__c k : [SELECT kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c ORDER BY kognoz1__Invoice_Date__c  DESC limit: List_size])
                {
                    InvoiceList.add(new VoiceWrapper(K));
                }


               } 

            Public void display() {
                InvoiceList.clear();
                Date startDate = InvoiceInfo.kognoz1__Invoice_Date__c;
                Date endDate = InvoiceInfo.kognoz1__Invoice_Due_Date__c;
                if(InvoiceInfo.kognoz1__Invoice_Date__c != null ) {
            //string Query = 'SELECT kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__c,(select id, name from Attachments) FROM kognoz1__Invoice2__c WHERE kognoz1__Invoice_Date__c = '+startDate+' AND kognoz1__Invoice_Date__c= '+EndDate+' ';
            InvoiceList = New List<VoiceWrapper>();
                for(kognoz1__Invoice2__c k : [SELECT kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c WHERE kognoz1__Invoice_Date__c >=: startDate AND kognoz1__Invoice_Date__c <=: EndDate ORDER BY kognoz1__Invoice_Date__c  DESC  limit: list_size offset: counter ])
                {
                    InvoiceList.add(new VoiceWrapper(K));
                 }
                 }
               }


        Public class VoiceWrapper{
        Public kognoz1__Invoice2__c KI {get;set;}
        Public boolean selected {get;set;}
        Public VoiceWrapper (kognoz1__Invoice2__c K) {
            KI = k;
            selected = false;
            system.debug(KI);
        }
    }
 public Pagereference Previous() { 
         /*
           InvoiceList = New List<VoiceWrapper>();
                for(kognoz1__Invoice2__c k : [SELECT kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__c, kognoz1__Invoice2_Number__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c ORDER BY kognoz1__Invoice_Date__c  DESC limit : list_size offset : counter])
                {
                    InvoiceList.add(new voicewrapper(K));
                }
*/
           counter = counter-list_size;
           display();
           return null;
          }

       public pagereference Next() {
            /*
           InvoiceList = New List<VoiceWrapper>();
                for(kognoz1__Invoice2__c k : [SELECT kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__c, kognoz1__Invoice2_Number__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c ORDER BY kognoz1__Invoice_Date__c  DESC limit : list_size offset : counter])
                {
                    InvoiceList.add(new voicewrapper(K));
                }
*/
           counter = counter + list_size;
           display();
           system.debug( InvoiceList);
           return null;
          }


      Public boolean getDisablePrevious() { 
            if (counter<=0) {
           return True;
         }
           else return false;
         }

       Public Boolean getDisableNext() {
          if (counter>=99*list_size) { 
           return false;
           }
           else return true;
        }

Issue i am facing, i have mentioned in given points and I would like to thank you for your precious time and concern in it in Advance.
1. I have a constructor and display() method which retrieves the record between two dates, i want to apply pagination on both but i don't know how can i achieve it.
2. i have mentioned two JS method in visualforce for downloading the invoice but it is not downloading it.
3. I am not able to get total_size of list, kindly refer my code first.

1 Answer 1

1
  1. I have a constructor and display() method which retrieves the record between two dates, i want to apply pagination on both but i don't know how can i achieve it.

Your current pagination implementation is probably throwing an exception because total_size is null.

  1. i have mentioned two JS method in visualforce for downloading the invoice but it is not downloading it.

I would suggest you break this out into a separate question and include detailed information about the debugging you have done so far.

  1. I am not able to get total_size of list, kindly refer my code first.

Your code never sets the variable total_size. You should probably turn it into a getter, i.e.,

public Integer total_size {
    get {
        return (InvoiceList != null ? InvoiceList.size() : 0);
    }
    private set;
}

Overall, the extremely messy formatting and style of your code makes it very difficult to follow. Please consider using a formatter like Prettier or manually applying consistent, best-practice indentation and brace style so that others can read your code.

It also helps find answers if you do the legwork of debugging. We cannot run your code locally. Since we can't, we need you to provide

  1. Detailed descriptions of behavior. Not just "it doesn't work".
  2. Limited code - just what is relevant to the problem. We don't need to see all the CSS in your page, or code that doesn't bear on the issue.
  3. Information from your logs about what the values of your variables are, any console logs output, or exceptions thrown, with messages and stack traces.
2
  • first of all thank you for your time and precious input on point 1. > I have one constructor which initializes the page and second one is display() method which retrieves the records between two dates on the basis of input of user. so I want to apply pagination on both, it should work with both when it initializes and when user gives input on dates then pagination on display method as well
    – Nishant
    Nov 15, 2019 at 10:21
  • @Nishant I am aware of this but I'm not sure what you are asking. You have at least one bug in your code, as described above.
    – David Reed
    Nov 15, 2019 at 23:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .