huge fix
This commit is contained in:
		
							parent
							
								
									810c87e2e0
								
							
						
					
					
						commit
						b5bf3a5dbe
					
				
					 51 changed files with 2397 additions and 326 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
{% extends '_base.html' %}
 | 
			
		||||
{% load static %}
 | 
			
		||||
{% load accounts_tags %}
 | 
			
		||||
{% load common_tags %}
 | 
			
		||||
 | 
			
		||||
{% block sidebar %}
 | 
			
		||||
    {% include 'sidebars/admin.html' %}
 | 
			
		||||
| 
						 | 
				
			
			@ -36,12 +37,10 @@
 | 
			
		|||
    <div class="d-md-flex justify-content-between align-items-center dt-layout-end col-md-auto ms-auto mt-0">
 | 
			
		||||
      <div class="dt-buttons btn-group flex-wrap mb-0">
 | 
			
		||||
        <div class="btn-group">
 | 
			
		||||
          <button class="btn buttons-collection btn-label-primary dropdown-toggle me-4 d-none" type="button">
 | 
			
		||||
            <span>
 | 
			
		||||
              <span class="d-flex align-items-center gap-2">
 | 
			
		||||
                <i class="icon-base bx bx-export me-sm-1"></i>
 | 
			
		||||
                <span class="d-none d-sm-inline-block">خروجی</span>
 | 
			
		||||
              </span>
 | 
			
		||||
          <button class="btn btn-label-success me-2" type="button" onclick="exportToExcel()">
 | 
			
		||||
            <span class="d-flex align-items-center gap-2">
 | 
			
		||||
              <i class="bx bx-export me-sm-1"></i>
 | 
			
		||||
              <span class="d-none d-sm-inline-block">خروجی اکسل</span>
 | 
			
		||||
            </span>
 | 
			
		||||
          </button>
 | 
			
		||||
          {% if request.user|is_broker %}
 | 
			
		||||
| 
						 | 
				
			
			@ -212,6 +211,7 @@
 | 
			
		|||
            <th>امور</th>
 | 
			
		||||
            <th>پیشرفت</th>
 | 
			
		||||
            <th>وضعیت</th>
 | 
			
		||||
            <th>تاریخ نصب/تاخیر</th>
 | 
			
		||||
            <th>تاریخ ایجاد</th>
 | 
			
		||||
            <th>عملیات</th>
 | 
			
		||||
          </tr>
 | 
			
		||||
| 
						 | 
				
			
			@ -244,6 +244,20 @@
 | 
			
		|||
              </div>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>{{ item.instance.get_status_display_with_color|safe }}</td>
 | 
			
		||||
            <td>
 | 
			
		||||
              {% if item.installation_scheduled_date %}
 | 
			
		||||
                <div>
 | 
			
		||||
                  <span title="{{ item.installation_scheduled_date|date:'Y-m-d' }}">{{ item.installation_scheduled_date | to_jalali }}</span>
 | 
			
		||||
                </div>
 | 
			
		||||
                {% if item.installation_overdue_days and item.installation_overdue_days > 0 %}
 | 
			
		||||
                  <small class="text-danger d-block">{{ item.installation_overdue_days }} روز تاخیر</small>
 | 
			
		||||
                {% else %}
 | 
			
		||||
                  <small class="text-muted d-block">بدون تاخیر</small>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
              {% else %}
 | 
			
		||||
                <span class="text-muted">تاریخ نصب تعیین نشده</span>
 | 
			
		||||
              {% endif %}
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>{{ item.instance.jcreated_date }}</td>
 | 
			
		||||
            <td>
 | 
			
		||||
              <div class="d-inline-block">
 | 
			
		||||
| 
						 | 
				
			
			@ -287,6 +301,7 @@
 | 
			
		|||
            <td></td>
 | 
			
		||||
            <td></td>
 | 
			
		||||
            <td></td>
 | 
			
		||||
            <td></td>
 | 
			
		||||
          </tr>
 | 
			
		||||
          {% endfor %}
 | 
			
		||||
        </tbody>
 | 
			
		||||
