Private
Public Access
funcionalidad de facturas tengo sueño Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
41 lines
943 B
TypeScript
41 lines
943 B
TypeScript
import { API_URL } from '$lib/env';
|
|
import { getToken } from '../token';
|
|
|
|
export interface ItemFacturaPayload {
|
|
repuestoId: number;
|
|
cantidad: number;
|
|
precioUnitario: number;
|
|
}
|
|
|
|
export interface PagoFacturaPayload {
|
|
formaDePagoId: number;
|
|
importe: number;
|
|
fecha?: string;
|
|
observacion?: string;
|
|
}
|
|
|
|
export interface CrearFacturaPayload {
|
|
clienteId: number;
|
|
almacenId: number;
|
|
items: ItemFacturaPayload[];
|
|
descuentoId?: number;
|
|
pagos?: PagoFacturaPayload[];
|
|
enviarEmail?: boolean;
|
|
observacion?: string;
|
|
}
|
|
|
|
export async function crearFactura(payload: CrearFacturaPayload) {
|
|
try {
|
|
const req = await fetch(`${API_URL}/facturas/`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` },
|
|
body: JSON.stringify(payload)
|
|
});
|
|
const data = await req.json();
|
|
if (req.ok) return data;
|
|
return data.error ?? 'error';
|
|
} catch {
|
|
return 'no se pudo alcanzar el servidor';
|
|
}
|
|
}
|