فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

ui(A01): let treasury operator link receipts and refunds to posted invoices

davoodmehraban89 committed Oct 17, 2026 at 00:44 UTC 1aff1397ec0a0dfe7c24a41cc22ee385e673959d
1 file changed +36 -1
src/views/TreasuryView.js
+36 -1
@@ -12,7 +12,7 @@ import { NumberInput } from '../utils/NumberInput.js';
12
13 let currentTab = 'accounts';
14 let txFilter = { search: '', type: '', accountId: '' };
15 -let cache = { accounts: [], balances: {}, transactions: [], contacts: [] };
15 +let cache = { accounts: [], balances: {}, transactions: [], contacts: [], invoices: [] };
16
17 class TreasuryViewImpl {
18 async render() {
@@ -45,6 +45,7 @@ class TreasuryViewImpl {
45 cache.balances = await TreasuryController.getBalanceMap();
46 cache.transactions = await TreasuryController.getTransactions();
47 cache.contacts = await ContactController.getAll();
48 + cache.invoices = await InvoiceController.getAll();
49 }
50
51 _switchTab(tab, btn) {
@@ -407,6 +408,25 @@ class TreasuryViewImpl {
408 ).join('');
409 }
410
411 +
412 + _buildInvoiceOptions(type) {
413 + const kinds=type==='receipt'
414 + ? ['sale','non_formal','purchase_return']
415 + : ['purchase','sale_return'];
416 + const invoices=cache.invoices.filter(row=>
417 + row.financePosted && !row.isPreInvoice && kinds.includes(row.kind) &&
418 + Number(row.remaining)>0);
419 + return '<option value="">— دریافت/پرداخت مستقل (بدون اتصال فاکتور) —</option>' +
420 + invoices.map(row => `<option value="${this._esc(row.id)}">#${this._esc(row.number)} — ${this._esc(row.contactName||'بدون نام')} (${Formatters.number(row.remaining)} ریال)</option>`).join('');
421 + }
422 +
423 + _onInvoiceSelection() {
424 + const id=document.getElementById('txInvoiceRef')?.value;
425 + const row=cache.invoices.find(x=>x.id===id);
426 + const contact=document.getElementById('txContact');
427 + if(row?.contactId && contact) contact.value=row.contactId;
428 + }
429 +
430 openReceiptModal() {
431 if (cache.accounts.length === 0) {
432 Toast.warning('ابتدا یک حساب یا صندوق تعریف کنید');
@@ -432,6 +452,13 @@ class TreasuryViewImpl {
452 </select>
453 </div>
454
455 + <div class="form-group">
456 + <label class="form-label">فاکتور مرتبط (اختیاری)</label>
457 + <select class="form-control" id="txInvoiceRef" onchange="window.TreasuryView._onInvoiceSelection()">
458 + ${this._buildInvoiceOptions('receipt')}
459 + </select>
460 + </div>
461 +
462 <div class="form-group">
463 <label class="form-label">به حساب <span class="req">*</span></label>
464 <select class="form-control" id="txToAccount">${this._buildAccountOptions()}</select>
@@ -483,6 +510,13 @@ class TreasuryViewImpl {
510 </select>
511 </div>
512
513 + <div class="form-group">
514 + <label class="form-label">فاکتور مرتبط / بازپرداخت (اختیاری)</label>
515 + <select class="form-control" id="txInvoiceRef" onchange="window.TreasuryView._onInvoiceSelection()">
516 + ${this._buildInvoiceOptions('payment')}
517 + </select>
518 + </div>
519 +
520 <div class="form-group">
521 <label class="form-label">از حساب <span class="req">*</span></label>
522 <select class="form-control" id="txFromAccount">${this._buildAccountOptions()}</select>
@@ -563,6 +597,7 @@ class TreasuryViewImpl {
597 method: document.getElementById('txMethod')?.value || 'cash',
598 contactId,
599 contactName: contact?.name || '',
600 + refInvoiceId: document.getElementById('txInvoiceRef')?.value || null,
601 fromAccountId: document.getElementById('txFromAccount')?.value || null,
602 toAccountId: document.getElementById('txToAccount')?.value || null,
603 description: document.getElementById('txDescription')?.value || ''