| 
						 | 
				
			
			@ -419,6 +434,10 @@
 | 
			
		|||
 | 
			
		||||
              <div id="repNewFields" class="col-sm-12" style="display:none;">
 | 
			
		||||
                <div class="row g-3">
 | 
			
		||||
                  <div class="col-sm-12">
 | 
			
		||||
                    <label class="form-label" for="id_user_type">{{ customer_form.user_type.label }}</label>
 | 
			
		||||
                    {{ customer_form.user_type }}
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div class="col-sm-6">
 | 
			
		||||
                    <label class="form-label" for="id_first_name">{{ customer_form.first_name.label }}</label>
 | 
			
		||||
                    {{ customer_form.first_name }}
 | 
			
		||||
| 
						 | 
				
			
			@ -439,6 +458,15 @@
 | 
			
		|||
                    <label class="form-label" for="id_national_code">{{ customer_form.national_code.label }}</label>
 | 
			
		||||
                    {{ customer_form.national_code }}
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <!-- Company fields for legal entities -->
 | 
			
		||||
                  <div class="col-sm-6 company-fields" style="display:none;">
 | 
			
		||||
                    <label class="form-label" for="id_company_name">{{ customer_form.company_name.label }}</label>
 | 
			
		||||
                    {{ customer_form.company_name }}
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div class="col-sm-6 company-fields" style="display:none;">
 | 
			
		||||
                    <label class="form-label" for="id_company_national_id">{{ customer_form.company_national_id.label }}</label>
 | 
			
		||||
                    {{ customer_form.company_national_id }}
 | 
			
		||||
                  </div>
 | 
			
		||||
                  <div class="col-sm-6">
 | 
			
		||||
                    <label class="form-label" for="id_card_number">{{ customer_form.card_number.label }}</label>
 | 
			
		||||
                    {{ customer_form.card_number }}
 | 
			
		||||
