535 lines
28 KiB
PHP
535 lines
28 KiB
PHP
<?php
|
|
$enablePrototypeComments = false;
|
|
include '../../header-invoice.php';
|
|
?>
|
|
|
|
<div class="container-fluid flex-grow-1 container-p-y">
|
|
|
|
<div
|
|
class="d-flex flex-column flex-md-row justify-content-between align-items-start align-items-md-center mb-4 gap-3">
|
|
<div class="d-flex flex-column justify-content-center">
|
|
<h4 class="mb-1 text-body">Nowa Faktura Zakupowa</h4>
|
|
<p class="text-muted mb-0">Wprowadź koszt firmowy</p>
|
|
</div>
|
|
<div class="d-flex align-content-center flex-wrap gap-2">
|
|
<a href="app-purchase-list.php" class="btn btn-label-secondary">Anuluj</a>
|
|
<button type="submit" form="invoiceForm" class="btn btn-primary"><i class="bx bx-save me-1"></i> Zapisz
|
|
fakturę</button>
|
|
</div>
|
|
</div>
|
|
|
|
<form id="invoiceForm" onsubmit="return false">
|
|
|
|
<div class="row mb-4">
|
|
|
|
<!-- Left Column: Seller & Buyer -->
|
|
<div class="col-lg-5 col-md-12 mb-3 mb-lg-0">
|
|
|
|
<!-- Buyer Card -->
|
|
<div class="card bg-label-secondary border-0 mb-3">
|
|
<div class="card-body p-3 d-flex flex-column justify-content-center text-center">
|
|
<div class="avatar mx-auto mb-2">
|
|
<span class="avatar-initial rounded bg-white text-secondary"><i
|
|
class="bx bx-building-house fs-4"></i></span>
|
|
</div>
|
|
<h6 class="card-title mb-1 text-nowrap">Nabywca</h6>
|
|
<small class="d-block fw-bold text-truncate">Magico Software</small>
|
|
<small class="text-muted text-truncate">NIP: 8652582386</small>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Seller Card -->
|
|
<div class="card mb-3">
|
|
<div class="card-header border-bottom py-3">
|
|
<h6 class="card-title m-0"><i class="bx bx-store-alt me-2"></i>Sprzedawca</h6>
|
|
</div>
|
|
<div class="card-body pt-3">
|
|
<div class="card shadow-none border mb-3 position-relative">
|
|
<div class="card-body p-3 d-flex justify-content-between align-items-center"
|
|
style="min-height: 80px;">
|
|
<i class="text-muted">Wybierz dostawcę z listy...</i>
|
|
<button class="btn btn-outline-primary btn-sm position-absolute end-0 top-0 m-2"><i
|
|
class="bx bx-search"></i></button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="d-flex flex-column gap-2">
|
|
<label class="form-check form-switch m-0">
|
|
<input class="form-check-input" type="checkbox" id="descToggle">
|
|
<span class="form-check-label text-muted">Dodatkowy opis dostawcy</span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<!-- Right Column: Document Data -->
|
|
<div class="col-lg-7 col-12">
|
|
<div class="card h-100">
|
|
<div class="card-header border-bottom py-3">
|
|
<h6 class="card-title m-0"><i class="bx bx-file me-2"></i>Dane Dokumentu</h6>
|
|
</div>
|
|
<div class="card-body pt-3">
|
|
|
|
<!-- OCR Dropzone -->
|
|
<div class="dropzone p-4 border-dashed border-2 rounded text-center mb-3 d-flex flex-column justify-content-center align-items-center"
|
|
style="border-color: #d9dee3; background-color: #f8f9fa; cursor: pointer; transition: 0.2s;"
|
|
onmouseover="this.style.borderColor='#696cff'; this.style.backgroundColor='#f0f2ff';"
|
|
onmouseout="this.style.borderColor='#d9dee3'; this.style.backgroundColor='#f8f9fa';">
|
|
<i class="bx bx-cloud-upload fs-2 text-muted mb-2"></i>
|
|
<span class="text-muted fw-bold">Przeciągnij fakturę tutaj lub kliknij</span>
|
|
<span class="small text-muted">(PDF, JPG, PNG)</span>
|
|
</div>
|
|
<button type="button" class="btn btn-label-primary w-100 mb-4" id="btn-ocr-read-page">
|
|
<i class="bx bx-scan me-1"></i> Odczytaj dane z pliku (OCR)
|
|
</button>
|
|
|
|
<!-- KSeF Info Block -->
|
|
<div class="mb-4 p-3 bg-label-secondary rounded border-dashed border-2">
|
|
<div class="d-flex align-items-center mb-2 justify-content-between">
|
|
<div class="d-flex align-items-center">
|
|
<i class="bx bx-shield-quarter me-2 text-success"></i>
|
|
<span class="fw-bold small">DANE SYSTEMU KSeF</span>
|
|
</div>
|
|
<span class="badge bg-white text-success shadow-sm">ZWERYFIKOWANA</span>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="small text-muted d-block mb-1">Numer identyfikacyjny:</label>
|
|
<code class="p-2 bg-white border rounded d-block text-dark small fw-bold"
|
|
style="word-break: break-all;">8652582386-20260120-0C7F00A11237-B1</code>
|
|
</div>
|
|
<div class="row align-items-center gx-2">
|
|
<div class="col-auto">
|
|
<img src="https://api.qrserver.com/v1/create-qr-code/?size=90x90&data=KSEF_VERIFY_URL"
|
|
class="border p-1 bg-white rounded" alt="QR KSeF" width="60">
|
|
</div>
|
|
<div class="col">
|
|
<div class="d-flex gap-2 mb-2">
|
|
<button class="btn btn-sm btn-outline-primary w-100"><i
|
|
class="bx bx-download me-1"></i>PDF</button>
|
|
<button class="btn btn-sm btn-outline-primary w-100"><i
|
|
class="bx bx-download me-1"></i>UPO</button>
|
|
<button class="btn btn-sm btn-outline-secondary w-100"><i
|
|
class="bx bx-copy me-1"></i>Numer</button>
|
|
</div>
|
|
<small class="text-muted d-block" style="font-size: 0.7rem;">Faktura została pobrana
|
|
z KSeF i zweryfikowana poprawnie.</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-2 mb-3">
|
|
<div class="col-md-6">
|
|
<label class="form-label fw-bold">Numer faktury</label>
|
|
<input type="text" class="form-control" placeholder="np. FV/2026/02/105">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label small text-uppercase fw-bold text-muted">Data zakupu</label>
|
|
<input type="text" class="form-control date-picker" value="2026-02-17">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-2 mb-3">
|
|
<div class="col-6">
|
|
<label class="form-label small text-uppercase fw-bold text-muted">Data wyst.</label>
|
|
<input type="text" class="form-control date-picker" value="2026-02-17">
|
|
</div>
|
|
<div class="col-6">
|
|
<label class="form-label small text-uppercase fw-bold text-muted">Termin płat.</label>
|
|
<input type="text" class="form-control date-picker" value="2026-02-24">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-2 align-items-end">
|
|
<div class="col-5">
|
|
<label class="form-label small text-uppercase fw-bold text-muted">Metoda</label>
|
|
<select class="form-select">
|
|
<option value="przelew">Przelew</option>
|
|
<option value="gotowka">Gotówka</option>
|
|
<option value="karta">Karta</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-7">
|
|
<label class="form-label fw-bold">Zapłacono</label>
|
|
<div class="input-group">
|
|
<input type="number" id="paidInput" class="form-control" value="0.00">
|
|
<button class="btn btn-outline-primary px-2" type="button" id="payFullBtn"
|
|
data-bs-toggle="tooltip" title="Przepisz pełną kwotę">
|
|
Całość
|
|
</button>
|
|
<span class="input-group-text">PLN</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card mb-4">
|
|
<div
|
|
class="card-header bg-label-primary py-2 d-flex flex-wrap justify-content-between align-items-center gap-3">
|
|
<span class="fw-bold">Pozycje faktury</span>
|
|
|
|
<div class="d-flex align-items-center flex-wrap gap-3">
|
|
|
|
<div class="d-flex align-items-center">
|
|
<label class="text-muted small me-2 text-nowrap d-flex align-items-center">
|
|
Kategoria kosztu
|
|
<i class="bx bx-info-circle ms-1 text-primary cursor-pointer" data-bs-toggle="tooltip"
|
|
title="Listę kategorii możesz zdefiniować w: Ustawienia -> Słowniki"></i>
|
|
</label>
|
|
<select class="form-select form-select-sm" style="min-width: 150px;">
|
|
<option value="towary">Towary handlowe</option>
|
|
<option value="paliwo">Paliwo i eksploatacja</option>
|
|
<option value="biuro">Koszty biurowe</option>
|
|
<option value="uslugi">Usługi obce</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="vr h-100 my-auto text-muted"></div>
|
|
|
|
<div class="d-flex align-items-center">
|
|
<label class="text-muted small me-2 text-nowrap">Licz od:</label>
|
|
<select class="form-select form-select-sm" style="width: auto;">
|
|
<option value="brutto">Brutto</option>
|
|
<option value="netto">Netto</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered mb-0">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th style="width: 40px;" class="text-center">Lp</th>
|
|
<th style="min-width: 250px;">Nazwa kosztu / Towaru</th>
|
|
<th style="width: 120px;">Kod / PKWiU</th>
|
|
<th style="width: 90px;">JM</th>
|
|
<th style="width: 100px;">Ilość</th>
|
|
<th style="width: 130px;">Cena Netto</th>
|
|
<th style="width: 100px;">VAT</th>
|
|
<th style="width: 130px;" class="text-end">Wartość Netto</th>
|
|
<th style="width: 130px;" class="text-end">Wartość Brutto</th>
|
|
<th style="width: 50px;"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="align-middle text-center text-muted">1</td>
|
|
<td class="p-2">
|
|
<input type="text" class="form-control border-0 shadow-none fw-medium"
|
|
placeholder="Np. Usługa księgowa, Paliwo...">
|
|
</td>
|
|
<td class="p-2">
|
|
<input type="text" class="form-control border-0 shadow-none text-muted"
|
|
placeholder="-">
|
|
</td>
|
|
<td class="p-2">
|
|
<select class="form-select border-0 shadow-none px-1">
|
|
<option value="szt">szt.</option>
|
|
<option value="usl">usł.</option>
|
|
<option value="m3">m3</option>
|
|
<option value="litr">litr</option>
|
|
</select>
|
|
</td>
|
|
<td class="p-2">
|
|
<input type="number" class="form-control border-0 shadow-none text-center fw-bold"
|
|
value="1" step="0.01">
|
|
</td>
|
|
<td class="p-2">
|
|
<input type="number" class="form-control border-0 shadow-none text-end" value="0.00"
|
|
step="0.01">
|
|
</td>
|
|
<td class="p-2">
|
|
<select class="form-select border-0 shadow-none px-1">
|
|
<option value="23">23%</option>
|
|
<option value="8">8%</option>
|
|
<option value="5">5%</option>
|
|
<option value="0">0%</option>
|
|
<option value="zw">ZW</option>
|
|
</select>
|
|
</td>
|
|
<td class="align-middle text-end pe-3 bg-lighter">0,00 zł</td>
|
|
<td class="align-middle text-end pe-3 bg-lighter fw-bold">0,00 zł</td>
|
|
<td class="align-middle text-center p-2">
|
|
<button class="btn btn-icon btn-sm btn-label-danger"><i
|
|
class="bx bx-trash"></i></button>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="border-top p-3 text-end bg-light">
|
|
<button class="btn btn-primary btn-sm"><i class="bx bx-plus me-1"></i> Dodaj kolejną
|
|
pozycję</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-lg-7 mb-4 mb-lg-0">
|
|
<div class="card h-100">
|
|
<div class="card-body">
|
|
|
|
<label class="form-label">Uwagi do dokumentu (wewnętrzne)</label>
|
|
<textarea class="form-control bg-lighter" rows="3"
|
|
placeholder="Wpisz uwagi widoczne tylko dla nas..."></textarea>
|
|
|
|
<div class="row g-2 mb-3 mt-3">
|
|
<div class="col-md-4">
|
|
<label class="form-label d-flex align-items-center">
|
|
Waluta dokumentu
|
|
<i class="bx bx-info-circle ms-1 fs-6 text-muted" data-bs-toggle="tooltip"
|
|
data-bs-placement="top"
|
|
title="Waluta w jakiej została wystawiona faktura przez dostawcę.">
|
|
</i>
|
|
</label>
|
|
<select class="form-select">
|
|
<option value="PLN">PLN</option>
|
|
<option value="EUR">EUR</option>
|
|
<option value="USD">USD</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="col-md-5">
|
|
<label class="form-label d-flex align-items-center">
|
|
Przelicznik (Kurs)
|
|
<i class="bx bx-info-circle ms-1 fs-6 text-muted" data-bs-toggle="tooltip"
|
|
data-bs-placement="top"
|
|
title="Kurs waluty z dnia poprzedzającego wystawienie faktury.">
|
|
</i>
|
|
</label>
|
|
<div class="input-group">
|
|
<input type="number" id="exchangeRateInput" class="form-control" value="1.0000"
|
|
disabled>
|
|
<button class="btn btn-outline-secondary" type="button" id="unlockRateBtn"
|
|
data-bs-toggle="tooltip" title="Odblokuj edycję kursu">
|
|
<i class="bx bx-lock-open-alt"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="d-flex align-items-center mt-3">
|
|
<label class="form-check form-switch m-0">
|
|
<input class="form-check-input" type="checkbox" checked>
|
|
<span class="form-check-label">Podzielona płatność (MPP)</span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-lg-5">
|
|
<div class="card h-100">
|
|
<div class="card-body">
|
|
<h6 class="card-title mb-4">Podsumowanie</h6>
|
|
|
|
<div class="d-flex justify-content-between mb-2">
|
|
<span class="text-muted">Suma Netto:</span>
|
|
<span class="fw-semibold">0,00 zł</span>
|
|
</div>
|
|
<div class="d-flex justify-content-between mb-3 border-bottom pb-2">
|
|
<span class="text-muted">Suma VAT:</span>
|
|
<span class="fw-semibold">0,00 zł</span>
|
|
</div>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<span class="h5 mb-0">Do zapłaty:</span>
|
|
<span class="h4 mb-0 text-primary" id="finalTotal">0,00 zł</span>
|
|
</div>
|
|
|
|
<div class="alert alert-warning d-flex align-items-start align-items-sm-center mb-0"
|
|
role="alert">
|
|
<i class="bx bx-bell-ring me-2 fs-4 mt-1 mt-sm-0"></i>
|
|
<div class="small">
|
|
<strong>Status: Nierozliczona.</strong>
|
|
Faktura zostanie dodana do kalendarza płatności.
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
<div class="content-backdrop fade"></div>
|
|
|
|
|
|
<?php include '../../footer.php'; ?>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Inicjalizacja Datepickerów
|
|
if (typeof flatpickr !== 'undefined') {
|
|
document.querySelectorAll('.date-picker').forEach(picker => {
|
|
flatpickr(picker, { dateFormat: 'Y-m-d' });
|
|
});
|
|
}
|
|
|
|
// Tooltipy
|
|
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
|
|
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
|
return new bootstrap.Tooltip(tooltipTriggerEl)
|
|
});
|
|
|
|
// Obsługa odblokowania kursu waluty
|
|
const unlockBtn = document.getElementById('unlockRateBtn');
|
|
const rateInput = document.getElementById('exchangeRateInput');
|
|
if (unlockBtn && rateInput) {
|
|
unlockBtn.addEventListener('click', function () {
|
|
rateInput.disabled = !rateInput.disabled;
|
|
if (!rateInput.disabled) {
|
|
rateInput.focus();
|
|
unlockBtn.classList.remove('btn-outline-secondary');
|
|
unlockBtn.classList.add('btn-primary');
|
|
unlockBtn.innerHTML = '<i class="bx bx-lock-open-alt"></i>';
|
|
} else {
|
|
unlockBtn.classList.add('btn-outline-secondary');
|
|
unlockBtn.classList.remove('btn-primary');
|
|
unlockBtn.innerHTML = '<i class="bx bx-lock-alt"></i>';
|
|
}
|
|
});
|
|
}
|
|
|
|
// Obsługa przycisku "Całość"
|
|
const payFullBtn = document.getElementById('payFullBtn');
|
|
const paidInput = document.getElementById('paidInput');
|
|
// Tutaj symulujemy pobranie kwoty z podsumowania (normalnie z logiki JS liczącej tabelę)
|
|
// Zakładamy, że user klika, a my bierzemy '0.00' lub cokolwiek tam jest
|
|
if (payFullBtn && paidInput) {
|
|
payFullBtn.addEventListener('click', function () {
|
|
// W prawdziwej aplikacji pobrałbyś sumę z obiektu calculateTotal()
|
|
// Tutaj dla przykładu wpiszemy placeholder, bo tabela jest pusta
|
|
paidInput.value = "1230.00"; // Przykładowa wartość
|
|
paidInput.focus();
|
|
});
|
|
}
|
|
|
|
// --- OCR Simulation Logic for Page ---
|
|
const ocrBtnPage = document.getElementById('btn-ocr-read-page');
|
|
if (ocrBtnPage) {
|
|
ocrBtnPage.addEventListener('click', function () {
|
|
const btn = this;
|
|
|
|
// 1. Loader
|
|
btn.disabled = true;
|
|
btn.innerHTML = '<span class="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true"></span> Przetwarzanie obrazu...';
|
|
|
|
// 2. Delay
|
|
setTimeout(() => {
|
|
// 3. Fill Data
|
|
|
|
// Vendor (Find the card body with select placeholder)
|
|
const vendorCardBody = document.querySelector('.card.shadow-none .card-body');
|
|
if (vendorCardBody) {
|
|
vendorCardBody.innerHTML = `
|
|
<div>
|
|
<h6 class="mb-0">Tauron Polska Energia S.A.</h6>
|
|
<small class="text-muted d-block">ul. Ks. Piotra Ściegiennego 3</small>
|
|
<small class="text-muted d-block">40-114 Katowice</small>
|
|
<small class="text-muted d-block">NIP: 551-102-12-34</small>
|
|
</div>
|
|
<button class="btn btn-outline-secondary btn-sm position-absolute end-0 top-0 m-2"><i class="bx bx-x"></i></button>
|
|
`;
|
|
}
|
|
|
|
// Invoice Data
|
|
const invNum = document.querySelector('input[placeholder="np. FV/2026/02/105"]');
|
|
if (invNum) invNum.value = 'FV/KAT/2026/02/552';
|
|
|
|
const dates = document.querySelectorAll('.date-picker');
|
|
if (dates.length >= 3) {
|
|
dates[0].value = '2026-02-15'; // Purchase
|
|
dates[1].value = '2026-02-15'; // Issue
|
|
dates[2].value = '2026-02-29'; // Payment
|
|
}
|
|
|
|
// Items - Row 1
|
|
const row1 = document.querySelector('table tbody tr:first-child');
|
|
if (row1) {
|
|
const inputs = row1.querySelectorAll('input');
|
|
if (inputs.length >= 5) { // Name, Code, Qty, Price, VAT (select is not input)
|
|
inputs[0].value = 'Energia elektryczna - taryfa C11'; // Name
|
|
inputs[1].value = 'PKW-2026'; // Code
|
|
// inputs[2] is select in some tables, here it is unit select (col 4, idx 3)
|
|
// wait, let's look at table structure.
|
|
// td 2: input name [0]
|
|
// td 3: input code [1]
|
|
// td 4: select unit
|
|
// td 5: input qty [2]
|
|
// td 6: input price [3]
|
|
|
|
// Let's use specific selector for safety
|
|
}
|
|
|
|
const nameInput = row1.querySelector('input[placeholder="Np. Usługa księgowa, Paliwo..."]');
|
|
if (nameInput) nameInput.value = 'Energia elektryczna - taryfa C11';
|
|
|
|
const codeInput = row1.querySelector('input[placeholder="-"]');
|
|
if (codeInput) codeInput.value = 'PKW-2026';
|
|
|
|
const qtyInput = row1.querySelector('td:nth-child(5) input');
|
|
if (qtyInput) qtyInput.value = '1.00';
|
|
|
|
const priceInput = row1.querySelector('td:nth-child(6) input');
|
|
if (priceInput) priceInput.value = '450.00';
|
|
|
|
// Update totals in row (td 8 and 9)
|
|
const netCell = row1.querySelector('td:nth-child(8)');
|
|
if (netCell) netCell.innerText = '450,00 zł';
|
|
|
|
const grossCell = row1.querySelector('td:nth-child(9)');
|
|
if (grossCell) grossCell.innerText = '553,50 zł';
|
|
}
|
|
|
|
// Summary
|
|
const summaries = document.querySelectorAll('.card-body .d-flex.justify-content-between span.fw-semibold');
|
|
if (summaries.length >= 2) {
|
|
summaries[0].innerText = '450,00 zł'; // Netto
|
|
summaries[1].innerText = '103,50 zł'; // VAT
|
|
}
|
|
|
|
const totalEl = document.getElementById('finalTotal');
|
|
if (totalEl) totalEl.innerText = '553,50 zł';
|
|
|
|
// 4. Restore Button
|
|
btn.disabled = false;
|
|
btn.innerHTML = '<i class="bx bx-check me-1"></i> Dane odczytane poprawnie';
|
|
btn.classList.remove('btn-label-primary');
|
|
btn.classList.add('btn-label-success');
|
|
|
|
// Animation
|
|
const allInputs = document.querySelectorAll('input');
|
|
allInputs.forEach(input => {
|
|
if (input.value && input.value !== '0.00' && input.type !== 'text' && input.type !== 'hidden') {
|
|
// Filter a bit to avoid everything flashing
|
|
}
|
|
if (input.value && input.value !== '0.00' && input.type !== 'hidden') {
|
|
input.classList.add('animate__animated', 'animate__flash');
|
|
setTimeout(() => input.classList.remove('animate__animated', 'animate__flash'), 1000);
|
|
}
|
|
});
|
|
|
|
|
|
}, 2000);
|
|
});
|
|
}
|
|
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|