<style type="text/css">
  body .modal {
    /* new custom width */
    width: 750px;
    /* must be half of the width, minus scrollbar on the left (30px) */
    margin-left: -375px;
  }

  /* Multi-step form */
  .form-step {
    display: none;
  }

  .form-step-active {
    display: block;
  }
</style>



<style type="text/css">
  body .modal {
    width: 750px;
    margin-left: -375px;
  }
</style>

<style type="text/css">
  body .modal {
    width: 750px;
    margin-left: -375px;
  }

  .form-step {
    display: none;
  }

  .form-step.active {
    display: block;
  }
</style>

<style>
  .container {
    max-width: 1200px;
  }

  .card {
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    border-radius: 1rem;
    margin-bottom: 2rem;
  }

  .card-header {
    background: linear-gradient(45deg, #0d6efd, #0dcaf0);
    color: white;
    border-radius: 1rem 1rem 0 0 !important;
  }

  .form-section {
    background-color: #f0f8ff;
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    border-left: 4px solid #0d6efd;
  }

  .form-section h5 {
    color: #0d6efd;
    border-bottom: 1px solid #cce5ff;
    padding-bottom: 0.5rem;
  }

  .document-item {
    margin-bottom: 1.5rem;
    padding: 1.5rem;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    background: #fff;
    transition: all 0.3s ease;
  }

  .document-item:hover {
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
  }

  .document-item h6 {
    color: #495057;
    font-weight: 600;
  }

  .btn-primary {
    background: linear-gradient(45deg, #0d6efd, #0a58ca);
    border: none;
  }

  .btn-primary:hover {
    background: linear-gradient(45deg, #0a58ca, #0d6efd);
  }

  .progress {
    height: 1.5rem;
    border-radius: 0.75rem;
    margin: 1.5rem 0;
  }

  .step-indicator {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2rem;
  }

  .step {
    text-align: center;
    flex: 1;
    position: relative;
  }

  .step-number {
    width: 40px;
    height: 40px;
    background-color: #6c757d;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.5rem;
  }

  .step.active .step-number {
    background-color: #0d6efd;
    box-shadow: 0 0 0 5px rgba(13, 110, 253, 0.2);
  }

  .step.completed .step-number {
    background-color: #198754;
  }

  .step-line {
    position: absolute;
    top: 20px;
    left: 50%;
    right: -50%;
    height: 2px;
    background-color: #dee2e6;
    z-index: -1;
  }

  .step:last-child .step-line {
    display: none;
  }

  .upload-status {
    font-size: 0.9rem;
    margin-top: 0.5rem;
  }

  .required-field::after {
    content: " *";
    color: #dc3545;
  }

  #documentUploadSection {
    display: none;
  }

  .completion-message {
    background: linear-gradient(45deg, #198754, #20c997);
    color: white;
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    margin-top: 2rem;
  }

  h1 {
    margin-top: -2px
  }
</style>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

<div class="modal-header">
  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  <h4 class="modal-title">Customer Registration</h4>
</div>
<div class="modal-body">
  <div id="error"></div>
  <div class="row">
    <div style="padding: 0px;" class="container py-5">

      <div class="row justify-content-center">
        <div class="col-lg-12">
          <div style="margin-bottom:0px;" class="card">
            <div class="card-header text-center py-4">

            </div>
            <div class="card-body p-5">
              <!-- Step Indicator -->
              <div class="step-indicator">
                <div class="step active">
                  <div class="step-number">1</div>
                  <div class="step-title">Personal Info</div>
                  <div class="step-line"></div>
                </div>
                <div class="step">
                  <div class="step-number">2</div>
                  <div class="step-title">Business Information</div>
                  <div class="step-line"></div>
                </div>
                <div class="step">
                  <div class="step-number">3</div>
                  <div class="step-title">Documents</div>
                </div>
              </div>

              <!-- Main Form -->
              <form id="customerForm">
                <!-- Personal Information Section -->
                <div class="form-section">
                  <h5><i class="fas fa-user me-2"></i>Personal Information</h5>
                  <div class="row mt-3">
                    <div class="col-md-6 mb-3">
                      <label for="title" class="form-label">Title</label>
                      <select class="form-control" id="title" name="title">
                        <option value="">Select</option>
                        <option value="Mr">Mr</option>
                        <option value="Mrs">Mrs</option>
                        <option value="Miss">Miss</option>
                      </select>
                    </div>
                    <div class="col-md-6 mb-3">
                      <label for="full_name" class="form-label required-field">Full Name</label>
                      <input type="text" class="form-control" id="full_name" name="full_name" required>
                    </div>
                  </div>

                  <div class="row">
                    <div class="col-md-6 mb-3">
                      <label for="date_of_birth" class="form-label">Date of Birth</label>
                      <input type="date" class="form-control" id="date_of_birth" name="date_of_birth">
                    </div>
                    <div class="col-md-6 mb-3">
                      <label for="nic" class="form-label required-field">NIC</label>
                      <input type="text" class="form-control" id="nic" name="nic" required>
                    </div>
                  </div>

                  <div class="row">
                    <div class="col-md-6 mb-3">
                      <label for="nic_issue_date" class="form-label">NIC Issue Date</label>
                      <input type="date" class="form-control" id="nic_issue_date" name="nic_issue_date">
                    </div>
                    <div class="col-md-6 mb-3">
                      <label for="passport_number" class="form-label">Passport Number</label>
                      <input type="text" class="form-control" id="passport_number" name="passport_number">
                    </div>
                  </div>
                </div>

                <!-- Contact Information Section -->
                <div class="form-section">
                  <h5><i class="fas fa-phone me-2"></i>Contact Information</h5>
                  <div class="row mt-3">
                    <div class="col-md-6 mb-3">
                      <label for="mobile" class="form-label required-field">Mobile 01</label>
                      <input type="text" class="form-control" id="mobile" name="mobile" required>
                    </div>
                    <div class="col-md-6 mb-3">
                      <label for="mobile2" class="form-label">Mobile 02</label>
                      <input type="text" class="form-control" id="mobile2" name="mobile2">
                    </div>
                  </div>

                  <div class="row">
                    <div class="col-md-6 mb-3">
                      <label for="email" class="form-label">Email Address</label>
                      <input type="email" class="form-control" id="email" name="email">
                    </div>
                    <div class="col-md-6 mb-3">
                      <label for="home_phone" class="form-label">Home Phone</label>
                      <input type="text" class="form-control" id="home_phone" name="home_phone">
                    </div>
                  </div>
                </div>

                <!-- Address Information Section -->
                <div class="form-section">
                  <h5><i class="fas fa-home me-2"></i>Address Information</h5>
                  <div class="row mt-3">
                    <div class="col-md-6 mb-3">
                      <label for="permanent_address" class="form-label required-field">Permanent Address</label>
                      <textarea class="form-control" id="permanent_address" name="permanent_address" rows="3" required></textarea>
                    </div>
                    <div class="col-md-6 mb-3">
                      <label for="correspondent_address" class="form-label">Correspondent Address</label>
                      <textarea class="form-control" id="correspondent_address" name="correspondent_address" rows="3"></textarea>
                    </div>
                  </div>
                </div>

                <!-- Employment Information Section -->
                <div class="form-section">
                  <h5><i class="fas fa-briefcase me-2"></i>Employment Information</h5>
                  <div class="row mt-3">
                    <div class="col-md-6 mb-3">
                      <label for="position_held" class="form-label">Position Held</label>
                      <input type="text" class="form-control" id="position_held" name="position_held">
                    </div>
                    <div class="col-md-6 mb-3">
                      <label for="business_type" class="form-label">Business Type</label>
                      <select class="form-control" id="business_type" name="business_type">
                        <option value="">Select</option>
                        <option value="Sole Proprietorship">Sole Proprietorship</option>
                        <option value="Partnership">Partnership</option>
                        <option value="Private Limited">Private Limited</option>
                        <option value="Public Limited">Public Limited</option>
                      </select>
                    </div>
                  </div>
                </div>

                <div class="text-center mt-4">
                  <button type="submit" style="margin-bottom:20px;" class="btn btn-primary btn-lg px-5">
                    <i class="fas fa-save me-2"></i>Save Customer Data
                  </button>
                </div>
              </form>

              <!-- Business Information Section (Section B) -->
                                <div class="form-section">
                                    <h5><i class="fas fa-building me-2"></i>Business Information</h5>
                                    <div class="row mt-3">
                                        <div class="col-md-6 mb-3">
                                            <label for="business_name" class="form-label required-field">Name of the Business</label>
                                            <input type="text" class="form-control" id="business_name" name="business_name" required>
                                        </div>
                                        <div class="col-md-6 mb-3">
                                            <label for="registered_address" class="form-label required-field">Registered Address</label>
                                            <textarea class="form-control" id="registered_address" name="registered_address" rows="2" required></textarea>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-md-6 mb-3">
                                            <label for="correspondent_address" class="form-label required-field">Correspondent Address</label>
                                            <textarea class="form-control" id="correspondent_address" name="correspondent_address" rows="2" required></textarea>
                                        </div>
                                        <div class="col-md-6 mb-3">
                                            <label for="registration_number" class="form-label required-field">Registration Number</label>
                                            <input type="text" class="form-control" id="registration_number" name="registration_number" required>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-md-6 mb-3">
                                            <label for="date_of_incorporation" class="form-label required-field">Date of Incorporation</label>
                                            <input type="date" class="form-control" id="date_of_incorporation" name="date_of_incorporation" required>
                                        </div>
                                        <div class="col-md-6 mb-3">
                                            <label for="nature_of_business" class="form-label required-field">Nature of the Business</label>
                                            <input type="text" class="form-control" id="nature_of_business" name="nature_of_business" required>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-md-6 mb-3">
                                            <label for="business_contact" class="form-label required-field">Contact Number</label>
                                            <input type="text" class="form-control" id="business_contact" name="business_contact" required>
                                        </div>
                                        <div class="col-md-6 mb-3">
                                            <label for="business_email" class="form-label required-field">Email Address</label>
                                            <input type="email" class="form-control" id="business_email" name="business_email" required>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-12 mb-3">
                                            <label class="form-label">Assets owned by the Entity and Estimated Value</label>
                                            <div class="asset-item">
                                                <input type="checkbox" class="asset-checkbox" id="property_asset" name="assets[]" value="property">
                                                <label for="property_asset">Property</label>
                                                <input type="text" class="form-control d-inline-block ml-2" style="width: 200px;" placeholder="LKR........." name="property_value" disabled>
                                            </div>
                                            <div class="asset-item">
                                                <input type="checkbox" class="asset-checkbox" id="vehicles_asset" name="assets[]" value="vehicles">
                                                <label for="vehicles_asset">Motor Vehicles</label>
                                                <input type="text" class="form-control d-inline-block ml-2" style="width: 200px;" placeholder="LKR........." name="vehicles_value" disabled>
                                            </div>
                                            <div class="asset-item">
                                                <input type="checkbox" class="asset-checkbox" id="investments_asset" name="assets[]" value="investments">
                                                <label for="investments_asset">Investments</label>
                                                <input type="text" class="form-control d-inline-block ml-2" style="width: 200px;" placeholder="LKR........." name="investments_value" disabled>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-md-4 mb-3">
                                            <label for="daily_turnover" class="form-label">Per Day Sales Turnover</label>
                                            <input type="text" class="form-control" id="daily_turnover" name="daily_turnover">
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <label for="daily_profit" class="form-label">Per Day Net Profit/Loss</label>
                                            <input type="text" class="form-control" id="daily_profit" name="daily_profit">
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <label for="total_liabilities" class="form-label">Total Liabilities</label>
                                            <input type="text" class="form-control" id="total_liabilities" name="total_liabilities">
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-12">
                                            <label class="form-label">Banking Relationship with Banks</label>
                                            <table class="table table-bordered" id="bankingTable">
                                                <thead>
                                                    <tr>
                                                        <th>Bank</th>
                                                        <th>Branch</th>
                                                        <th>Account Number</th>
                                                        <th>Account Type</th>
                                                        <th>Action</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr>
                                                        <td><input type="text" class="form-control" name="bank_name[]"></td>
                                                        <td><input type="text" class="form-control" name="bank_branch[]"></td>
                                                        <td><input type="text" class="form-control" name="account_number[]"></td>
                                                        <td>
                                                            <select class="form-control" name="account_type[]">
                                                                <option value="Savings">Savings</option>
                                                                <option value="Current">Current</option>
                                                                <option value="Business">Business</option>
                                                            </select>
                                                        </td>
                                                        <td><button type="button" class="btn btn-sm btn-danger" onclick="removeBankRow(this)"><i class="fas fa-trash"></i></button></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                            <button type="button" class="btn btn-sm btn-primary" onclick="addBankRow()"><i class="fas fa-plus"></i> Add Bank</button>
                                        </div>
                                    </div>
                                </div>

                                <div class="text-center mt-4">
                                    <button type="submit" style="margin-bottom:20px;" class="btn btn-primary btn-lg px-5">
                                        <i class="fas fa-save me-2"></i>Save Customer Data
                                    </button>
                                </div>
                            </form>

              <!-- Document Upload Section -->
              <div id="documentUploadSection" class="mt-5">
                <h3 class="text-center mb-4"><i class="fas fa-file-upload me-2"></i>Upload Required Documents</h3>
                <input type="hidden" id="customerId" value="">

                <div class="row">
                  <div class="col-md-6">
                    <!-- Business Documents -->
                    <div class="document-item">
                      <h6><i class="fas fa-briefcase me-2"></i>Business Registration Documents *</h6>
                      <form class="documentUploadForm" data-doc-type="business_registration">
                        <div class="input-group">
                          <input type="file" class="form-control" name="document" accept=".jpg,.jpeg,.png,.pdf" required>
                          <button type="submit" class="btn btn-primary">Upload</button>
                        </div>
                        <div class="upload-status"></div>
                        <small class="text-muted">Include: Registration Certificate, Forms (1,13,15,20), Articles of Association</small>
                      </form>
                    </div>

                    <div class="document-item">
                      <h6><i class="fas fa-building me-2"></i>Business Premises Proof *</h6>
                      <form class="documentUploadForm" data-doc-type="business_premises">
                        <div class="input-group">
                          <input type="file" class="form-control" name="document" accept=".jpg,.jpeg,.png,.pdf" required>
                          <button type="submit" class="btn btn-primary">Upload</button>
                        </div>
                        <div class="upload-status"></div>
                        <small class="text-muted">Include: Lease/Deed, CMC Tax Receipts, Utility Bills</small>
                      </form>
                    </div>

                    <div class="document-item">
                      <h6><i class="fas fa-chart-line me-2"></i>Financial Records *</h6>
                      <form class="documentUploadForm" data-doc-type="financial_records">
                        <div class="input-group">
                          <input type="file" class="form-control" name="document" accept=".jpg,.jpeg,.png,.pdf" required>
                          <button type="submit" class="btn btn-primary">Upload</button>
                        </div>
                        <div class="upload-status"></div>
                        <small class="text-muted">Include: Audited Statements (3 years), Management Accounts</small>
                      </form>
                    </div>
                  </div>

                  <div class="col-md-6">
                    <!-- Personal Documents -->
                    <div class="document-item">
                      <h6><i class="fas fa-id-card me-2"></i>Identification Documents *</h6>
                      <form class="documentUploadForm" data-doc-type="id_documents">
                        <div class="input-group">
                          <input type="file" class="form-control" name="document" accept=".jpg,.jpeg,.png,.pdf" required>
                          <button type="submit" class="btn btn-primary">Upload</button>
                        </div>
                        <div class="upload-status"></div>
                        <small class="text-muted">NIC (both sides), Passport if available</small>
                      </form>
                    </div>

                    <div class="document-item">
                      <h6><i class="fas fa-home me-2"></i>Residential Proof</h6>
                      <form class="documentUploadForm" data-doc-type="residential_proof">
                        <div class="input-group">
                          <input type="file" class="form-control" name="document" accept=".jpg,.jpeg,.png,.pdf">
                          <button type="submit" class="btn btn-primary">Upload</button>
                        </div>
                        <div class="upload-status"></div>
                        <small class="text-muted">Lease/Deed, Utility Bills, CMC Tax Receipts</small>
                      </form>
                    </div>

                    <div class="document-item">
                      <h6><i class="fas fa-file-invoice me-2"></i>Other Required Documents *</h6>
                      <form class="documentUploadForm" data-doc-type="other_documents">
                        <div class="input-group">
                          <input type="file" class="form-control" name="document" accept=".jpg,.jpeg,.png,.pdf" required>
                          <button type="submit" class="btn btn-primary">Upload</button>
                        </div>
                        <div class="upload-status"></div>
                        <small class="text-muted">Request Letter, CRIB Report, Assets & Liability Declaration</small>
                      </form>
                    </div>
                  </div>
                </div>

                <div class="document-item mt-4">
                  <h6><i class="fas fa-university me-2"></i>Bank Statements (Last 6 months) *</h6>
                  <form class="documentUploadForm" data-doc-type="bank_statements">
                    <div class="input-group">
                      <input type="file" class="form-control" name="document" accept=".jpg,.jpeg,.png,.pdf" required>
                      <button type="submit" class="btn btn-primary">Upload</button>
                    </div>
                    <div class="upload-status"></div>
                    <small class="text-muted">Both corporate and personal account statements</small>
                  </form>
                </div>

                <div id="uploadProgress" class="mt-4">
                  <h5 class="text-center">Upload Progress</h5>
                  <div class="progress">
                    <div class="progress-bar" role="progressbar" style="width: 0%"></div>
                  </div>
                  <p class="text-center">Uploaded <span id="uploadCount">0</span> of <span id="totalDocuments">7</span> required documents</p>
                </div>

                <div id="completionMessage" class="completion-message" style="display:none;">
                  <h3><i class="fas fa-check-circle me-2"></i>All documents uploaded successfully!</h3>
                  <p class="mb-0">Your customer registration is now complete.</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <!--col-md-12-->
</div>



<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
  $(document).ready(function() {
    // Handle main form submission
    $('#customerForm').submit(function(e) {
      e.preventDefault();

      // Simple validation
      let isValid = true;
      $('.required-field').each(function() {
        const fieldId = $(this).attr('for');
        if (!$('#' + fieldId).val()) {
          isValid = false;
          $('#' + fieldId).addClass('is-invalid');
        } else {
          $('#' + fieldId).removeClass('is-invalid');
        }
      });

      if (!isValid) {
        alert('Please fill in all required fields.');
        return;
      }

      // Prepare form data for AJAX submission
      var formData = $(this).serialize();

      // Add additional fields that might not be in the form
      formData += '&cus_type=loan&cus_status=1&location_status=0&locaton_update_user_id=0';

      // Send data via AJAX
      $.post("<?php echo base_url(); ?>customers/add_customer", formData)
        .done(function(data) {
          var obj = jQuery.parseJSON(data);
          if (obj.status == 0) {
            // Show validation errors
            $('div#error').html('<div class="alert alert-block alert-danger fade in"><button type="button" class="close" data-dismiss="alert">×</button><h4 class="alert-heading"><i class="fa fa-times-circle"></i> Error!</h4>' + obj.validation + '</div>');
          } else {
            // Success - show document upload section
            $('#customerId').val(obj.id);
            $('#documentUploadSection').show();
            $('#customerForm').hide();

            // Update step indicator
            $('.step').removeClass('active');
            $('.step:eq(0)').addClass('completed');
            $('.step:eq(1)').addClass('active');

            alert('Customer data saved successfully! Customer ID: ' + obj.id + '\nPlease upload the required documents.');
          }
        })
        .fail(function() {
          alert('An error occurred while saving customer data.');
        });
    
    
      });

    // Handle individual document uploads
    $('.documentUploadForm').submit(function(e) {
      e.preventDefault();
      const form = $(this);
      const docType = form.data('doc-type');
      const customerId = $('#customerId').val();

      if (!customerId) {
        alert('Please save customer data first.');
        return;
      }

      // Create FormData object for file upload
      var formData = new FormData();
      formData.append('document', form.find('input[type="file"]')[0].files[0]);
      formData.append('customer_id', customerId);
      formData.append('doc_type', docType);

      // Simulate file upload
      form.find('button').prop('disabled', true);
      form.find('.upload-status').html('<i class="fas fa-spinner fa-spin"></i> Uploading...');

      // Send file via AJAX
      $.ajax({
        url: "<?php echo base_url(); ?>customers/upload_document",
        type: "POST",
        data: formData,
        processData: false,
        contentType: false,
        success: function(response) {
          var obj = jQuery.parseJSON(response);
          if (obj.success) {
            form.find('.upload-status').html('<i class="fas fa-check-circle text-success"></i> Uploaded successfully');
            form.find('button').hide();

            // Update progress
            const uploaded = $('.upload-status:contains("Uploaded successfully")').length;
            const total = $('.documentUploadForm').length;
            const percent = (uploaded / total) * 100;
            $('.progress-bar').css('width', percent + '%').text(Math.round(percent) + '%');
            $('#uploadCount').text(uploaded);

            // Update step indicator when all documents are uploaded
            if (uploaded === total) {
              $('.step').removeClass('active');
              $('.step:eq(1)').addClass('completed');
              $('.step:eq(2)').addClass('completed');
              $('#completionMessage').show();

              // Close modal after successful registration
              setTimeout(function() {
                $('div#ajax-modal').modal('hide');
                displayNotice('page', 'Customer has been added successfully!');
              }, 2000);
            }
          } else {
            form.find('.upload-status').html('<i class="fas fa-times text-danger"></i> ' + obj.error);
            form.find('button').prop('disabled', false);
          }
        },
        error: function() {
          form.find('.upload-status').html('<i class="fas fa-times text-danger"></i> Upload failed');
          form.find('button').prop('disabled', false);
        }
      });
    });


  });
</script>


<script>
  jQuery(document).ready(function() {

    $("#country_id").select2();
  });

  function insertCustomerData() {
    var type = $('#type').val();
    var cus_id = $('#cus_id').val();
    var country_id = $('#country_id').val();
    var city_name = $('#city_name').val();
    var cus_name = $('#cus_name').val();
    var cus_code = $('#cus_code').val();
    var cus_email = $('#cus_email').val();
    var cus_phone = $('#cus_phone').val();
    var cus_address = $('#cus_address').val();
    var cus_state = $('#cus_state').val();
    var cus_postal_code = $('#cus_postal_code').val();
    var cus_mobile = $('#cus_mobile').val();
    var cus_mobile_2 = $('#cus_mobile_2').val();
    var cus_home_phone = $('#cus_home_phone').val();
    var warehouse_id_c = $('#warehouse_id_c').val();
    var route_id = $('#route_id').val();
    var cus_nic = $('#cus_nic').val();


    $.post("<?php echo base_url(); ?>customers/save_customer", {
        type: type,
        cus_id: cus_id,
        country_id: country_id,
        city_name: city_name,
        cus_name: cus_name,
        cus_code: cus_code,
        cus_email: cus_email,
        cus_phone: cus_phone,
        cus_address: cus_address,
        cus_state: cus_state,
        cus_postal_code: cus_postal_code,
        cus_mobile: cus_mobile,
        cus_mobile_2: cus_mobile_2,
        cus_home_phone: cus_home_phone,
        warehouse_id_c: warehouse_id_c,
        cus_nic: cus_nic,
        route_id: route_id
      })
      .done(function(data) {

        var obj = jQuery.parseJSON(data);
        if (obj.status == 0) {
          $('div#error').html('<div class="alert alert-block alert-danger fade in"><button type="button" class="close" data-dismiss="alert">×</button><h4 class="alert-heading"><i class="fa fa-times-circle"></i> Error!</h4>' + obj.validation + '</div>');
          //$('body').modalmanager('removeLoading');
          $('body').attr('class', '');
        } else {
          // alert(obj.type); //last id	  
          $('div#ajax-modal').modal('hide');

          if (obj.type == 'E') {
            displayNotice('page', 'Customer has been updated successfully!');
          }
          if (obj.type == 'A') {
            displayNotice('page', 'Customer has been added successfully!');

          }

          <?php if (isset($btn_id)) { ?>
            var data = {
              id: obj.id,
              text: $('#cus_name').val()
            };
            //var newOption = new Option(data.text, data.id, false, false);

            <?php if ($btn_id == "cus_id") { ?>
              $(".js-data-cus_id-ajax").select2('data', {
                id: obj.id,
                text: $('#cus_name').val()
              });
            <?php } ?>
            <?php if ($btn_id == "g_cus_id") { ?>
              $(".js-data-g_cus_id-ajax").select2('data', {
                id: obj.id,
                text: $('#cus_name').val()
              });
            <?php } ?>


          <?php } ?>
          //loadGrid();// load customer data	
        }
      });
    return false;
  }
</script>