| 
						 | 
				
			
			@ -717,6 +745,21 @@
 | 
			
		|||
        .fail(function(){ setStatus('#wellStatus', 'خطا در بررسی چاه', 'danger'); });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    function toggleRepCompanyFields() {
 | 
			
		||||
      const userType = $('#user-type-select').val();
 | 
			
		||||
      if (userType === 'legal') {
 | 
			
		||||
        $('#repNewFields .company-fields').show();
 | 
			
		||||
        $('input[name="company_name"]').attr('required', true);
 | 
			
		||||
        $('input[name="company_national_id"]').attr('required', true);
 | 
			
		||||
      } else {
 | 
			
		||||
        $('#repNewFields .company-fields').hide();
 | 
			
		||||
        $('input[name="company_name"]').removeAttr('required');
 | 
			
		||||
        $('input[name="company_national_id"]').removeAttr('required');
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $('#user-type-select').on('change', toggleRepCompanyFields);
 | 
			
		||||
 | 
			
		||||
    $('#btnLookupRep').on('click', function() {
 | 
			
		||||
      const nc = $('#rep_national_code').val().trim();
 | 
			
		||||
      if (!nc) { setStatus('#repStatus', 'لطفا کد ملی نماینده را وارد کنید', 'danger'); return; }
 | 
			
		||||
| 
						 | 
				
			
			@ -732,36 +775,47 @@
 | 
			
		|||
            $('#id_first_name').val(resp.user.first_name || '');
 | 
			
		||||
            $('#id_last_name').val(resp.user.last_name || '');
 | 
			
		||||
            if (resp.user.profile) {
 | 
			
		||||
              $('#user-type-select').val(resp.user.profile.user_type || 'individual');
 | 
			
		||||
              $('#id_national_code').val(resp.user.profile.national_code || nc);
 | 
			
		||||
              $('#id_phone_number_1').val(resp.user.profile.phone_number_1 || '');
 | 
			
		||||
              $('#id_phone_number_2').val(resp.user.profile.phone_number_2 || '');
 | 
			
		||||
              $('#id_company_name').val(resp.user.profile.company_name || '');
 | 
			
		||||
              $('#id_company_national_id').val(resp.user.profile.company_national_id || '');
 | 
			
		||||
              $('#id_card_number').val(resp.user.profile.card_number || '');
 | 
			
		||||
              $('#id_account_number').val(resp.user.profile.account_number || '');
 | 
			
		||||
              $('#id_bank_name').val(resp.user.profile.bank_name || '');
 | 
			
		||||
              $('#id_address').val(resp.user.profile.address || '');
 | 
			
		||||
            } else {
 | 
			
		||||
              $('#user-type-select').val('individual');
 | 
			
		||||
              $('#id_national_code').val(nc);
 | 
			
		||||
              $('#id_phone_number_1').val('');
 | 
			
		||||
              $('#id_phone_number_2').val('');
 | 
			
		||||
              $('#id_company_name').val('');
 | 
			
		||||
              $('#id_company_national_id').val('');
 | 
			
		||||
              $('#id_card_number').val('');
 | 
			
		||||
              $('#id_account_number').val('');
 | 
			
		||||
              $('#id_bank_name').val('');
 | 
			
		||||
              $('#id_address').val('');
 | 
			
		||||
            }
 | 
			
		||||
            toggleRepCompanyFields();
 | 
			
		||||
            setStatus('#repStatus', 'نماینده یافت شد.', 'success');
 | 
			
		||||
          } else {
 | 
			
		||||
            currentRepId = null;
 | 
			
		||||
            $('#repNewFields').show();
 | 
			
		||||
            // Clear form and prefill national code
 | 
			
		||||
            $('#user-type-select').val('individual');
 | 
			
		||||
            $('#id_first_name').val('');
 | 
			
		||||
            $('#id_last_name').val('');
 | 
			
		||||
            $('#id_national_code').val(nc);
 | 
			
		||||
            $('#id_phone_number_1').val('');
 | 
			
		||||
            $('#id_phone_number_2').val('');
 | 
			
		||||
            $('#id_company_name').val('');
 | 
			
		||||
            $('#id_company_national_id').val('');
 | 
			
		||||
            $('#id_card_number').val('');
 | 
			
		||||
            $('#id_account_number').val('');
 | 
			
		||||
            $('#id_bank_name').val('');
 | 
			
		||||
            $('#id_address').val('');
 | 
			
		||||
            toggleRepCompanyFields();
 | 
			
		||||
            setStatus('#repStatus', 'نماینده یافت نشد. لطفا اطلاعات را تکمیل کنید.', 'danger');
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
| 
						 | 
				
			
			@ -954,6 +1008,45 @@
 | 
			
		|||
        });
 | 
			
		||||
      };
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // Export to Excel function
 | 
			
		||||
    window.exportToExcel = function() {
 | 
			
		||||
      // Get current filter parameters from the form
 | 
			
		||||
      const form = document.querySelector('form[method="get"]');
 | 
			
		||||
      const formData = new FormData(form);
 | 
			
		||||
      
 | 
			
		||||
      // Build query string
 | 
			
		||||
      const params = new URLSearchParams();
 | 
			
		||||
      for (const [key, value] of formData.entries()) {
 | 
			
		||||
        if (value.trim()) {
 | 
			
		||||
          params.append(key, value);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Create export URL with current filters
 | 
			
		||||
      const exportUrl = '{% url "processes:export_requests_excel" %}' + '?' + params.toString();
 | 
			
		||||
      
 | 
			
		||||
      // Show loading state
 | 
			
		||||
      const btn = document.querySelector('button[onclick="exportToExcel()"]');
 | 
			
		||||
      const originalText = btn.innerHTML;
 | 
			
		||||
      btn.innerHTML = '<i class="bx bx-loader-circle bx-spin me-1"></i>در حال تولید...';
 | 
			
		||||
      btn.disabled = true;
 | 
			
		||||
      
 | 
			
		||||
      // Create invisible link and trigger download
 | 
			
		||||
      const link = document.createElement('a');
 | 
			
		||||
      link.href = exportUrl;
 | 
			
		||||
      link.style.display = 'none';
 | 
			
		||||
      document.body.appendChild(link);
 | 
			
		||||
      link.click();
 | 
			
		||||
      document.body.removeChild(link);
 | 
			
		||||
      
 | 
			
		||||
      // Reset button after a short delay
 | 
			
		||||
      setTimeout(() => {
 | 
			
		||||
        btn.innerHTML = originalText;
 | 
			
		||||
        btn.disabled = false;
 | 
			
		||||
        showToast('فایل اکسل آماده دانلود است', 'success');
 | 
			
		||||
      }, 1000);
 | 
			
		||||
    };
 | 
			
		||||
  });
 | 
			
		||||
</script>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue