<script>
$('body').on('click', '#btn_print_client_receipt', function() {
  var no = $(this).closest('tr').children('td');
  var receipt_id = no.eq(1).text();
  window.open('<?php echo base_url() . 'client_payments/print_receipt/' ?>' + receipt_id, 'newwindow', 'width=1200,height=700');
  return false
});
<?php if ($page_name == 'client_payments' || $page_name == 'invoices_payments' || $page_name == 'data_entry_approval') { ?>
  // Only for Client Payment View PAge
  $("#table_filter_work").select2({
    placeholder: "Select  Work",
    templateResult: format_project_dropdown
  })
  $("#table_filter_clients").select2({
    placeholder: "Select  Client"
  })

  $("#client_payment_work_add").select2({
    placeholder: "Select Work",
    dropdownParent: $("#form_client_payment_add"),
    templateResult: format_project_dropdown
  })

  $("#client_payment_work_edit").select2({
    placeholder: "Select Work",
    dropdownParent: $("#form_client_payment_edit"),
    templateResult: format_project_dropdown
  })


  $('#client_payment_invoice_add').on("change", function(e) {
    invoice_id_change('add');
  });

  $('#client_payment_invoice_edit').on("change", function(e) {
    invoice_id_change('edit');
  });



  $('body').on('change', '#client_payment_work_add,input[type=radio][name=payment_type_add]', function() {
    var work_id = $('#client_payment_work_add :selected').val();
    var payment_type = $("input[type=radio][name=payment_type_add]:checked").val();
    $("#reference_id_add_client_payment").val(work_id);
    $("#reference_type_add_client_payment").val('project');
    $.post("<?php echo base_url() ?>work/select_details", {
      work_id: work_id
    }, function(data) {
      var obj = $.parseJSON(data);
      var i = 0;
      if (obj.count == 1 && payment_type=='advance') {
        $("#client_payment_client_name_add").val(obj.data['client_name']);
        $("#client_payment_client_id_add").val(obj.data['client_id']);
      }
    })
  })


  $('body').on('change', '#client_payment_work_edit,input[type=radio][name=payment_type_edit]', function() {
    var work_id = $('#client_payment_work_edit :selected').val();
    var payment_type = $("input[type=radio][name=payment_type_edit]:checked").val();
    $("#reference_id_edit_client_payment").val(work_id);
    $("#reference_type_edit_client_payment").val('project');
    $.post("<?php echo base_url() ?>work/select_details", {
      work_id: work_id
    }, function(data) {
      var obj = $.parseJSON(data);
      var i = 0;
      if (obj.count == 1 && payment_type=='advance') {
        $("#client_payment_client_name_edit").val(obj.data['client_name']);
        $("#client_payment_client_id_edit").val(obj.data['client_id']);
      }
    })
  })
  <?php } ?>

  function invoice_id_change(type) {
    var invoice_id = $('#client_payment_invoice_' + type + ' :selected').val();
    if (invoice_id > 0) {
      $.post("<?php echo base_url() ?>invoices/select_invoices/payment", {
        invoice_id: invoice_id
      }, function(data) {
        var obj = $.parseJSON(data);
        var balance = obj[0].balance;
        var work_name = obj[0].work_name;
        var client_name = obj[0].client_name;
        var work_id = obj[0].work_id;
        // $('#client_payment_received_amount_'+type).attr('max',balance);
        $('#invoice_work_name_' + type).val(work_name);
        $('#client_payment_client_name_' + type).val(client_name);
        $('#reference_id_' + type + '_client_payment').val(work_id);
        $('#client_payment_work_' + type).val(work_id).trigger('change');

      })
    } else {
      $('#client_payment_received_amount_' + type).removeAttr('max');
      $('#invoice_work_name' + type).val('');
      <?php if ($page_name != 'work_profile' && $page_name != 'projects_profile') { ?>
        $('#client_payment_client_name_' + type).val('');
        $('#reference_id_' + type + '_client_payment').val('');
        <?php } ?>
      }
    }
    <?php if ($page_name == 'work_profile' || $page_name == 'projects_profile') { ?>
      $("#invoice_work_div_add").hide();
      $("#invoice_work_div_edit").hide();
      <?php } ?>
      $("#client_payment_tax_percent_add").select2({
        placeholder: "Select Tax %",
        dropdownParent: $("#form_client_payment_add")
      })

      $("#client_payment_tax_percent_edit").select2({
        placeholder: "Select Tax %",
        dropdownParent: $("#form_client_payment_edit")
      })

      $('body').on('change keyup', '.form_client_tax_amount_add_fields', function() {
        calculate_client_payment_tax_amount_add('add');
      })

      $('body').on('change keyup', '.form_client_tax_amount_edit_fields', function() {
        calculate_client_payment_tax_amount_add('edit');
      })

      function calculate_client_payment_tax_amount_add(form_type = '') {
        if (form_type == 'add') {
          var payment_type = $("input[type=radio][name=payment_type_add]:checked").val();
        } else {
          var payment_type = $("input[type=radio][name=payment_type_edit]:checked").val();
        }
        var client_payment_invoice = "<?= $this->config->item('Client_Payment_client_payment_invoice') ?>";
        if (payment_type == 'advance' || client_payment_invoice == '0') {
          if (form_type == 'add') {
            var tax_inclusive = $("input[type=radio][name=tax_inclusive_add]:checked").val();
            var tax_percent = parseFloat($('#client_payment_tax_percent_add :selected').val());
            if (tax_inclusive == 1) {
              var received_amount = parseFloat($('#client_payment_received_amount_add').val());
              if (received_amount == '' || received_amount == null || isNaN(received_amount)) {
                received_amount = 0;
              }
              var taxable_amount = received_amount * 100 / (tax_percent + 100);
              var tax_amount = received_amount - taxable_amount;
              $("#client_payment_tax_amount_add").val(tax_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2') ?>));
              $("#client_payment_taxable_amount_add").val(taxable_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2') ?>));

            } else {

              var tax_payable = parseFloat(($("#client_payment_taxable_amount_add").val() == '') ? 0 : parseFloat($("#client_payment_taxable_amount_add").val()));
              var tax_amount = tax_payable * tax_percent / 100;
              $("#client_payment_tax_amount_add").val(tax_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2') ?>));
              var received_amount = tax_payable + tax_amount;
              $("#client_payment_received_amount_add").val(received_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2') ?>));
            }
          } else {
            var tax_inclusive = $("input[type=radio][name=tax_inclusive_edit]:checked").val();
            var tax_percent = parseFloat($('#client_payment_tax_percent_edit :selected').val());
            if (tax_inclusive == 1) {
              var received_amount = parseFloat($('#client_payment_received_amount_edit').val());
              if (received_amount == '' || received_amount == null || isNaN(received_amount)) {
                received_amount = 0;
              }
              var taxable_amount = received_amount * 100 / (tax_percent + 100);
              var tax_amount = received_amount - taxable_amount;
              $("#client_payment_tax_amount_edit").val(tax_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2') ?>));
              $("#client_payment_taxable_amount_edit").val(taxable_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2') ?>));
            } else {
              var tax_payable = parseFloat(($("#client_payment_taxable_amount_edit").val() == '') ? 0 : parseFloat($("#client_payment_taxable_amount_edit").val()));
              var tax_amount = tax_payable * tax_percent / 100;
              $("#client_payment_tax_amount_edit").val(tax_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2') ?>));
              var received_amount = tax_payable + tax_amount;
              $("#client_payment_received_amount_edit").val(received_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2') ?>));
            }
          }
        }
      }


      $("#client_payment_acc_add").select2({
        placeholder: "Select Credit Account",
        dropdownParent: $("#form_client_payment_add")
      })
      $("#client_payment_invoice_edit").select2({
        placeholder: "Select  Invoice"
      });
      $("#client_payment_acc_edit").select2({
        placeholder: "Select Credit Account",
        dropdownParent: $("#form_client_payment_edit")
      })

      $("#client_payment_received_date_add,#client_payment_received_date_edit").datepicker({
        todayHighlight: !0,
        orientation: "bottom left",
        templates: {
          leftArrow: '<i class="la la-angle-left"></i>',
          rightArrow: '<i class="la la-angle-right"></i>'
        },
        endDate: '+0d',
        <?php if ($this->session->userdata('user_role') != 'admin' && $this->config->item('User_calendar_date_restriction_enabled') == 1) { ?>
          startDate: '<?php echo $this->config->item('User_calendar_date_restriction_start_days'); ?>d'
          <?php } ?>
        })


        $('body').on('click', '#send_email_btn', function() {
          var no = $(this).closest('tr').children('td');
          $('#transaction_id_send_receipt').val(no.eq(1).text());
          $('#client_id_send_receipt').val(no.eq(22).text());
          $('#client_name_send_receipt').val(no.eq(5).text());
          $('#email_send_receipt').val(no.eq(24).text());
        })
        $('body').on('click', '#send_whatsapp_btn', function() {
          var no = $(this).closest('tr').children('td');
          $('#transaction_id_send_receipt_whatsapp').val(no.eq(1).text());
          $('#client_id_send_receipt_whatsapp').val(no.eq(22).text());
          $('#client_name_send_receipt_whatsapp').val(no.eq(5).text());
          var mobile_no = no.eq(27).text();
          if (mobile_no.indexOf('+') == -1) {
            if (mobile_no.replace(/ /g, '').length == 10) {
              mobile_no = "+91" + mobile_no;
            } else {
              if (mobile_no[0] == '0' && mobile_no[1] == '0') {
                mobile_no = mobile_no.substring(2);
              } else if (mobile_no[0] == '0') {
                mobile_no = mobile_no.substring(1);
              }
              mobile_no = "+" + mobile_no;
            }
          }
          $('#whatsapp_no_send_receipt').val(mobile_no);
        })

        $('input[type=radio][name=tax_inclusive_add]').change(function() {
          var tax_inclusive = $("input[type=radio][name=tax_inclusive_add]:checked").val();
          if (tax_inclusive == 1) {
            $("#client_payment_received_amount_add").removeAttr('readonly', true);
            $("#client_payment_taxable_amount_add").attr('readonly', true);
          } else {
            $("#client_payment_taxable_amount_add").removeAttr('readonly', true);
            $("#client_payment_received_amount_add").attr('readonly', true);
          }
        });

        $('input[type=radio][name=tax_inclusive_edit]').change(function() {
          var tax_inclusive = $("input[type=radio][name=tax_inclusive_edit]:checked").val();
          if (tax_inclusive == 1) {
            $("#client_payment_received_amount_edit").removeAttr('readonly', true);
            $("#client_payment_taxable_amount_edit").attr('readonly', true);
          } else {
            $("#client_payment_taxable_amount_edit").removeAttr('readonly', true);
            $("#client_payment_received_amount_edit").attr('readonly', true);
          }
        });

        function payment_type_change(type) {
          var payment_type = $("input[type=radio][name=payment_type_" + type + "]:checked").val();
          if (payment_type == 'invoice') {
            <?php if ($page_name != 'work_profile' && $page_name != 'projects_profile') { ?>
              $('#invoice_work_div_' + type).show();
              <?php } ?>
              $('#client_payment_invoice_div_' + type).show();
              $('#tax_details_' + type + '_row,#work_id_div_' + type).hide();
              $("#client_payment_invoice_" + type).attr('required', true);
              $('#client_payment_work_' + type + ',.form_client_tax_amount_' + type + '_fields').removeAttr('required');
              $('#client_payment_received_amount_' + type).removeAttr('readonly', 'readonly')
            } else {
              $('#client_payment_invoice_div_' + type + ',#invoice_work_div_' + type).hide();
              $('#tax_details_' + type + '_row,#work_id_div_' + type).show();
              $('#client_payment_work_' + type + ',.form_client_tax_amount_' + type + '_fields').attr('required');
              $("#client_payment_invoice_" + type).removeAttr('required', true);
              $('#client_payment_received_amount_' + type).attr('readonly', 'readonly')
            }
          }

          $('input[type=radio][name=payment_type_add]').change(function() {
            payment_type_change('add');
            invoice_id_change('add');
          });

          $('input[type=radio][name=payment_type_edit]').change(function() {
            payment_type_change('edit');
            invoice_id_change('edit');
          });

          payment_type_change('add');

          $("#client_payment_invoice_add").select2({
            placeholder: "Select  Invoice",
            dropdownParent: $("#form_client_payment_add")
          });

          $('body').on('click', '#client_payment_edit_btn', function() {
            var no = $(this).closest('tr').children('td');
            var invoice_id = no.eq(26).text();

            if (invoice_id > 0) {
              $('input[type=radio][name=payment_type_edit][value=invoice]').prop('checked', true);
              $('#invoice_div').show();
              $('#work_name_div,#client_name_div').removeClass('col-lg-6').addClass('col-lg-4');
              $('#client_payment_invoice_edit').val(invoice_id).trigger('change');
              $('#tax_details_add_row').hide();
              $('#client_payment_client_name_edit').val(no.eq(5).text());
            } else {
              $('input[type=radio][name=payment_type_edit][value=advance]').prop('checked', true);
              $('#invoice_div').hide();
              $('#tax_details_add_row').show();
              $('#client_payment_taxable_amount_edit').val(no.eq(7).text());
              $("#client_payment_tax_percent_edit").val(no.eq(8).text().slice(0, -1)).trigger('change');
              $('#client_payment_tax_amount_edit').val(no.eq(9).text());
              $('#work_name_div,#client_name_div').removeClass('col-lg-4').addClass('col-lg-6');
            }
            payment_type_change('edit');
            $('#client_payment_tr_id_edit').val(no.eq(1).text());
            $("#client_payment_work_edit").val(no.eq(21).text()).trigger('change');
            $('#client_payment_received_amount_edit').val(no.eq(10).text());
            $("#client_payment_received_date_edit").datepicker("setDate", no.eq(4).text());
            $("#client_payment_acc_edit").val(no.eq(23).text()).trigger('change');
            $('#client_payment_remarks_edit').val(no.eq(13).text());
            $('#client_payment_client_id_edit').val(no.eq(22).text());

            $('#client_payment_receipt_no_edit').val(no.eq(12).text());
            $("#client_payment_received_from_edit").val(no.eq(14).text());
            $("#reference_id_edit_client_payment").val(no.eq(17).text());

            $("#reference_type_edit_client_payment").val('project');
            var tax_inclusive = no.eq(25).text();
            $("input[name=tax_inclusive_edit][value='" + tax_inclusive + "']").attr('checked', true);
            if (tax_inclusive == 1) {
              $("#client_payment_received_amount_edit").removeAttr('readonly', true);
              $("#client_payment_taxable_amount_edit").attr('readonly', true);
            } else {
              $("#client_payment_taxable_amount_edit").removeAttr('readonly', true);
              $("#client_payment_received_amount_edit").attr('readonly', true);
            }
            var attachment = no.eq(29).text();
            if(attachment!=''){
              $("#view_attachment_client_payment_edit").html('<a href="<?php echo base_url()?>uploads/transaction/'+attachment+'">Click to View</a>');
            }
          })
          <?php if ($page_name == 'work_summary') { ?>
            function GetStartDate() {
              return $('#table_filter_start_date').val();
            }
            function GetEndDate() {
              return $('#table_filter_end_date').val();
            }
            <?php } ?>
            <?php if ($page_name == 'data_entry_approval') { ?>

              function GetStartDate() {
                return $('#table_filter_start_date').val();
              }

              function GetEndDate() {
                return $('#table_filter_end_date').val();
              }

              function GetSearchWork() {
                return $('#table_filter_work').val();
              }

              function GetSearchUser() {
                return $('#table_filter_user').val();
              }
              function GetSearchAccount() {
                return $('#table_filter_account').val();
              }
              function GetSearchApprovalStatus() {
                return $('#table_filter_approval_status').val();
              }
              <?php } ?>
              <?php
              $page_type = '';
              if ($page_name == 'data_entry_approval') {
                $page_type = 'approval_entries';
              }
              ?>
              <?php if ($page_name == 'client_payments' || $page_name == 'work_summary') { ?>

                function GetSearchClient() {
                  return $('#table_filter_clients').val();
                }

                function GetSearchDate() {
                  return $('#table_filter_date_range').val();
                }

                function GetSearchWork() {
                  return $('#table_filter_work').val();
                }

                function get_branch_id() {
                  return $('#company_branch :selected').val();
                }
                <?php } ?>
                var client_payments_view_table = $('#client_payments_view_table').DataTable({
                  "ajax": {
                    url: "<?php echo base_url() . 'client_payments/select_client_payments/' . $page_type ?>", // json datasource
                    type: "post", // type of method  , by default would be get
                    data: function(d) {
                      <?php if ($page_name == 'client_payments') { ?>
                        d.date = GetSearchDate();
                        d.clients = GetSearchClient();
                        d.work = GetSearchWork();
                        <?php if (!empty($this->config->item('company_branches'))) { ?>
                          d.branch_id = get_branch_id();
                          <?php } ?>
                          <?php } elseif ($page_name == 'work_profile' || $page_name == 'projects_profile' || $page_name == 'work_summary') { ?>
                            d.work = "<?php echo $work_data->work_id ?>";
                            <?php } ?>
                            <?php if($page_name=='work_profile_master' || $page_name=='work_summary_master'){?>
                              d.work_ids = "<?php echo implode(',',$sub_project_ids)?>";
                              <?php } ?>
                            <?php if ($page_name == 'work_summary') { ?>
                              d.start_date = GetStartDate();
                              d.end_date = GetEndDate();
                              <?php } ?>
                              <?php if ($page_name == 'reports_activity') { ?>
                                d.date = GetSearchDate();
                                d.work = GetSearchWork();
                                <?php } ?>
                                <?php if ($page_name == 'user_profile') { ?>
                                  d.acc_user_id = "<?php echo $user_data->user_id ?>";
                                  <?php } ?>
                                  <?php if ($page_name == 'stage_profile' || $page_name == 'stage_summary' || $page_name == 'stage_summary') { ?>
                                    d.stage_id = "<?php echo $stage_data->stage_id ?>";
                                    <?php } ?>
                                    <?php if ($page_name == 'data_entry_approval') { ?>
                                      d.start_date = GetStartDate();
                                      d.end_date = GetEndDate();
                                      d.work = GetSearchWork();
                                      d.approval_status = GetSearchApprovalStatus();
                                      d.created_by = GetSearchUser();
                                      d.acc_head_id = GetSearchAccount();
                                      <?php } ?>
                                    }
                                  },
                                  "bProcessing": true,
                                  "deferRender": true,
                                  "bDeferRender": true,
                                  <?php if ($page_name == 'work_summary') { ?> "scrollX": false,
                                  bFilter: false,
                                  "bLengthChange": false,
                                  "bPaginate": false,
                                  "bInfo": false,
                                  buttons: [{
                                    extend: 'colvis',
                                    className: 'btn dark btn-outline',
                                    text: 'Columns'
                                  }],
                                  "dom": "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable
                                  <?php } else { ?> "scrollX": true,
                                  buttons: [{
                                    extend: 'print',
                                    className: 'btn dark btn-outline',
                                    exportOptions: {
                                      columns: ':visible'
                                    },
                                    title: 'List of Client Payments',
                                    <?php if($this->config->item('company_letter_head')!=''){ ?>
                                      customize: function ( win ) {
                                        $(win.document.body).prepend(
                                          '<img src="<?php echo base_url().'uploads/company/'.$this->config->item('company_letter_head')?>" style="top:0; left:0;width:100%;" />'
                                        );
                                      }
                                      <?php } ?>
                                    },
                                    {
                                      extend: 'csv',
                                      className: 'btn purple btn-outline '
                                    },
                                    {
                                      extend: 'colvis',
                                      className: 'btn dark btn-outline',
                                      text: 'Columns'
                                    }
                                  ],
                                  dom: "<'row'<'col-sm-6 text-left'B><'col-sm-6 text-right'f>>\n\t\t\t<'row'<'col-sm-12'tr>>\n\t\t\t<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 dataTables_pager'lp>>", // horizobtal scrollable datatable
                                  "lengthMenu": [
                                    [25, 50, 100, -1],
                                    [25, 50, 100, "All"] // change per page values here
                                  ],
                                  <?php } ?> 'order': false,
                                  "columnDefs": [{
                                    "targets": [1, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,29 <?php if ($page_name == 'work_profile' || $page_name == 'projects_profile') {
                                      echo ",5,6";
                                    } ?><?php if ($page_name == 'work_summary') {
                                      echo ",2,5,6,13,16,18";
                                    } ?><?php if ($page_name == 'reports_activity') {
                                      echo ",18";
                                    } ?><?php if ($this->config->item('Client_Payment_client_payment_invoice') == 0) {
                                      echo ',3';
                                    } ?><?php if ($this->session->userdata('user_role') == 'auditor') {
                                      echo ",18";
                                    } ?>],

                                    className: "hidden"
                                  }],
                                  "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                                    if (aData[28] == '0') {
                                      $('td', nRow).css('background-color', '#ffcccc');
                                    } else if (aData[28] == '2') {
                                      $('td', nRow).css('background-color', '#ffcccc');
                                    }
                                  }
                                });
                                $(".table_filter").on("change", function() {
                                  client_payments_view_table.ajax.reload();
                                });
                                $(".hide_column").hide();

                                <?php if ($page_name == 'client_payments') { ?>
                                  // Date Range Picker
                                  <?php if ($selected_start_date != '') { ?>
                                    var start = moment("<?php echo date('F d, Y', strtotime("01-" . $selected_start_date)) ?>");
                                    <?php } else { ?>
                                      var start = moment();
                                      <?php } ?>

                                      <?php if ($selected_end_date != '') { ?>
                                        var end = moment("<?php echo date('F t, Y', strtotime("01-" . $selected_end_date)) ?>");
                                        <?php } else { ?>
                                          var end = moment();
                                          <?php } ?>

                                          function cb(start, end) {
                                            $('#table_filter_date_range').val(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
                                            client_payments_view_table.ajax.reload();
                                          }

                                          $('#table_filter_date_range').daterangepicker({
                                            buttonClasses: "m-btn btn",
                                            applyClass: "btn-primary",
                                            cancelClass: "btn-secondary",
                                            startDate: start,
                                            endDate: end,
                                            locale: {
                                              format: 'MMMM D, YYYY'
                                            },
                                            ranges: {
                                              'Today': [moment(), moment()],
                                              'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                                              'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                                              'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                                              'This Month': [moment().startOf('month'), moment().endOf('month')],
                                              'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
                                              'All time': [moment('1970-01-01'), moment().add(9999, 'days')],
                                            }
                                          }, cb);

                                          cb(start, end);

                                          $(".form_submit_btn").click(function(e) {
                                            e.preventDefault();
                                            var a = $(this),
                                            l = $(this).closest("form"),
                                            action = l.attr('action');
                                            var form_id = l.attr('id');
                                            l.validate({
                                              rules: {
                                                received_amount: {
                                                  number: !0,
                                                  required: !0
                                                }
                                              },
                                              invalidHandler: function(e, r) {
                                                var i = $("#" + form_id + "_msg");
                                                i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
                                              },
                                              submitHandler: function(e) {}
                                            }), l.valid() && (a.addClass("m-loader m-loader--right m-loader--light").attr("disabled", !0),
                                            l.ajaxSubmit({
                                              url: action,
                                              beforeSend: function() {
                                                // Handle the beforeSend event
                                                // Block UI
                                                mApp.blockPage({
                                                  overlayColor: "#000000",
                                                  type: "loader",
                                                  state: "success",
                                                  message: "Please wait..."
                                                });

                                                mApp.block(".modal-content", {
                                                  overlayColor: "#000000",
                                                  type: "loader",
                                                  state: "success",
                                                  message: "Please wait..."
                                                });
                                              },

                                              success: function(e, t, r, s) {
                                                // UnBlock UI

                                                var modal_id = l.attr('data-modal-id');
                                                var form_type = l.attr('data-form-type');
                                                $("#" + form_id + "_msg").addClass("m--hide");


                                                var obj = $.parseJSON(e);
                                                if (obj.status == 1) {
                                                  a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                  $("#" + modal_id).modal('toggle');
                                                  $("." + form_id + "_fields").val('');
                                                  $("." + form_id + "_select").val('').trigger("change");
                                                  $(".custom-file-label").text('');

                                                  if (form_id != 'form_send_whatsapp') {
                                                    toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
                                                  } else {
                                                    window.open(window.atob(obj.url), '_blank');
                                                  }
                                                  client_payments_view_table.ajax.reload();
                                                } else {
                                                  a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                  toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
                                                }
                                                if (obj == null) {
                                                  setTimeout(function() {
                                                    a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                    toastr["warning"]("Your Attempt is Timed Out. Please Try Again.", "Timed Out");
                                                  }, 2e4)
                                                }
                                              },
                                              error: function() {
                                                a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                toastr["error"]("Sorry. There Has Been Some Error Occurred. Please Try Again.", "Error");
                                              },
                                              ajaxComplete: function() {
                                                mApp.unblockPage();
                                                mApp.unblock(".modal-content");
                                              },
                                              complete: function() {
                                                mApp.unblockPage();
                                                mApp.unblock(".modal-content");
                                              },
                                            })
                                          )
                                        });


                                        <?php } ?>
                                        </script>
