789 lines
32 KiB
HTML
789 lines
32 KiB
HTML
{% extends "./customerBaseNew.html" %}
|
||
{% load custom_tags %}
|
||
{% load static %}
|
||
|
||
{% block BodyCustomer1 %}
|
||
|
||
<style>
|
||
/* استایلهای اختصاصی جدول و جستجوگر */
|
||
.sayyad-code {
|
||
font-family: monospace, monospace;
|
||
letter-spacing: 1px;
|
||
font-weight: 700;
|
||
color: #1e293b;
|
||
background-color: #f1f5f9;
|
||
padding: 3px 8px;
|
||
border-radius: 4px;
|
||
display: inline-block;
|
||
}
|
||
.table th {
|
||
vertical-align: middle !important;
|
||
background-color: #f8fafc;
|
||
white-space: nowrap;
|
||
}
|
||
.table td {
|
||
vertical-align: middle !important;
|
||
white-space: nowrap;
|
||
}
|
||
.price-preview {
|
||
font-size: 0.85rem;
|
||
color: #2563eb;
|
||
font-weight: 600;
|
||
margin-top: 4px;
|
||
display: block;
|
||
}
|
||
|
||
/* تنظیمات پاسخگویی هدر */
|
||
.header-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
width: 100%;
|
||
}
|
||
.search-box {
|
||
flex-grow: 1;
|
||
max-width: 300px;
|
||
}
|
||
|
||
@media screen and (max-width: 768px) {
|
||
.header-container {
|
||
flex-direction: column;
|
||
align-items: stretch !important;
|
||
gap: 12px;
|
||
}
|
||
.header-actions {
|
||
flex-direction: column;
|
||
width: 100%;
|
||
}
|
||
.search-box {
|
||
max-width: 100% !important;
|
||
width: 100%;
|
||
}
|
||
.header-actions .button {
|
||
width: 100%;
|
||
justify-content: center;
|
||
}
|
||
.table th, .table td {
|
||
padding: 0.5em 0.6em !important;
|
||
font-size: 0.85rem;
|
||
}
|
||
}
|
||
|
||
.table-responsive-wrapper {
|
||
width: 100%;
|
||
overflow-x: auto;
|
||
-webkit-overflow-scrolling: touch;
|
||
border-radius: 6px;
|
||
}
|
||
|
||
/* استایلهای نتایج استعلام */
|
||
.inquiry-box {
|
||
background-color: #f8fafc;
|
||
padding: 15px;
|
||
border-radius: 8px;
|
||
margin-top: 15px;
|
||
border: 1px solid #cbd5e1;
|
||
}
|
||
</style>
|
||
|
||
<div id="hesabdari" class="column is-12-mobile is-12-desktop">
|
||
|
||
<div class="is-flex is-justify-content-space-between is-align-items-center mb-4 header-container">
|
||
<div>
|
||
<h1 class="title is-5 has-text-weight-bold mb-0">
|
||
مدیریت چکها و نسیهها
|
||
</h1>
|
||
</div>
|
||
|
||
<div class="header-actions">
|
||
<div class="field mb-0 search-box">
|
||
<p class="control has-icons-left">
|
||
<input class="input is-rounded is-small" type="text" id="checkSearchInput" placeholder="جستجو: ردیف چک یا صیادی...">
|
||
<span class="icon is-small is-left has-text-grey">
|
||
<i class="fas fa-search"></i>
|
||
</span>
|
||
</p>
|
||
</div>
|
||
|
||
<button class="button is-primary is-rounded is-small" id="newSarresid">
|
||
<span class="icon"><i class="fas fa-plus"></i></span>
|
||
<span>افزودن سند جدید</span>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
{% if messages %}
|
||
{% for message in messages %}
|
||
<div class="notification is-{{ message.tags }} is-light mt-3 py-2">
|
||
<button class="delete"></button>
|
||
{{ message }}
|
||
</div>
|
||
{% endfor %}
|
||
{% endif %}
|
||
|
||
{% if all_sarresid %}
|
||
<div class="table-responsive-wrapper">
|
||
<table class="table is-bordered is-striped is-hoverable is-fullwidth has-text-centered mb-0" id="sarresidTable">
|
||
<thead>
|
||
<tr>
|
||
<th style="width: 50px;">#</th>
|
||
<th>مبلغ (تومان)</th>
|
||
<th>نوع</th>
|
||
<th>وضعیت</th>
|
||
<th>عملیات</th>
|
||
<th>تکمیل اطلاعات چک</th>
|
||
<th>تاریخ سررسید</th>
|
||
<th>ردیف چک</th>
|
||
<th>شناسه صیادی</th>
|
||
<th>صاحب حساب (تلفن)</th>
|
||
<th>توضیحات / فاکتور</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{% for sarresid in all_sarresid %}
|
||
<tr class="sarresid-row">
|
||
<td>{{ forloop.counter }}</td>
|
||
|
||
<td>
|
||
<span class="has-text-weight-bold is-size-6 bedehkar toCurrency">{{ sarresid.price }}</span>
|
||
</td>
|
||
|
||
<td>
|
||
{% if sarresid.type == 'check' %}
|
||
<span class="tag is-info is-light has-text-weight-bold">چک</span>
|
||
{% elif sarresid.type == 'nesiye' %}
|
||
<span class="tag is-warning is-light has-text-weight-bold">نسیه</span>
|
||
{% endif %}
|
||
</td>
|
||
|
||
<td>
|
||
{% if sarresid.payStatus == "true" %}
|
||
<span class="has-text-success has-text-weight-bold is-size-7">
|
||
<i class="fas fa-check-circle"></i> وصول شد
|
||
</span>
|
||
{% else %}
|
||
<span class="has-text-danger has-text-weight-bold is-size-7">
|
||
<i class="fas fa-clock"></i> در انتظار
|
||
</span>
|
||
{% endif %}
|
||
</td>
|
||
|
||
<td>
|
||
{% if sarresid.payStatus == "false" %}
|
||
<button class="button is-danger is-small is-outlined VosolButton"
|
||
price="{{ sarresid.price }}"
|
||
type="{{ sarresid.type }}"
|
||
articlID="{{ sarresid.id }}">
|
||
وصول شد
|
||
</button>
|
||
{% else %}
|
||
<span class="has-text-grey-light is-size-7">تسویه شده</span>
|
||
{% endif %}
|
||
</td>
|
||
|
||
<td>
|
||
{% if sarresid.type == 'check' %}
|
||
<button class="button is-small is-info is-light has-text-weight-bold btn-update-check"
|
||
data-id="{{ sarresid.id }}"
|
||
data-row="{{ sarresid.check_row_number|default:'' }}"
|
||
data-sayyad="{{ sarresid.check_sayyad_id|default:'' }}"
|
||
data-owner="{{ sarresid.check_owner_name|default:'' }}"
|
||
data-phone="{{ sarresid.check_owner_phone|default:'' }}">
|
||
<span class="icon is-small"><i class="fas fa-edit"></i></span>
|
||
<span>ویرایش و استعلام</span>
|
||
</button>
|
||
{% else %}
|
||
<span class="has-text-grey-light">-</span>
|
||
{% endif %}
|
||
</td>
|
||
|
||
<td>{{ sarresid.sarresidDT | toJalali }}</td>
|
||
|
||
<td class="search-row-num has-text-weight-semibold">
|
||
{{ sarresid.check_row_number|default:"-" }}
|
||
</td>
|
||
|
||
<td class="search-sayyad-id">
|
||
{% if sarresid.check_sayyad_id %}
|
||
<span class="sayyad-code">{{ sarresid.check_sayyad_id }}</span>
|
||
{% else %}
|
||
-
|
||
{% endif %}
|
||
</td>
|
||
|
||
<td>
|
||
{% if sarresid.check_owner_name %}
|
||
<div class="has-text-dark has-text-weight-semibold is-size-7">{{ sarresid.check_owner_name }}</div>
|
||
{% if sarresid.check_owner_phone %}
|
||
<div class="has-text-grey is-size-7 mt-1" dir="ltr">{{ sarresid.check_owner_phone }}</div>
|
||
{% endif %}
|
||
{% else %}
|
||
-
|
||
{% endif %}
|
||
</td>
|
||
|
||
<td class="has-text-right is-size-7">
|
||
{% if sarresid.desc %}
|
||
<p class="has-text-grey-dark">{{ sarresid.desc }}</p>
|
||
{% endif %}
|
||
{% if sarresid.factor.id %}
|
||
<span class="tag is-small is-link is-light mt-1">فاکتور: {{ sarresid.factor.id }}</span>
|
||
{% endif %}
|
||
</td>
|
||
|
||
</tr>
|
||
{% endfor %}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
{% else %}
|
||
<div class="notification is-warning is-light has-text-centered my-5">
|
||
هیچ سابقه چک یا نسیهای برای این مشتری ثبت نشده است.
|
||
</div>
|
||
{% endif %}
|
||
|
||
</div>
|
||
|
||
<form class="modal modalAddNew" method="post" action="{% url 'admin_panel:addSarresid' customer.id %}" id="addSarresidForm">
|
||
{% csrf_token %}
|
||
<div class="modal-background"></div>
|
||
<div class="modal-card">
|
||
<header class="modal-card-head">
|
||
<p class="modal-card-title">ثبت سررسید / چک جدید</p>
|
||
<button type="button" class="delete" aria-label="close"></button>
|
||
</header>
|
||
<section class="modal-card-body">
|
||
|
||
<div class="field">
|
||
<label class="label">نوع سند <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<div class="select is-fullwidth">
|
||
<select required class="reset_input" name="n_sarresidType" id="sarresidTypeSelect">
|
||
<option value="">انتخاب کنید...</option>
|
||
<option value="check">چک بانکی</option>
|
||
<option value="nesiye">نسیه / حساب دفتری</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label class="label">مبلغ (تومان) <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<input id="formattedPriceInput" required class="input reset_input comma-separator" type="text" inputmode="numeric" placeholder="مثال: ۱,۰۰۰,۰۰۰">
|
||
<input type="hidden" name="n_sarresidPrice" id="realPriceInput" class="reset_input">
|
||
<span class="price-preview" id="priceInWords"></span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label class="label">تاریخ سررسید <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<input required class="input reset_input" id="NewSarResid" type="text" autocomplete="off" readonly style="cursor: pointer;" placeholder="برای انتخاب تاریخ کلیک کنید">
|
||
</div>
|
||
</div>
|
||
|
||
<input type="hidden" name="n_sarresidDateTime" id="NewSarResidVal" class="reset_input">
|
||
|
||
<div id="check_extra_fields" class="inquiry-box" style="display: none;">
|
||
<p class="has-text-weight-bold mb-3 has-text-info">اطلاعات چک صیادی</p>
|
||
|
||
<div class="field">
|
||
<label class="label">شماره ردیف / سریال چک <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<input name="check_row_number" class="input reset_input is-required-check" type="text" placeholder="مثال: 123456">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label class="label">شناسه صیادی (۱۶ رقم) <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<input id="new_check_sayyad" name="check_sayyad_id" class="input reset_input is-required-check sayyad-input-dynamic" data-target="new" type="text" inputmode="numeric" pattern="[0-9]{16}" minlength="16" maxlength="16" placeholder="فقط اعداد ۱۶ رقمی را وارد کنید تا استعلام خودکار انجام شود...">
|
||
</div>
|
||
<div id="new_inquiry_results" class="mt-3" style="display:none;"></div>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label class="label">نام و نامخانوادگی صاحب حساب <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<input name="check_owner_name" id="new_check_owner" class="input reset_input is-required-check" type="text" placeholder="نام مالک چک">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label class="label">تلفن مالک چک (اختیاری)</label>
|
||
<div class="control">
|
||
<input name="check_owner_phone" class="input reset_input" type="text" inputmode="numeric" pattern="[0-9]*" maxlength="11" placeholder="مثال: 09123456789">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</section>
|
||
<footer class="modal-card-foot">
|
||
<button type="submit" class="button is-success" id="new_submit_btn" style="display: none;">
|
||
<i class="fas fa-save ml-1"></i> ثبت اطلاعات
|
||
</button>
|
||
<span class="button cancellBTNSR">لغو</span>
|
||
</footer>
|
||
</div>
|
||
</form>
|
||
|
||
<form class="modal modalUpdateCheck" method="post" action="" id="updateCheckForm">
|
||
{% csrf_token %}
|
||
<div class="modal-background"></div>
|
||
<div class="modal-card">
|
||
<header class="modal-card-head">
|
||
<p class="modal-card-title">ویرایش و استعلام چک صیادی</p>
|
||
<button type="button" class="delete" aria-label="close"></button>
|
||
</header>
|
||
<section class="modal-card-body">
|
||
|
||
<div class="field">
|
||
<label class="label">شماره ردیف / سریال چک <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<input id="up_check_row" name="check_row_number" class="input reset_input" type="text" required placeholder="مثال: 123456">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label class="label">شناسه صیادی (۱۶ رقم) <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<input id="up_check_sayyad" name="check_sayyad_id" class="input reset_input sayyad-input-dynamic" data-target="up" type="text" required inputmode="numeric" pattern="[0-9]{16}" minlength="16" maxlength="16" placeholder="فقط اعداد ۱۶ رقمی را وارد کنید تا استعلام خودکار انجام شود...">
|
||
</div>
|
||
<div id="up_inquiry_results" class="mt-3" style="display:none;"></div>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label class="label">نام و نامخانوادگی صاحب حساب <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<input id="up_check_owner" name="check_owner_name" class="input reset_input" type="text" required placeholder="نام مالک چک">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label class="label">تلفن مالک چک (اختیاری)</label>
|
||
<div class="control">
|
||
<input id="up_check_phone" name="check_owner_phone" class="input reset_input" type="text" inputmode="numeric" pattern="[0-9]*" maxlength="11" placeholder="مثال: 09123456789">
|
||
</div>
|
||
</div>
|
||
|
||
</section>
|
||
<footer class="modal-card-foot">
|
||
<button type="submit" class="button is-info" id="up_submit_btn" style="display: none;">
|
||
<i class="fas fa-check ml-1"></i> ذخیره اطلاعات
|
||
</button>
|
||
<span class="button cancellBTNSR">لغو</span>
|
||
</footer>
|
||
</div>
|
||
</form>
|
||
|
||
<form class="modal nesiyeModal" method="post" action="{% url 'admin_panel:pardakhtNesiye' customer.id %}" id="pardakhtNesiyeForm">
|
||
{% csrf_token %}
|
||
<div class="modal-background"></div>
|
||
<div class="modal-card">
|
||
<header class="modal-card-head">
|
||
<p class="modal-card-title">پرداخت و تسویه نسیه</p>
|
||
<button type="button" class="delete" aria-label="close"></button>
|
||
</header>
|
||
<section class="modal-card-body">
|
||
|
||
<div class="field">
|
||
<label class="label">مانده فعلی از این نسیه (تومان)</label>
|
||
<div class="control">
|
||
<input id="priceBedehi" disabled class="input reset_input has-text-weight-bold" type="text">
|
||
</div>
|
||
</div>
|
||
|
||
<input name="sr_articlID" id="sr_articlID" class="input reset_input is-hidden" type="text">
|
||
|
||
<div class="field">
|
||
<label class="label">مبلغ پرداختی فعلی (تومان) <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<input id="formattedNextPriceInput" required class="input reset_input comma-separator" type="text" inputmode="numeric" placeholder="مبلغ واریزی">
|
||
<input type="hidden" name="next_sarresidPrice" id="realNextPriceInput" class="reset_input">
|
||
<span class="price-preview" id="nextPriceInWords"></span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label class="label">نحوه پرداخت <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<div class="select is-fullwidth">
|
||
<select required class="reset_input" name="nahvePardakht">
|
||
<option value="">انتخاب کنید...</option>
|
||
<option value="naghd">نقد</option>
|
||
<option value="kartbekart">کارت به کارت</option>
|
||
<option value="kartkhan">کارت خوان</option>
|
||
<option value="takhfif">تخفیف</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label class="label">سررسید بعدی (برای مابقی حساب) <span class="has-text-danger">*</span></label>
|
||
<div class="control">
|
||
<input required class="input reset_input" id="NextSarResid" type="text" autocomplete="off" readonly style="cursor: pointer;">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="field">
|
||
<label class="label">توضیحات</label>
|
||
<div class="control">
|
||
<textarea name="desc_sar" class="input reset_input" rows="2" placeholder="توضیحات اختیاری..."></textarea>
|
||
</div>
|
||
</div>
|
||
|
||
<input type="hidden" name="next_sarresidDateTime" id="NextSarResidVal" class="reset_input">
|
||
|
||
</section>
|
||
<footer class="modal-card-foot">
|
||
<button type="submit" class="button is-success">ثبت و بروزرسانی</button>
|
||
<span class="button cancellBTNSR">لغو</span>
|
||
</footer>
|
||
</div>
|
||
</form>
|
||
|
||
<script>
|
||
$(document).ready(function() {
|
||
|
||
// ----------------------------------------------------
|
||
// جستجوگر زنده (Real-time Search)
|
||
// ----------------------------------------------------
|
||
$("#checkSearchInput").on("keyup", function() {
|
||
var value = $(this).val().toLowerCase();
|
||
$("#sarresidTable tbody tr").filter(function() {
|
||
var searchData = $(this).find('.search-row-num, .search-sayyad-id').text().toLowerCase();
|
||
$(this).toggle(searchData.indexOf(value) > -1);
|
||
});
|
||
});
|
||
|
||
// ----------------------------------------------------
|
||
// فرمتبندی اعداد (۳ رقم ۳ رقم)
|
||
// ----------------------------------------------------
|
||
function formatNumber(num) {
|
||
if (!num) return "0";
|
||
return num.toString().replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||
}
|
||
|
||
$(document).on('input', '.comma-separator', function() {
|
||
let val = $(this).val();
|
||
let rawVal = val.replace(/,/g, '');
|
||
|
||
if (rawVal && !isNaN(rawVal)) {
|
||
$(this).val(formatNumber(rawVal));
|
||
if ($(this).attr('id') === 'formattedPriceInput') {
|
||
$('#realPriceInput').val(rawVal);
|
||
$('#priceInWords').text(formatNumber(rawVal) + ' تومان');
|
||
} else if ($(this).attr('id') === 'formattedNextPriceInput') {
|
||
$('#realNextPriceInput').val(rawVal);
|
||
$('#nextPriceInWords').text(formatNumber(rawVal) + ' تومان');
|
||
}
|
||
} else {
|
||
$(this).val('');
|
||
$('#realPriceInput, #realNextPriceInput').val('');
|
||
$('#priceInWords, #nextPriceInWords').text('');
|
||
}
|
||
});
|
||
|
||
// ----------------------------------------------------
|
||
// تبدیل JSON ثبت پاسارگاد به حالت خوانا و فارسی
|
||
// ----------------------------------------------------
|
||
function parseSabtData(dataObj) {
|
||
if (typeof dataObj === 'string') {
|
||
try { dataObj = JSON.parse(dataObj); } catch(e) { return dataObj; }
|
||
}
|
||
|
||
let onGoing = dataObj.onGoingAmount || 0;
|
||
let blocked = dataObj.blocked || 0;
|
||
let bounced = 0;
|
||
let cleared = 0;
|
||
|
||
if (dataObj.ownersInfo && dataObj.ownersInfo.length > 0) {
|
||
bounced = dataObj.ownersInfo[0].bouncedAmount || 0;
|
||
cleared = dataObj.ownersInfo[0].clearedAmount || 0;
|
||
}
|
||
|
||
// تبدیل از ریال به تومان (تقسیم بر ۱۰) و جدا کردن با کاما
|
||
let onGoingToman = formatNumber(onGoing / 10);
|
||
let blockedToman = formatNumber(blocked / 10);
|
||
let bouncedToman = formatNumber(bounced / 10);
|
||
let clearedToman = formatNumber(cleared / 10);
|
||
|
||
let colorClassSabt = bounced > 0 ? "is-danger" : "is-success";
|
||
|
||
return `
|
||
<div class="notification is-light ${colorClassSabt} py-3 px-4 mb-2 is-size-7">
|
||
<p class="mb-2"><strong><i class="fas fa-file-signature"></i> وضعیت ثبت در صیاد:</strong></p>
|
||
<ul style="list-style: none; margin: 0; padding: 0; line-height: 2;">
|
||
<li><i class="fas fa-money-bill-wave has-text-info"></i> <b>مبلغ در جریان:</b> <span dir="ltr">${onGoingToman}</span> تومان</li>
|
||
<li><i class="fas fa-ban has-text-danger"></i> <b>مبلغ مسدودی:</b> <span dir="ltr">${blockedToman}</span> تومان</li>
|
||
<li><i class="fas fa-exclamation-triangle has-text-warning"></i> <b>مبلغ برگشتی:</b> <span dir="ltr">${bouncedToman}</span> تومان</li>
|
||
<li><i class="fas fa-check-circle has-text-success"></i> <b>مبلغ پاس شده:</b> <span dir="ltr">${clearedToman}</span> تومان</li>
|
||
</ul>
|
||
</div>
|
||
`;
|
||
}
|
||
|
||
// ----------------------------------------------------
|
||
// استعلام خودکار با تایپ شدن کامل ۱۶ رقم صیادی
|
||
// ----------------------------------------------------
|
||
$(".sayyad-input-dynamic").on("input", function() {
|
||
let val = $(this).val();
|
||
let target = $(this).data('target'); // 'new' یا 'up'
|
||
let resultsContainer = $(`#${target}_inquiry_results`);
|
||
let submitBtn = $(`#${target}_submit_btn`);
|
||
|
||
// اگر طول رشته کمتر یا بیشتر از ۱۶ بود دکمه ثبت و نتایج را مخفی کن
|
||
if (val.length !== 16) {
|
||
resultsContainer.hide().html('');
|
||
submitBtn.hide();
|
||
return;
|
||
}
|
||
|
||
// به محض رسیدن به ۱۶ رقم، استعلامها شروع میشود
|
||
let sayad_id = val;
|
||
|
||
resultsContainer.show().html(`
|
||
<div class="notification is-light is-info py-2 px-3 mb-2 is-size-7">
|
||
<i class="fas fa-spinner fa-spin"></i> در حال برقراری ارتباط با سامانههای بانک مرکزی و صیاد...
|
||
</div>
|
||
`);
|
||
submitBtn.hide();
|
||
|
||
let req1_CBI = $.ajax({
|
||
url: "{% url 'admin_panel:api_check_status_inquiry' %}",
|
||
data: { sayad_id: sayad_id },
|
||
method: "GET"
|
||
});
|
||
|
||
let req2_SABT = $.ajax({
|
||
url: "{% url 'admin_panel:api_check_sabt_inquiry' %}",
|
||
data: { sayad_id: sayad_id, national_id: '', id_type: 1 },
|
||
method: "GET"
|
||
});
|
||
|
||
// مدیریت همزمان هر دو درخواست
|
||
$.when(req1_CBI, req2_SABT).done(function(cbiResArray, sabtResArray) {
|
||
let resCBI = cbiResArray[0];
|
||
let resSABT = sabtResArray[0];
|
||
|
||
let htmlOutput = "";
|
||
|
||
// --- تحلیل نتیجه بانک مرکزی (رنگ چک) ---
|
||
if (resCBI.success && resCBI.data) {
|
||
let colorClassCBI = "is-info";
|
||
let statusText = resCBI.data.status || "";
|
||
|
||
// برطرف کردن باگ فاصلههای زیاد و مخفی در نام صاحب حساب
|
||
let ownerNameClean = (resCBI.data.owner_name || "").replace(/ /ig, ' ').replace(/\s+/g, ' ').trim();
|
||
|
||
if (statusText.includes("سفید")) colorClassCBI = "is-success";
|
||
else if (statusText.includes("زرد") || statusText.includes("نارنجی")) colorClassCBI = "is-warning";
|
||
else if (statusText.includes("قرمز") || statusText.includes("قهوه ای") || statusText.includes("برگشت")) colorClassCBI = "is-danger";
|
||
|
||
htmlOutput += `
|
||
<div class="notification is-light ${colorClassCBI} py-2 px-3 mb-2 is-size-7">
|
||
<strong><i class="fas fa-university"></i> وضعیت حساب صادرکننده در بانک مرکزی:</strong>
|
||
<br>وضعیت چک: <b>${statusText}</b>
|
||
<br>مالک حساب: <b>${ownerNameClean}</b>
|
||
</div>
|
||
`;
|
||
|
||
// بهروزرسانی فیلد نام صاحب حساب با متن اصلاحشده و بدون فاصله اضافی
|
||
$(`#${target}_check_owner`).val(ownerNameClean);
|
||
|
||
} else {
|
||
htmlOutput += `
|
||
<div class="notification is-light is-danger py-2 px-3 mb-2 is-size-7">
|
||
<strong><i class="fas fa-exclamation-triangle"></i> خطا (بانک مرکزی):</strong> ${resCBI.error || 'ارتباط با بانک مرکزی برقرار نشد'}
|
||
</div>
|
||
`;
|
||
|
||
// در صورت وجود خطا در استعلام، فیلد نام صاحب حساب خالی شود
|
||
$(`#${target}_check_owner`).val('');
|
||
}
|
||
|
||
// --- تحلیل نتیجه سامانه ثبت صیاد ---
|
||
if (resSABT.success && resSABT.data) {
|
||
htmlOutput += parseSabtData(resSABT.data);
|
||
} else {
|
||
let sabtErrorMsg = resSABT.error || 'سیستم استعلام ثبت در دسترس نیست';
|
||
|
||
// بررسی خطای کد 524 و عدم ثبت چک توسط صادرکننده
|
||
if (sabtErrorMsg.includes("کارتابل مشتري وجود ندارد") || sabtErrorMsg.includes("524")) {
|
||
sabtErrorMsg = "مشتری هنوز چک را برای شما (کد ملی 1219968218) ثبت نکرده، از مشتری بخواهید چک را ثبت کند.";
|
||
}
|
||
|
||
htmlOutput += `
|
||
<div class="notification is-light is-warning py-2 px-3 mb-2 is-size-7">
|
||
<strong><i class="fas fa-exclamation-triangle"></i> خطا (استعلام ثبت):</strong> ${sabtErrorMsg}
|
||
</div>
|
||
`;
|
||
}
|
||
|
||
// نمایش نتایج و نمایش دادن دکمه ثبت
|
||
resultsContainer.html(htmlOutput);
|
||
submitBtn.fadeIn();
|
||
|
||
}).fail(function() {
|
||
// در صورتی که کلا اینترنت سرور یا ریکوئست ایجکس فیِل شود
|
||
resultsContainer.html(`
|
||
<div class="notification is-light is-danger py-2 px-3 mb-2 is-size-7">
|
||
<strong><i class="fas fa-wifi"></i> خطای سرور در برقراری ارتباط با سامانههای استعلام (احتمالا کپچا یا قطعی شبکه)</strong>
|
||
</div>
|
||
`);
|
||
|
||
// در صورت خطای کلی شبکه یا سرور، نام صاحب حساب پاک شود
|
||
$(`#${target}_check_owner`).val('');
|
||
|
||
// با وجود خطا، دکمه ذخیره را نمایش میدهیم تا کاربر بتواند اطلاعات را دستی ذخیره کند
|
||
submitBtn.fadeIn();
|
||
});
|
||
});
|
||
|
||
// ----------------------------------------------------
|
||
// مدیریت فرم و نمایش دینامیک باکس چک
|
||
// ----------------------------------------------------
|
||
$("#sarresidTypeSelect").change(function(){
|
||
let selectedType = $(this).val();
|
||
if(selectedType === "check") {
|
||
$("#check_extra_fields").slideDown(250);
|
||
$(".is-required-check").prop('required', true);
|
||
} else {
|
||
$("#check_extra_fields").slideUp(250);
|
||
$(".is-required-check").prop('required', false);
|
||
$("#check_extra_fields input").val('');
|
||
$("#new_inquiry_results").hide().html('');
|
||
// برای نسیه دکمه ثبت مستقیما باز میشود
|
||
$("#new_submit_btn").show();
|
||
}
|
||
});
|
||
|
||
// ----------------------------------------------------
|
||
// حذف پیامهای سیستم
|
||
// ----------------------------------------------------
|
||
$('.notification .delete').click(function() {
|
||
$(this).parent().fadeOut();
|
||
});
|
||
|
||
// ----------------------------------------------------
|
||
// مودالها و باز و بسته شدن آنها
|
||
// ----------------------------------------------------
|
||
$("#newSarresid").click(function(){
|
||
$(".modalAddNew").addClass("is-active");
|
||
$("#new_submit_btn").hide(); // پیشفرض مخفی تا نوع سند انتخاب شود
|
||
});
|
||
|
||
// رویداد کلیک برای باز کردن مُدال ویرایش
|
||
$(".btn-update-check").click(function(){
|
||
let sarresidId = $(this).data('id');
|
||
let rowNum = $(this).data('row');
|
||
let sayyadId = $(this).data('sayyad');
|
||
let ownerName = $(this).data('owner');
|
||
let ownerPhone = $(this).data('phone');
|
||
|
||
// مقداردهی فرم با اطلاعات قبلی
|
||
$("#up_check_row").val(rowNum !== 'None' ? rowNum : '');
|
||
$("#up_check_sayyad").val(sayyadId !== 'None' ? sayyadId : '');
|
||
$("#up_check_owner").val(ownerName !== 'None' ? ownerName : '');
|
||
$("#up_check_phone").val(ownerPhone !== 'None' ? ownerPhone : '');
|
||
|
||
// تنظیم آدرس (Action) فرم برای این آیدی خاص
|
||
$("#updateCheckForm").attr('action', '/panel/sarresid/update-check-info/' + sarresidId);
|
||
|
||
// باز کردن مُدال
|
||
$(".modalUpdateCheck").addClass("is-active");
|
||
|
||
// اگر شناسه صیادی از قبل ۱۶ رقم است، استعلام خودکار فراخوانی شود
|
||
if ($("#up_check_sayyad").val().length === 16) {
|
||
$("#up_check_sayyad").trigger("input");
|
||
} else {
|
||
$("#up_submit_btn").show(); // اگر ناقص بود دکمه را نشان بده تا ویرایش کند
|
||
}
|
||
});
|
||
|
||
// بستن تمامی مدالها
|
||
$(".modal-background, .delete, .cancellBTNSR").click(function(){
|
||
$(".modal").removeClass("is-active");
|
||
$('.reset_input').not(':hidden').val('');
|
||
$('#priceInWords, #nextPriceInWords').text('');
|
||
$("#check_extra_fields").hide();
|
||
$(".is-required-check").prop('required', false);
|
||
$("#new_inquiry_results, #up_inquiry_results").hide().html('');
|
||
$("#new_submit_btn, #up_submit_btn").hide();
|
||
});
|
||
|
||
// ----------------------------------------------------
|
||
// تقویم شمسی
|
||
// ----------------------------------------------------
|
||
$("#NewSarResid").pDatepicker({
|
||
initialValue: false,
|
||
initialValueType: 'en',
|
||
format: 'YYYY/MM/DD',
|
||
autoClose: true,
|
||
calendar: {
|
||
persian: { locale: 'fa' }
|
||
},
|
||
onSelect: function(unix){
|
||
$("#NewSarResidVal").val(unix);
|
||
}
|
||
});
|
||
|
||
$("#NextSarResid").pDatepicker({
|
||
initialValue: false,
|
||
initialValueType: 'en',
|
||
format: 'YYYY/MM/DD',
|
||
autoClose: true,
|
||
calendar: {
|
||
persian: { locale: 'fa' }
|
||
},
|
||
onSelect: function(unix){
|
||
$("#NextSarResidVal").val(unix);
|
||
}
|
||
});
|
||
|
||
// ----------------------------------------------------
|
||
// اعتبارپردازی و اطمینان از مقداردهی قبل از Submit
|
||
// ----------------------------------------------------
|
||
$("#addSarresidForm").on("submit", function(e) {
|
||
if(!$("#NewSarResidVal").val()){
|
||
alert("لطفاً تاریخ سررسید را انتخاب کنید.");
|
||
e.preventDefault();
|
||
return false;
|
||
}
|
||
});
|
||
|
||
$("#pardakhtNesiyeForm").on("submit", function(e) {
|
||
if(!$("#NextSarResidVal").val()){
|
||
alert("لطفاً تاریخ سررسید بعدی را انتخاب کنید.");
|
||
e.preventDefault();
|
||
return false;
|
||
}
|
||
});
|
||
|
||
// ----------------------------------------------------
|
||
// عملیات وصول شد
|
||
// ----------------------------------------------------
|
||
$(".VosolButton").click(function(){
|
||
var articlID = $(this).attr("articlID");
|
||
var type = $(this).attr("type");
|
||
var price = $(this).attr("price");
|
||
|
||
if(type === "check"){
|
||
if( confirm('آیا از وصول شدن این چک بانکی اطمینان دارید؟') ){
|
||
if( confirm('با تایید شما، سند حسابداری تسویه این چک ثبت خواهد شد.') ){
|
||
window.location.href = '/panel/passCheck/' + articlID;
|
||
}
|
||
}
|
||
} else {
|
||
$(".nesiyeModal").addClass("is-active");
|
||
$("#priceBedehi").val(formatNumber(price));
|
||
$("#sr_articlID").val(articlID);
|
||
}
|
||
});
|
||
|
||
});
|
||
</script>
|
||
|
||
{% endblock %} |