$(document).ready(function() {
            $('.main-spinner').show();
              var index = $('#datatable_payment_client_report').DataTable({
                "lengthMenu": [[20, 25, 50, 100, 500], [20, 25, 50, 100, 500]],
                ordering:  false,
                serverSide: true,
                ajax: "/realty/get-report-receivable-note-branch",
                  columns: [
                    {data: 'DT_RowIndex'},
                    {data: 'client_name'},
                    {data: 'project_name'},
                    {data: 'category_name'},
                    {data: 'item_code'},
                    {data: 'sale_amount'},
                    {data: 'sale_discount'},
                    {data: 'sale_price'},
                    {data: 'sale_recieve'},
                    {data: 'amount_due'}

                  ],
                
                "initComplete": function(settings, json) {
                    $('.main-spinner').hide();
                },

                "footerCallback": function ( row, data, start, end, display ) {
                  var api = this.api(), data;
       
                  // converting to interger to find total
                  var intVal = function ( i ) {
                      return typeof i === 'string' ?
                          i.replace(/[\$,]/g, '')*1 :
                          typeof i === 'number' ?
                              i : 0;
                  };
       
                  var sale_price = api
                      .column( 5 )
                      .data()
                      .reduce( function (a, b) {
                          return intVal(a) + intVal(b);
                      }, 0 );

                  var sale_discount = api
                      .column( 6 )
                      .data()
                      .reduce( function (a, b) {
                          return intVal(a) + intVal(b);
                      }, 0 );

                  var selling_price = api
                      .column( 7 )
                      .data()
                      .reduce( function (a, b) {
                          return intVal(a) + intVal(b);
                      }, 0 );

                  var payment_recieve = api
                      .column( 8 )
                      .data()
                      .reduce( function (a, b) {
                          return intVal(a) + intVal(b);
                      }, 0 );

                  var payment_due = api
                      .column( 9 )
                      .data()
                      .reduce( function (a, b) {
                          return intVal(a) + intVal(b);
                      }, 0 );
              
                  var numFormat = $.fn.dataTable.render.number( '\,', '.', 2, '$ ' ).display;
                  $( api.column( 5 ).footer() ).html(numFormat(sale_price));
                  $( api.column( 6 ).footer() ).html(numFormat(sale_discount));
                  $( api.column( 7 ).footer() ).html(numFormat(selling_price));
                  $( api.column( 8 ).footer() ).html(numFormat(payment_recieve));
                  $( api.column( 9 ).footer() ).html(numFormat(payment_due));
                },   
          });
          index.on( 'order.dt search.dt', function () {
            index.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
              cell.innerHTML = i+1 ;
            } );
          } ).draw();
          $.fn.dataTable.ext.errMode = 'throw';
        });