feat(pos): add 5 quick improvements — dark mode, email quotes, barcode scan, returns, offline catalog

1. Auto dark mode: detect system prefers-color-scheme, auto-switch industrial/modern theme
2. Email quotation endpoint: POST /quotations/:id/email sends HTML email via SMTP
3. Camera barcode scanner: BarcodeDetector API with getUserMedia overlay in catalog
4. Returns with warranty: POST /returns endpoint with stock restoration and sale status tracking
5. Partial offline catalog: cache top 500 parts in IndexedDB, search when offline

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-04 08:03:28 +00:00
parent 39f2aaf98f
commit c61e58ac6a
9 changed files with 751 additions and 23 deletions

View File

@@ -6,21 +6,114 @@
window.NexusNative = {
isNative: typeof Capacitor !== 'undefined',
_scanStream: null,
_scanVideo: null,
// Camera for barcode scanning
// Camera barcode scanning — works in native (Capacitor) and web (BarcodeDetector / getUserMedia)
async scanBarcode() {
if (!this.isNative) return null;
try {
const { Camera } = await import('@capacitor/camera');
const photo = await Camera.getPhoto({
quality: 90,
resultType: 'base64'
});
// In production, send to a barcode decode service
return photo;
} catch(e) {
// Native Capacitor path
if (this.isNative) {
try {
const { Camera } = await import('@capacitor/camera');
const photo = await Camera.getPhoto({
quality: 90,
resultType: 'base64'
});
return photo;
} catch(e) {
return null;
}
}
// Web path: use BarcodeDetector API (Chrome 83+)
if (!('BarcodeDetector' in window)) {
alert('Tu navegador no soporta escaneo de codigos de barras. Usa Chrome 83+ o un dispositivo movil.');
return null;
}
return new Promise(async (resolve) => {
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: { facingMode: 'environment', width: { ideal: 1280 }, height: { ideal: 720 } }
});
this._scanStream = stream;
// Create overlay UI
const overlay = document.createElement('div');
overlay.id = 'barcode-scan-overlay';
overlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.9);z-index:99999;display:flex;flex-direction:column;align-items:center;justify-content:center;';
const video = document.createElement('video');
video.autoplay = true;
video.playsInline = true;
video.style.cssText = 'width:90%;max-width:500px;border-radius:12px;border:3px solid #F5A623;';
video.srcObject = stream;
this._scanVideo = video;
const label = document.createElement('p');
label.textContent = 'Apunta al codigo de barras...';
label.style.cssText = 'color:#fff;font-size:16px;margin-top:16px;font-family:sans-serif;';
const cancelBtn = document.createElement('button');
cancelBtn.textContent = 'Cancelar';
cancelBtn.style.cssText = 'margin-top:16px;padding:10px 24px;background:#F5A623;color:#000;border:none;border-radius:6px;font-size:15px;cursor:pointer;font-weight:bold;';
cancelBtn.onclick = () => {
this.stopScan();
overlay.remove();
resolve(null);
};
overlay.appendChild(video);
overlay.appendChild(label);
overlay.appendChild(cancelBtn);
document.body.appendChild(overlay);
const detector = new BarcodeDetector({
formats: ['ean_13', 'ean_8', 'code_128', 'code_39', 'qr_code', 'upc_a', 'upc_e']
});
const scanFrame = async () => {
if (!this._scanStream) return;
try {
const barcodes = await detector.detect(video);
if (barcodes.length > 0) {
const code = barcodes[0].rawValue;
label.textContent = 'Codigo detectado: ' + code;
label.style.color = '#4CAF50';
// Small delay so user sees the result
setTimeout(() => {
this.stopScan();
overlay.remove();
resolve(code);
}, 400);
return;
}
} catch(e) { /* frame failed, retry */ }
requestAnimationFrame(scanFrame);
};
// Wait for video to be ready
video.onloadedmetadata = () => {
video.play();
requestAnimationFrame(scanFrame);
};
} catch(e) {
console.error('Camera access error:', e);
alert('No se pudo acceder a la camara: ' + e.message);
resolve(null);
}
});
},
stopScan() {
if (this._scanStream) {
this._scanStream.getTracks().forEach(t => t.stop());
this._scanStream = null;
}
this._scanVideo = null;
var overlay = document.getElementById('barcode-scan-overlay');
if (overlay) overlay.remove();
},
// Push notification registration
@@ -34,7 +127,6 @@
}
PushNotifications.addListener('registration', token => {
console.log('Push token:', token.value);
// Send token to server for this employee
});
PushNotifications.addListener('pushNotificationReceived', notification => {
console.log('Push received:', notification);