// $('#customers-table tbody').on('click', 'td.details-control', function () {
    $(document).on('click', 'td.details-control', function() {  
        // alert();
        var tr = $(this).closest('tr');
        var row = table.row(tr);
        var tableId = 'purchases-' + row.data().id;
        var client_id = row.data().id;

        if (row.child.isShown()) {
          // This row is already open - close it
          row.child.hide();
          tr.removeClass('shown');
        } else {
          // Open this row
          row.child(template(row.data())).show();
          initTable(tableId, row.data(),client_id);
          console.log(row.data());
          tr.addClass('shown');
          tr.next().find('td').addClass('no-padding bg-gray');
        }

      });

      function initTable(tableId, data,client_id) {
        $('.main-spinner').show();
        var id = client_id;
        $.ajax({
            type: 'GET',
            url: '/realty/get-detail-client-deposit/'+id,
            dataType:'json',
            data: {'id': id},
            success: function (data){
              console.log(data);
              $('.project').html(data[0].project_name);
              $('.item-code').html(data[0].item_name);
              $('.category').html(data[0].category_name);
              $('.price').html("$ "+data[0].loan_amount);
              $('.deposit').html("$ "+data[0].sale_receive);
              $('.discount').html("$ "+data[0].loan_discount);
              //$('.remain-amount').html("$ "+parseFloat(data[0].loan_amount-parseFloat(data[0].sale_discount + data[0].sale_receive)));
              $('.paid').html("$ "+(data[0].loan_amount - data[0].loan_amountos));
              $('.balance').html("$ "+ data[0].loan_amountos);
            }
        });




        $('#' + tableId).DataTable({
          paging: false,
          searching: false,
          ordering: false,
          info:false,
          ajax: data.details_url,
          columns: [
            { data: 'loanprocess_no', name: 'loanprocess_no' },
            { data: 'loanprocess_datepayment', name: 'loanprocess_datepayment' },
            { data: 'loanprocess_principle', name: 'loanprocess_principle'},
            { data: 'loanprocess_interest', name: 'loanprocess_interest'},
            { data: 'loanprocess_owe', name: 'loanprocess_owe'},
            { data: 'loanprocess_principleos', name: 'loanprocess_principleos'},
            { data: 'status', name: 'status'},
          ],
          "initComplete": function(settings, json) {
						$('.main-spinner').hide();
					}	 
        });

      }