dicom evidence update
This commit is contained in:
@@ -27,12 +27,29 @@
|
||||
<label class="small text-muted mb-1">Monto (CLP)</label>
|
||||
<input type="number" id="dicom-amount" class="form-control" placeholder="Ej: 5000">
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="small text-muted mb-1">Nota (Opcional)</label>
|
||||
<input type="text" id="dicom-notes" class="form-control" placeholder="Ej: Pan y bebida"
|
||||
onkeydown="if(event.key === 'Enter') submitDicom('add')">
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="small text-muted mb-1">Foto / Comprobante</label>
|
||||
<div class="input-group">
|
||||
<input type="text" id="dicom-image-url" class="form-control" placeholder="URL de imagen" readonly>
|
||||
<input type="file" id="dicom-camera-input" accept="image/*" capture="environment" style="display: none;"
|
||||
onchange="handleDicomUpload(this)">
|
||||
<button class="btn btn-outline-secondary" type="button"
|
||||
onclick="document.getElementById('dicom-camera-input').click()">
|
||||
<i class="bi bi-camera"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div id="dicom-img-preview-container" class="mt-2 d-none">
|
||||
<img id="dicom-img-preview" src="" class="img-thumbnail" style="max-height: 100px;">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-column gap-2">
|
||||
<button class="btn btn-danger py-2 fw-bold" onclick="submitDicom('add')">
|
||||
<i class="bi bi-cart-plus me-1"></i> Fiar (Sumar Deuda)
|
||||
@@ -57,6 +74,7 @@
|
||||
<table class="table mb-0" id="dicom-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Foto</th>
|
||||
<th>Nombre</th>
|
||||
<th>Deuda Total</th>
|
||||
<th>Última Nota</th>
|
||||
@@ -67,6 +85,16 @@
|
||||
<tbody>
|
||||
{% for d in debtors %}
|
||||
<tr>
|
||||
<td>
|
||||
{% if d[5] %}
|
||||
<img src="{{ d[5] }}" class="rounded" style="width: 40px; height: 40px; object-fit: cover; cursor: pointer;"
|
||||
onclick="window.open(this.src, '_blank')">
|
||||
{% else %}
|
||||
<div class="bg-secondary rounded" style="width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; opacity: 0.3;">
|
||||
<i class="bi bi-image text-white"></i>
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="fw-bold">{{ d[1] }}</td>
|
||||
<td class="fw-bold price-cell" data-value="{{ d[2] }}"></td>
|
||||
<td class="text-muted small">{{ d[3] }}</td>
|
||||
@@ -112,14 +140,62 @@
|
||||
}
|
||||
});
|
||||
|
||||
function clearDicomForm() {
|
||||
document.getElementById('dicom-name').value = '';
|
||||
document.getElementById('dicom-amount').value = '';
|
||||
document.getElementById('dicom-notes').value = '';
|
||||
document.getElementById('dicom-name').focus();
|
||||
function compressImage(file, maxWidth, quality) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = event => {
|
||||
const img = new Image();
|
||||
img.src = event.target.result;
|
||||
img.onload = () => {
|
||||
const canvas = document.createElement('canvas');
|
||||
let width = img.width;
|
||||
let height = img.height;
|
||||
if (width > maxWidth) {
|
||||
height = Math.round((height * maxWidth) / width);
|
||||
width = maxWidth;
|
||||
}
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0, width, height);
|
||||
canvas.toBlob(blob => resolve(blob), 'image/jpeg', quality);
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// Search Filter
|
||||
async function handleDicomUpload(input) {
|
||||
const name = document.getElementById('dicom-name').value;
|
||||
if (!name) {
|
||||
alert("Primero ingresa un nombre para asociar la foto.");
|
||||
input.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
const file = input.files[0];
|
||||
if (!file) return;
|
||||
|
||||
try {
|
||||
const compressedBlob = await compressImage(file, 800, 0.7);
|
||||
const formData = new FormData();
|
||||
// Use a unique name for the file based on the debtor
|
||||
formData.append('image', compressedBlob, `debt_${name}_${Date.now()}.jpg`);
|
||||
formData.append('barcode', `debt_${name}`); // Reusing the barcode field as a prefix
|
||||
|
||||
const res = await fetch('/upload_image', { method: 'POST', body: formData });
|
||||
const data = await res.json();
|
||||
|
||||
if (res.ok) {
|
||||
document.getElementById('dicom-image-url').value = data.image_url;
|
||||
document.getElementById('dicom-img-preview').src = data.image_url;
|
||||
document.getElementById('dicom-img-preview-container').classList.remove('d-none');
|
||||
}
|
||||
} catch (e) {
|
||||
alert("Error procesando imagen.");
|
||||
}
|
||||
}
|
||||
|
||||
function filterDicom() {
|
||||
const q = document.getElementById('dicom-search').value.toLowerCase();
|
||||
document.querySelectorAll('#dicom-table tbody tr').forEach(row => {
|
||||
@@ -139,6 +215,7 @@
|
||||
const name = document.getElementById('dicom-name').value;
|
||||
const amount = document.getElementById('dicom-amount').value;
|
||||
const notes = document.getElementById('dicom-notes').value;
|
||||
const image_url = document.getElementById('dicom-image-url').value; // Added
|
||||
|
||||
if (!name || amount <= 0) {
|
||||
alert('Ingresa un nombre y monto válido.');
|
||||
@@ -149,17 +226,20 @@
|
||||
const res = await fetch('/api/dicom/update', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, amount, notes, action })
|
||||
body: JSON.stringify({ name, amount, notes, action, image_url }) // Added image_url
|
||||
});
|
||||
if (res.ok) window.location.reload();
|
||||
} catch (e) { alert("Error de conexión."); }
|
||||
}
|
||||
|
||||
if (res.ok) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
alert('Error actualizando la base de datos.');
|
||||
}
|
||||
} catch (e) {
|
||||
alert("Error de conexión.");
|
||||
}
|
||||
// UPDATE your existing clearDicomForm
|
||||
function clearDicomForm() {
|
||||
document.getElementById('dicom-name').value = '';
|
||||
document.getElementById('dicom-amount').value = '';
|
||||
document.getElementById('dicom-notes').value = '';
|
||||
document.getElementById('dicom-image-url').value = ''; // Added
|
||||
document.getElementById('dicom-img-preview-container').classList.add('d-none'); // Added
|
||||
document.getElementById('dicom-name').focus();
|
||||
}
|
||||
|
||||
async function forgiveDebt(id, name) {
|
||||
|
||||
Reference in New Issue
Block a user