-
Wszystkie statusy
@@ -190,7 +193,8 @@ include '../../header-travel.php';
Nierozliczone
- Przypisz fakturę
+ Przypisz fakturę
@@ -216,7 +220,8 @@ include '../../header-travel.php';
-
Szczegóły
Rozliczone
- Szczegóły
-
+
+ Szczegóły
+
@@ -280,11 +292,18 @@ include '../../header-travel.php';
Rozliczone
- Szczegóły
-
+
+ Szczegóły
+
@@ -309,7 +328,8 @@ include '../../header-travel.php';
Nierozliczone
- Przypisz fakturę
+ Przypisz fakturę
@@ -334,7 +354,8 @@ include '../../header-travel.php';
rozliczone
-
Szczegóły
Rozliczone
- Szczegóły
-
+
+ Szczegóły
+
@@ -398,7 +426,8 @@ include '../../header-travel.php';
Nierozliczone
- Przypisz fakturę
+ Przypisz fakturę
@@ -424,7 +453,8 @@ include '../../header-travel.php';
rozliczone
-
Szczegóły
Rozliczone
- Szczegóły
-
+
+ Szczegóły
+
@@ -582,6 +618,122 @@ include '../../header-travel.php';
+
+
+
+
+
+
+
+ Nazwa
+ pozycji
+
+ Ilość
+
+ J.m.
+
+ Cena netto
+
+ VAT
+
+ Kwota VAT
+
+ Kwota brutto
+
+
+
+
+ Przejazd autokarowy Warszawa–Zakopane (gr. 24 os.)
+
+ 24
+ os.
+ 2 600,00
+ 8%
+ 208,00
+ 2 808,00
+
+
+ Przejazd autokarowy Zakopane–Warszawa (gr. 24 os.)
+
+ 24
+ os.
+ 600,00
+ 8%
+ 48,00
+ 648,00
+
+
+ Opłata za rezerwację + obsługa
+ 1
+ szt.
+ 214,63
+ 23%
+ 49,37
+ 264,00
+
+
+ Razem
+ 3 414,63
+
+ 785,37
+ 4 200,00 PLN
+
+
+
+
+
+
+
+
+ Suma przypisanych pozycji musi być równa kwocie faktury.
+
+
Wróć
-
+
Zapisz i Powiąż
@@ -1041,7 +1313,115 @@ include '../../header-travel.php';
// Zmiana na radio w tabeli, aby można było wybrać tylko jedno
document.querySelectorAll('input[name="orderSelect"]').forEach(el => el.type = 'radio');
}
+
+ updateSplitAmountSummary();
}
+
+ function formatPln(value) {
+ return value.toLocaleString('pl-PL', {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2
+ }) + ' PLN';
+ }
+
+ function getInvoiceGrossAmount() {
+ const invoiceInput = document.getElementById('invoiceGrossAmount');
+ const amount = parseFloat(invoiceInput ? invoiceInput.value : 0);
+ return Number.isFinite(amount) ? amount : 0;
+ }
+
+ function updateSplitAmountSummary() {
+ const isSplit = document.getElementById('assignSplit')?.checked;
+ const totalRow = document.getElementById('splitTotalRow');
+ const totalValue = document.getElementById('splitTotalValue');
+ const alertBox = document.getElementById('splitValidationAlert');
+ const saveBtn = document.getElementById('btnSaveAssign');
+
+ if (!isSplit) {
+ totalRow?.classList.add('d-none');
+ alertBox?.classList.add('d-none');
+ if (saveBtn) saveBtn.disabled = false;
+ return;
+ }
+
+ let sum = 0;
+ document.querySelectorAll('#step-assign .table-responsive table tbody tr').forEach(function (row) {
+ const selector = row.querySelector('input[name="orderSelect"]');
+ const amountInput = row.querySelector('.split-amount-input');
+ if (!selector || !amountInput || !selector.checked) return;
+ const value = parseFloat(amountInput.value);
+ if (Number.isFinite(value)) sum += value;
+ });
+
+ const invoiceAmount = getInvoiceGrossAmount();
+ const isMatch = Math.abs(sum - invoiceAmount) < 0.01;
+
+ totalRow?.classList.remove('d-none');
+ if (totalValue) {
+ totalValue.textContent = formatPln(sum);
+ totalValue.classList.toggle('text-danger', !isMatch);
+ totalValue.classList.toggle('text-success', isMatch);
+ }
+
+ alertBox?.classList.toggle('d-none', isMatch);
+ if (saveBtn) saveBtn.disabled = !isMatch;
+ }
+
+ function updateSuggestedOrder() {
+ const tbody = document.querySelector('#step-assign .table-responsive table tbody');
+ if (!tbody) return;
+
+ const rows = Array.from(tbody.querySelectorAll('.assign-order-row'));
+ if (!rows.length) return;
+
+ const invoiceAmount = getInvoiceGrossAmount();
+ let bestRow = null;
+ let bestDiff = Number.POSITIVE_INFINITY;
+
+ rows.forEach(function (row) {
+ row.classList.remove('table-success');
+ row.querySelectorAll('.order-suggestion-badge').forEach(function (badge) {
+ badge.classList.add('d-none');
+ });
+
+ const orderAmount = parseFloat(row.dataset.orderAmount || '0');
+ const diff = Math.abs(orderAmount - invoiceAmount);
+ if (diff < bestDiff) {
+ bestDiff = diff;
+ bestRow = row;
+ }
+ });
+
+ if (!bestRow) return;
+ tbody.prepend(bestRow);
+ bestRow.classList.add('table-success');
+ bestRow.querySelectorAll('.order-suggestion-badge').forEach(function (badge) {
+ badge.classList.remove('d-none');
+ });
+ }
+
+ document.querySelectorAll('input[name="orderSelect"], .split-amount-input').forEach(function (el) {
+ el.addEventListener('change', updateSplitAmountSummary);
+ el.addEventListener('input', updateSplitAmountSummary);
+ });
+
+ document.querySelectorAll('.split-amount-input').forEach(function (input) {
+ input.addEventListener('input', function () {
+ const row = input.closest('tr');
+ const selector = row ? row.querySelector('input[name="orderSelect"]') : null;
+ const value = parseFloat(input.value);
+ if (selector && Number.isFinite(value) && value > 0) {
+ selector.checked = true;
+ }
+ });
+ });
+
+ document.getElementById('invoiceGrossAmount')?.addEventListener('input', function () {
+ updateSplitAmountSummary();
+ updateSuggestedOrder();
+ });
+ updateSuggestedOrder();
+ updateSplitAmountSummary();